Skip to main content
GameDev.net gamedev.net
🔒 Locked

texture mapping, help me please!!!

Started by warerare Jan 12, 2005 at 1:12 PM 9 replies 2.4k views
Original Post
warerare
warerare
hey if anyone can help me urgently then it would be great I have to create a 2d opengl diagram of a rugby stadium by tomorrow, ive decided to add a texture map of grass for the pitch and it has turned all other colors different shades of green, anyone know how to remedy this Thanks [Edited by - warerare on January 12, 2005 3:14:25 PM]
Whirlwind
Whirlwind
I've not touched opengl in about 4 years but I am going to take a stab at saying that you probably need to increase the percision of the RGBA variables used to load the image. OpenGL just uses the "best guess" to match the colors you request with what the video card can do. If the RGBA thing is bogus, try increasing your desktop and/or application resolution to 32-bit.
warerare
warerare
i dont think it is that because the colours were normal up until the texture map was loaded plus the texture map is green which is why i think its gone a shade of that colour
Thoooms
Thoooms
Did you remember to disable your texture object after you are done with it?
warerare
warerare
sorry dont know how i do that, could u tell me please
Thoooms
Thoooms
Well, you can just do a:
glDisable(GL_TEXTURE_2D);
to disable all texturing, and then use
glEnable(GL_TEXTURE_2D);
to enable it.

So all in all you might want to do something like this:
//....glEnable(GL_TEXTURE_2D);//bind the right texture and draw the object with correct texture coordinatesglDisable(GL_TEXTURE_2D);//....
warerare
warerare
ive done that and the colour returns to normal but the texture disappears
Thoooms
Thoooms
did you remember to reenable texturing as I wrote above?
warerare
warerare
tried that and it just made the colour change green again
Enigma
Enigma
OpenGL is a state machine. When you enable something or set something it will affect all future operations until you disable it or set something else. Two examples of these states are the texture enable state and the current texture coordinate. When you enable texturing it remains enabled until you disable it. When you set a texture coordinate that coordinate applies to all future vertices until you change it. So this code:
glEnable(GL_TEXTURE_2D);glBegin(GL_QUADS);	glTexCoord2f(0, 0);	glVertex2f(-10, 10);	glTexCoord2f(1, 0);	glVertex2f(0, 10);	glTexCoord2f(1, 1);	glVertex2f(0, -10);	glTexCoord2f(0, 1);	glVertex2f(-10, -10);glEnd();glBegin(GL_QUADS);	glVertex2f(0, 10);	glVertex2f(10, 10);	glVertex2f(10, -10);	glVertex2f(0, -10);glEnd();

is actually exactly the same as:
glEnable(GL_TEXTURE_2D);glBegin(GL_QUADS);	glTexCoord2f(0, 0);	glVertex2f(-10, 10);	glTexCoord2f(1, 0);	glVertex2f(0, 10);	glTexCoord2f(1, 1);	glVertex2f(0, -10);	glTexCoord2f(0, 1);	glVertex2f(-10, -10);glEnd();glEnable(GL_TEXTURE_2D);glBegin(GL_QUADS);	glTexCoord2f(0, 1);	glVertex2f(0, 10);	glTexCoord2f(0, 1);	glVertex2f(10, 10);	glTexCoord2f(0, 1);	glVertex2f(10, -10);	glTexCoord2f(0, 1);	glVertex2f(0, -10);glEnd();

Note how the last texture coordinate persists and applies to all vertices. So you're not drawing a textured polygon and an untextured polygon, you're drawing two textured polygons. One is textured with the entire texture. The other is textured with a single sample (pixel) from the texture. This is why your objects go green (in reality OpenGL will by default multiply the texture colour by the colour you specify with glColor{3 4}{b s i f d ub us ui}). To have the first polygon textured and the second not you must explicitly set that state each time:
// explicitly enable texturing for the first polygonglEnable(GL_TEXTURE_2D);glBegin(GL_QUADS);	glTexCoord2f(0, 0);	glVertex2f(-10, 10);	glTexCoord2f(1, 0);	glVertex2f(0, 10);	glTexCoord2f(1, 1);	glVertex2f(0, -10);	glTexCoord2f(0, 1);	glVertex2f(-10, -10);glEnd();// explicitly disable texturing for the second polygonglDisable(GL_TEXTURE_2D);glBegin(GL_QUADS);	glVertex2f(0, 10);	glVertex2f(10, 10);	glVertex2f(10, -10);	glVertex2f(0, -10);glEnd();


Enigma
warerare
warerare
what a legend, thanks alot that worked like a charm ,great explanation, now all i gotta figure out is zooming and panning and im sorted


thanks alot

Topic Locked

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

Sign in to reply to this topic.