i’ve been reading up on opengl stuff and from what i understand, it’s usually faster to use display lists when drawing the same shape over and over.
i’m trying to draw a rect in a display list which has a texture mapped onto it, and i’m not really sure how to proceed. i based myself on flight404’s latest particles stuff (in p5) and figured out that the code should look something like this:
glBindTexture( someTexture );
glBegin(gl.GL_QUADS);
glTexCoord4f( loc.x, loc.y, loc.z, 75 );
glCallList( myRectList );
glEnd();
so, my idea is to extend ofTexture and override draw() so that instead of calling glVertex3i(…), i call glCallList(aList).
this is what i have so far:
ofListTexture.h
#include "ofTexture.h"
class ofListTexture : public ofTexture {
public:
void setList(int aList);
void draw(float x, float y, float w, float h);
private:
int displayList;
};
ofListTexture.cpp
#include "ofListTexture.h"
//----------------------------------------------------------
void ofListTexture::setList(int aList) {
displayList = aList;
}
//----------------------------------------------------------
void ofListTexture::draw(float x, float y, float w, float h) {
glEnable(textureTarget);
// bind the texture
glBindTexture( textureTarget, (GLuint)textureName[0] );
GLint px0 = 0; // up to you to get the aspect ratio right
GLint py0 = 0;
GLint px1 = (GLint)w;
GLint py1 = (GLint)h;
if (bFlipTexture == true){
GLint temp = py0;
py0 = py1;
py1 = temp;
}
// for rect mode center, let's do this:
if (ofGetRectMode() == OF_RECTMODE_CENTER){
px0 = (GLint)-w/2;
py0 = (GLint)-h/2;
px1 = (GLint)+w/2;
py1 = (GLint)+h/2;
}
// -------------------------------------------------
// complete hack to remove border artifacts.
// slightly, slightly alters an image, scaling...
// to remove the border.
// we need a better solution for this, but
// to constantly add a 2 pixel border on all uploaded images
// is insane..
GLfloat offsetw = 0;
GLfloat offseth = 0;
if (textureTarget == GL_TEXTURE_2D){
offsetw = 1.0f/(tex_w);
offseth = 1.0f/(tex_h);
}
// -------------------------------------------------
GLfloat tx0 = 0+offsetw;
GLfloat ty0 = 0+offseth;
GLfloat tx1 = tex_t - offsetw;
GLfloat ty1 = tex_u - offseth;
glPushMatrix();
glTranslated(x, y, 0);
glBegin( GL_QUADS );
glTexCoord2f(x, y);
glCallList(displayList);
glEnd();
glPopMatrix();
glDisable(textureTarget);
}
i think i’m almost there, but i’m kind of stuck. i’m not sure what the params to glTexCoord2f(…) should be (between glBegin(GL_QUADS) and glEnd()).
am i on the right track ?
thanks for the help