Archived

This topic is now archived and is closed to further replies.

mstein

texture problem

Recommended Posts

i recently have come back to an old program i wrote and for some reason the texturing no longer works . . . assuming that the readTexture function works. . . do you have any ideas on why this will not work.
  
/* TEXTURE */

void TextureSetup(char * filename, unsigned int * textureID) {

		void * textureData;
		int width, height;
		GLenum format, type;
		int bytes, bitsPerPixel;

		textureData = (void *)readTexture(filename, NULL, &width, &height, &format, &type, &bytes, &bitsPerPixel);
		glGenTextures(1, textureID);
		glBindTexture(GL_TEXTURE_2D, *textureID);
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		gluBuild2DMipmaps(GL_TEXTURE_2D, format, width, height, format, type, textureData);
		
		free(textureData);
}

void TextureChange(int newTexture) {
	glBindTexture(GL_TEXTURE_2D, textureIDs[newTexture]);
}
  
I call TextureSetup like this:
  
	/* setup textures */
	TextureSetup("road.pbm", &textureIDs[ROAD]);
	TextureSetup("wood.pbm", &textureIDs[WOOD]);
	TextureSetup("snow.pbm", &textureIDs[SNOW]);
  
My display list for drawing my textured quad is here:
  
/* display list for background quads */
void createBackgroundLists() {

	int i;

	/* create the display list for the textured background */
	quad_textured = glGenLists(1);
	glNewList(quad_textured, GL_COMPILE);
		glEnable(GL_TEXTURE_2D);
		glColor3f(1.0, 1.0, 1.0);
		glNormal3f(0.0, 0.0, 1.0);
		float step = .00625;
		for(i = 0; i <= 320; i++) {
			glBegin(GL_QUAD_STRIP);
			glTexCoord2f((-1.0 + 1.0)/2, ((1.0 - (i+1) * step) + 1.0)/2);
			glVertex2f(-1.0, 1.0 - (i+1) * step);
			glTexCoord2f((-1.0 + 1.0)/2, ((1.0 - i * step) + 1.0)/2);
			glVertex2f(-1.0, 1.0 - i * step);
			for(int j= 1; j <= 320; j++) {
				glTexCoord2f(((-1.0 + j * step) + 1.0) /2, ((1.0 - (i+1) * step) + 1.0)/2);
				glVertex2f(-1.0 + j * step, 1.0 - (i+1) * step);
				glTexCoord2f(((-1.0 + j * step) + 1.0)/ 2, ((1.0 - i * step) + 1.0)/2);
				glVertex2f(-1.0 + j * step, 1.0 - i * step);
			}
			glEnd();
		}
		glDisable(GL_TEXTURE_2D);
	glEndList();

	/* create the display list for the untextured background */
	quad_untextured = glGenLists(1);
	glNewList(quad_untextured, GL_COMPILE);
		glEnable(GL_COLOR_MATERIAL);
		glColor3f(1.0, 1.0, 1.0);
		glNormal3f(0.0, 0.0, 1.0);
		step = .00625;
		for(i = 0; i <= 320; i++) {
			glBegin(GL_QUAD_STRIP);
			glVertex2f(-1.0, 1.0 - (i+1) * step);
			glVertex2f(-1.0, 1.0 - i * step);
			for(int j= 1; j <= 320; j++) {
				glVertex2f(-1.0 + j * step, 1.0 - (i+1) * step);
				glVertex2f(-1.0 + j * step, 1.0 - i * step);
			}
			glEnd();
		}
	glEndList();
}
/* END DISPLAY LISTS */
  
I realize this is a lot of code to lay on you guys, but I have been away from it for so long I really do not know where to start . .. and for some reason i cant locate my red book (i know there is one online) . . . thanks for any help.

Share this post


Link to post
Share on other sites