Textures and Display Lists

Just a simple question,

Can you put a texture on something in a display list? I tried but it doesn’t seem to work so either a: you can’t or b: I’m doing it wrong. Any thoughts?

	glNewList(dBackgroundDisplayList, GL_COMPILE);

			glEnable(GL_TEXTURE_2D);
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
			glBindTexture(GL_TEXTURE_2D, dBackgroundTex.GetID());

			glBegin(GL_QUADS);
				glTexCoord2f(0.0, 0.0); glVertex2i(0,0);
				glTexCoord2f(0.0, texHeight); glVertex2i(0,dHeight);
				glTexCoord2f(texWidth, texHeight); glVertex2i(dWidth,dHeight);
				glTexCoord2f(texWidth, 0.0); glVertex2i(dWidth,0);
			glEnd();
			glDisable(GL_TEXTURE_2D);

				//left
				glColor4ub(255,255,255,40);
				glRecti...

glEndList();

Thanks in advance

should be able to, as long as you dont delet the texture object.

check to make sure the texture has a width & height of 2 to the power of something. Check that the texture file is in a colour depth and bit format that is supported.

Make sure the quad is being drawn the correct way around. Can you see the quad at all? or is it just not textured.

think I know, try this.

glBegin(GL_QUADS);
glTexCoord2f(1.0, 0.0); glVertex2i(dWidth,0);
glTexCoord2f(1.0, 1.0); glVertex2i(dWidth,dHeight);
glTexCoord2f(0.0, 1.0); glVertex2i(0,dHeight);
glTexCoord2f(0.0, 0.0); glVertex2i(0,0);
glEnd();

define quads in anti-clockwise order etc

[This message has been edited by Rob The Bloke (edited 04-18-2001).]

you CAN bind a texture to a poly in a display list.

It seems from the posts that you can bind a texture to something in a display list so my code must be messed up then. If I copy the contents of the display list directly to where I want it executed (in immediate mode), it works fine. When I copy it to a display list (in the constructor) it doesn’t. Is there any special procedures required for binding textures in a display list?

Thanks again for the responses,

PS Would anyone have an example of some working code?

Thanks

MyList= glGenLists(1);
glNewList(MyList, GL_COMPILE);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tList[TEXTURE]);
glBegin (GL_TRIANGLES);
// glTexCoord…glVertex…
glEnd ();
glDisable(GL_TEXTURE_2D);
glEndList();

The only obvious difference is you have this inside the display list.

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

// From the red book.
Commands that set the client state and commands that retrieve state values are not stored in a display list. If these commands are called while making a list they are executed immediately.

Hope this helps,
Cheers,
Dan

You create the display list in a constructor? Is that object getting instantiated before you initialize OpenGL? You need to create a suitable pixelformat for OpenGL before you use any openGL functions (such as creating a display list.)

So if you had something like this…

void InitGL();

SomeModelWithDisplayListInConstructor model;

void main()
{
InitGL();
}

Your display list won’t be created because the constructor will be invoked on startup, before the InitGL function is called…

Yes, I’m entering gamemode before the constructor is called and the texture data is static so that shouldn’t be a problem. From the posts the code I was using was along the correct line so my problems must be somewhere else. Thanks for the replys.