• Advertisement


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

Texture mapping with display lists

This topic is 5685 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been using the NeHe tutorials for most of my program but unfortunately the texture mapping tutorial comes before the one for display lists. So I'm confused as to how to texture map a triangle strip that is in a display list. The code I have is as follows: In textures.cpp:
#include	<stdio.h>				// Header File For Standard Input/Output 

#include	<gl\glaux.h>
#include	<gl\glu.h>				// To use gluBuild2DMipmaps function

#include	"global_vars.h"

const int NumTextures = 1;						// The number of textures

GLuint texture[NumTextures];					// Storage For Textures

AUX_RGBImageRec *LoadBMP(char *Filename)		// Loads A Bitmap Image


	FILE *File=NULL;							// File Handle

	if (!Filename)								// Make Sure A Filename Was Given

		return NULL;							// If Not Return NULL


	File=fopen(Filename,"r");					// Check To See If The File Exists

	if (File)									// Does The File Exist?

		fclose(File);							// Close The Handle

		return auxDIBImageLoad(Filename);		// Load The Bitmap And Return A Pointer


	return NULL;								// If Load Failed Return NULL

} // End of method AUX_RGBImageRec

int LoadGLTextures()							// Load Bitmaps And Convert To Textures


	char filenames[NumTextures][24] = { "Data/border_texture.bmp" };
	int Status = FALSE;							// Status Indicator For Texture Loaded/Built

	AUX_RGBImageRec *TextureImage[NumTextures];			// Create Storage Space For The Textures

	memset(TextureImage,0,sizeof(void *)*NumTextures);	// Set The Pointer To NULL

	for (int count = 0; count < NumTextures; count++)	// For each texture


		// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit

		if (TextureImage[count]=LoadBMP(filenames[count]))
			Status = TRUE;									// Set The Status To TRUE

			glGenTextures(1, &texture[count]);				// Create The Texture

			// Typical Texture Generation Using Data From The Bitmap

			glBindTexture(GL_TEXTURE_2D, texture[count]);	// Function to bind each BMP to its texture

			// Generate The Texture

			// Assign each BMPs data to its Texture			

			// Insure to refer to the individual texture counter (aBMPTexture)				

			gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[count]->sizeX, TextureImage[count]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[count]->data);


			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// Linear Filtering

		}		// End bind *.bmp to textures

		else	// File containing BMP wasn't found to be able to map a texture

			MessageBox(hWnd,filenames[count],"texture not found",MB_OK);	
			// File not found. Display Error dialog box w/ filename	

			Status = false;	// False Status to indicate load failed	

			return Status;		
		}	// End if-else

		/* Cycle through each texture and de-allocate memory defined		
		   while still within allocation loop, but before leaving function */
		if (TextureImage[count])					// If Texture Exists

			if (TextureImage[count]->data)				// If Texture Image Exists

				free(TextureImage[count]->data);			// Free The Texture Image Memory

			free(TextureImage[count]);					// Free The Image Structure

	} // End for

	return Status;								// Return The Status

} // End of method LoadGLTextures

void TextureDraw(GLint TextureNum)

	glBindTexture(GL_TEXTURE_2D, texture[TextureNum]);			// Select Our Texture

} // End of method TextureDraw

In border.cpp:
void Border::BuildBorderLists()

	TextureDraw(0);									// Select texture

	// (Left border) top face

	top_face = glGenLists(2);						// Build two lists. top_face holds location of first list

	glNewList(top_face, GL_COMPILE);				
			glNormal3f( 0.0f, 0.0f, 1.0f );							// Create normal

			glVertex3f( left_border-1.0f,	bottom_border,	0.0f);	// Bottom Left Of The Face

			glVertex3f( left_border,		bottom_border,	0.0f);	// Bottom Right Of The Face

			glVertex3f( left_border-1.0f,	top_border,		0.0f);	// Top Left Of The Face

			glVertex3f( left_border,		top_border,		0.0f);	// Top Right Of The Face

} // End of method BuildBorderLists

void Border::DrawBorder()

	// Build borders from display lists

	// Left border

} // End of method DrawBorder

In init.cpp:
int InitGL(GLvoid)
	if (!LoadGLTextures())		// Jump To Texture Loading Routine

		return FALSE;		// If Texture Didn't Load Return FALSE 

	glEnable(GL_TEXTURE_2D);	// Enable Texture Mapping

I thought this would work but it doesn't add the texture (it also seems to turn off the lights). Can anyone see what I am doing wrong? [edited by - Billy Lee on August 30, 2002 10:39:56 AM] [edited by - Billy Lee on August 30, 2002 10:43:11 AM]

Share this post

Link to post
Share on other sites
Actually, I''ve just looked and the display lists tutorial does deal with texture maps. However, the code above is pretty much what the tutorial does but I''ve loaded the texture within the display list code, which should also work. I don''t know why it doesn''t.

Share this post

Link to post
Share on other sites
You haven't added the Texture coordinate lines in before each vertex line.

You have to specify a texture coordinate for each vertex.

where s and t are between 0 and 1 inclusive for glTexCoord2f() and they correspond to the appropriate location for the vertex. This is covered in the tutorials on NeHe.

If you specify s and t between 0 and 1 then it will render different parts of the texture, but if you specify 0 and 1 then it will scale the texture to fit the object you are texture mapping.

[edited by - emblem on August 30, 2002 11:18:59 AM]

Share this post

Link to post
Share on other sites

  • Advertisement