Skip to main content
gamedev.net
🔒 Locked

A Few Texture Problems

Started by bladetnt 2 replies 650+ views
Original Post
bladetnt
bladetnt
I use the following code to lay textures to floor for (int m = -9; m < 9; m++) { for (int k = -9; k < 9; k++) { Gl.glPushMatrix(); Gl.glTranslated(-2 + 2 * k, 0, 8+2*m); Gl.glScaled(1, 0.1, 1); Draw2(); Gl.glPopMatrix(); } } void Draw2() { Gl.glBegin(Gl.GL_QUADS); Gl.glTexCoord2f(1.0f, 1.0f); Gl.glVertex3f(1.0f, 1.0f, -1.0f); Gl.glTexCoord2f(0.0f, 1.0f); Gl.glVertex3f(-1.0f, 1.0f, -1.0f); Gl.glTexCoord2f(0.0f, 0.0f); Gl.glVertex3f(-1.0f, 1.0f, 1.0f); Gl.glTexCoord2f(1.0f, 0.0f); Gl.glVertex3f(1.0f, 1.0f, 1.0f); Gl.glEnd(); } Code is fine with for from -9 to 9 but if the number increasas program gets too slow. My graphics card is Ati radeon mobility x300. Can anyone suggest a better(faster)way for using textures in the code. Also the same code does not work with nvidia mx440 garphics card. Program runs but can't see texture objects. Does anyone have an idea?
AndyEsser
AndyEsser
Use display lists.

Display lists work just like Immediate calls but you can't change them afterwards.

After you've set up you opengl context and whatnot run Draw2 but change the code to:

int listId = glGenLists (1) // Generate display list id

glNewList listId, glCompile

//
Code for drawing whatever (Exact code from your previous Draw2
//

glEndList

Then where you have Draw2() in your for loops just have

glCallList listId

That way the quad as already been stored in the GFX card memory and is therefore very fast. Only downside of Display Lists is that you can't edit them afterwards.

Hope this helps

P.S. And don't forget your glBindTexture... call before glBegin
P.P.S Since I program in VB this code might not be exactly how you need it
Nitrogenycs
Nitrogenycs
Don't do what you are doing there, forget about all glVertex*, glTexCoord* commands. Use VBOs instead.
Falhar
Falhar
i think he makes texture tile, try this :

Gl.glBegin(Gl.GL_QUADS);
Gl.glTexCoord2f(18.0f, 18.0f);
Gl.glVertex3f(1.0f, 1.0f, -1.0f);
Gl.glTexCoord2f(0.0f, 18.0f);
Gl.glVertex3f(-1.0f, 1.0f, -1.0f);
Gl.glTexCoord2f(0.0f, 0.0f);
Gl.glVertex3f(-1.0f, 1.0f, 1.0f);
Gl.glTexCoord2f(18.0f, 0.0f);
Gl.glVertex3f(1.0f, 1.0f, 1.0f);
Gl.glEnd();

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.