PDA

View Full Version : frustrating texturing problems



naz
02-19-2001, 01:44 PM
I've to make each class in my opengl program get it's own address from wglgetprocaddress for the multitexture extension (that's the only one I'm using so far). However, one of my classes isn't displaying the textures correctly. I know that the textures are loading correctly, but it displays a random texture on the skybox rather than the one I specified with the setTexture member functions. OGLWrapper is just a generic openGL wrapper that keeps track of wether lighting and blending have been enabled. I know that the viewer class works correctly too. Here's some of the code:

class skybox{
private:
typedef void (APIENTRY * PFNGLACTIVETEXTUREARBPROC) (GLenum target);
typedef void (APIENTRY * PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t);

PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB;

GLuint top;
GLuint bottom;
GLuint left;
GLuint right;
GLuint back;
GLuint front;
public:

void setTop(GLuint newtexture);
void setBottom(GLuint newtexture);
void setLeft(GLuint newtexture);
void setRight(GLuint newtexture);
void setFront(GLuint newtexture);
void setBack(GLuint newtexture);

void drawBox(Viewer *me, OGLWrapper *OGLWrapper);

void setExtensions();
};

//now here's the implementation for the class

void skybox::drawBox(Viewer *me, OGLWrapper *OGLWrapper){


GLfloat rotMatrix[ 16 ];
me->camOrient.getMatrix( rotMatrix );

glPushMatrix();
glLoadIdentity();
glMultMatrixf( rotMatrix );

//glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

(*glActiveTextureARB)(GL_TEXTURE0_ARB);
//glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, front);

(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.01f, 0.01f);
glVertex3f(-40.0f, 40.0f, -40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.99f, 0.01f);
glVertex3f(40.0f, 40.0f, -40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.99f, 0.99f);
glVertex3f(40.0f, -40.0f, -40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.01f, 0.99f);
glVertex3f(-40.0f, -40.0f, -40.0f);


(*glActiveTextureARB)(GL_TEXTURE0_ARB);
//glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, top);


(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.01f, 0.01f);
glVertex3f(-40.0f, -40.0f, -40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.99f, 0.01f);
glVertex3f(40.0f, -40.0f, -40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.99f, 0.99f);
glVertex3f(40.0f, -40.0f, 40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.01f, 0.99f);
glVertex3f(-40.0f, -40.0f, 40.0f);


(*glActiveTextureARB)(GL_TEXTURE0_ARB);
//glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, bottom);


(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.01f, 0.01f);
glVertex3f(-40.0f, 40.0f, 40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.99f, 0.01f);
glVertex3f(40.0f, 40.0f, 40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.99f, 0.99f);
glVertex3f(40.0f, 40.0f, -40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.01f, 0.99f);
glVertex3f(-40.0f, 40.0f, -40.0f);

(*glActiveTextureARB)(GL_TEXTURE0_ARB);
//glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, right);


(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.01f, 0.01f);
glVertex3f(40.0f, -40.0f, -40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.99f, 0.01f);
glVertex3f(40.0f, 40.0f, -40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.99f, 0.99f);
glVertex3f(40.0f, 40.0f, 40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.01f, 0.99f);
glVertex3f(40.0f, -40.0f, 40.0f);

(*glActiveTextureARB)(GL_TEXTURE0_ARB);
//glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, left);


(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.01f, 0.01f);
glVertex3f(-40.0f, -40.0f, 40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.99f, 0.01f);
glVertex3f(-40.0f, 40.0f, 40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.99f, 0.99f);
glVertex3f(-40.0f, 40.0f, -40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.01f, 0.99f);
glVertex3f(-40.0f, -40.0f, -40.0f);

(*glActiveTextureARB)(GL_TEXTURE0_ARB);
//glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, back);


(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.01f, 0.01f);
glVertex3f(-40.0f, -40.0f, 40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.99f, 0.01f);
glVertex3f(40.0f, -40.0f, 40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.99f, 0.99f);
glVertex3f(40.0f, 40.0f, 40.0f);
(*glMultiTexCoord2fARB)(GL_TEXTURE0_ARB, 0.01f, 0.99f);
glVertex3f(-40.0f, 40.0f, 40.0f);

glEnd();
glPopMatrix();

}

naz
02-19-2001, 01:46 PM
I forgot to post the other member functions :P

void skybox::setExtensions(){
glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glActiveTextureARB");
glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC) wglGetProcAddress("glMultiTexCoord2fARB");
}


void skybox::setTop(GLuint newtexture){
top = newtexture;
}
void skybox::setBottom(GLuint newtexture){
bottom = newtexture;
}
void skybox::setLeft(GLuint newtexture){
left = newtexture;
}
void skybox::setRight(GLuint newtexture){
right = newtexture;
}
void skybox::setFront(GLuint newtexture){
front = newtexture;
}
void skybox::setBack(GLuint newtexture){
back = newtexture;
}