Sign in to follow this  
andr0cles

texture mapping problem

Recommended Posts

Hi, I am having a problem with applying textures. I have a display list (CreateFont) to which I apply one texture, and a list of GL_QUADS (showStartScreen) to which I apply another one. Each displays fine on its own, but if I try to display both, my display list is not textured properly. Can anyone help me please? -here are the relevant functions;
GLvoid CreateFont()
{
	fontlist = glGenLists(2);
	glBindTexture(GL_TEXTURE_2D, targaTexs[1].texNum);
	glNewList(fontlist, GL_COMPILE);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f,   0.0f);	    glVertex2f( 0.0f, 0.0f);
		glTexCoord2f(0.0625f,0.0f);	    glVertex2f( 0.125f, 0.0f);
		glTexCoord2f(0.0625f,0.0625f);	glVertex2f( 0.125f, 0.125f);
		glTexCoord2f(0.0f,   0.0625f);	glVertex2f( 0.0f, 0.125f);
	glEnd();
	glEndList();
	fontlist2 = fontlist+1;
	glNewList(fontlist2, GL_COMPILE);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f,   0.0f);	    glVertex2f( 1.2f, 0.0f);
		glTexCoord2f(0.0625f,0.0f);	    glVertex2f( 2.2f, 0.0f);
		glTexCoord2f(0.0625f,0.0625f);  glVertex2f( 2.2f, 1.0f);
		glTexCoord2f(0.0f,   0.0625f);	glVertex2f( 1.2f, 1.0f);
	glEnd();
	glEndList();
}

GLvoid showStartScreen()
{
glLoadIdentity();
glTranslatef(-2.8f,2.1f,-5.0f);
glBindTexture(GL_TEXTURE_2D, targaTexs[0].texNum);
for (int a=0; a<12; a++)	//draw the bar at the top
{
glBegin(GL_QUADS);
	glNormal3f(0.0f, 0.0f, 1.0f);
	glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, -0.5f, 0.0f);
	glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, -0.5f, 0.0f);
	glTexCoord2f(1.0f, 0.8f); glVertex3f( 0.5f,  0.0f, 0.0f);
	glTexCoord2f(0.0f, 0.8f); glVertex3f( 0.0f,  0.0f, 0.0f);
glEnd();
glTranslatef(0.5f,0.0f,0.0f);
}
}

int SetupGL(GLvoid)									
{
for (int i=0; i<NUMTEXTURES; i++)
	{
		if (!LoadTargaFile(fname[i], &targaTexs[i]))
		{
			return false;
		}
	}
	glEnable(GL_TEXTURE_2D);
	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	CreateFont();
return true;
}

bool DisplayScene(GLvoid)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	showStartScreen();
	glLoadIdentity();
	glTranslatef(-1.0f,0.0f,-5.0f);
	glCallList(fontlist);
	glTranslatef(0.0f,0.0f,0.0f);
	glCallList(fontlist2);

	return true;
}


Share this post


Link to post
Share on other sites
Well, my guess is your text characters is all in one file, you are trying to clip out just one little image for your 2D plane. I don't know what 'exactly' the problem is, but I would suggest starting with whole images and keeping your glTexCoord2f numbers to be whole numbers 0.0 or 1.0 for the corners of your images, not 0.0625.

Remember that your images need to be 8x8 16x16 32x32 etc to be valid sizes for OpenGl (or at least that's what I've learned for now.)

I hope this helps.

Share this post


Link to post
Share on other sites
Thanks for your help, I actually just this minute found the problem-
-I was calling glBindTextures inside my CreateFont function rather than in the DisplayScene function, before glCallLists. As a result the previously bound texture was being used in place of my font texture.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this