I’m trying to learn to use textures using the redbook and the “superbible”; I’ve also been thru the gl game programming wiki and some other tutorials; none of these use exactly the same procedure, but it still seems like it should be DEAD SIMPLE.
Can someone tell me why what I doing does not work? This is my initialization/setup function which loads the texture. The “gltLoadTGA” is from the superbible toolkit and works in the demos there:
void init(float R, float G, float B) {
GLubyte *tximg;
GLint wd, hgt, comp;
GLenum form;
GLuint Texture;
glClearColor(R,G,B,1.0f);
glEnable(GL_TEXTURE_2D);
glGenTextures(1,&Texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* because of tga format */
tximg = gltLoadTGA("hexpattern.tga",&wd,&hgt,&comp,&form);
glTexImage2D(GL_TEXTURE,0,comp,wd,hgt,0,form,GL_UNSIGNED_BYTE,tximg);
free(tximg);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D,Texture);
}
I’ve tried a few different options with TexParameter and TexEnv. Then the scene rendering function:
void scene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor4f(1.0f,1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f); glVertex3f(-10.0f,-10.0f,0.0f);
glTexCoord2f(0.0f,1.0f); glVertex3f(-10.0f,10.0f,0.0f);
glTexCoord2f(1.0f,1.0f); glVertex3f(10.0f,10.0f,0.0f);
glTexCoord2f(1.0f,0.0f); glVertex3f(10.0f,-10.0f,0.0f);
glEnd();
gluLookAt(0.0f,0.0f,50.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glutSwapBuffers();
}
I have no lighting enabled in this because it’s a simplification of the original scene, and no one implies that it is necessary. But no matter what I do, all I end with is a white square.