PDA

View Full Version : Texture mapping



stim
06-25-2001, 03:13 AM
I cannot get texture mapping to work.
I have created a context.
I have enabled 2d texture mapping.
I have generated a texture name.
I have bound the texture name to 2d textures
I have used the following to setup my texture

glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, array)

where array is a [256*256*3] byte array of texture data.

I setup my quad with texture coords for each corner but when I display the quad it appears coloured with no texture.
I have re-bound the texture before calling glBegin but still nothing.

I have used glGetError but it reports that nothing is wrong. Please help as I have run out of ideas. http://www.opengl.org/discussion_boards/ubb/frown.gif


[This message has been edited by stim (edited 06-25-2001).]

Tim Stirling
06-25-2001, 03:36 AM
Can you post more code!

DFrey
06-25-2001, 03:44 AM
When you say it appears colored, are you saying that that color is the primary color? Or does the color change depending on the texture used? If the color changes as the texture changes, then it sounds like texture mapping is working fine, and that its the texture coordinates that are bad (or possibly the texture matrix).

stim
06-25-2001, 04:59 AM
this is the setup code...
(I have omitted the error checking code for space)

glEnable(GL_TEXTURE_2D);
glGenTextures(1, &m_nTexture);
glBindTexture(GL_TEXTURE_2D, m_nTexture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, array);

this is the drawing code...

glBindTexture(GL_TEXTURE_2D, m_nTexture);
glBegin(GL_QUADS);
glColor3d(1,1,1);
glTexCoord2d(0,0); glVertex2d(-1,-1);
glTexCoord2d(1,0); glVertex2d( 1,-1);
glTexCoord2d(1,1); glVertex2d( 1, 1);
glTexCoord2d(0,1); glVertex2d(-1, 1);
glEnd();

the quad is rendered white only.
is this enough code?

[This message has been edited by stim (edited 06-25-2001).]

Boresight
06-25-2001, 05:33 AM
For each texture binded you must set Min and Mag Filter property.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ...);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, ...);

For some reason if you don't set these properties, the texture isn't displayed.

I have the same problem one week ago (RIVA TNT)

[This message has been edited by Boresight (edited 06-25-2001).]

stim
06-25-2001, 05:42 AM
I tried that but The texture appeared black.

MCote79
06-25-2001, 10:23 AM
Is it possible to make textures affected by lighting? I have a moon texture and I want the light to go around like the sun.

stim
06-25-2001, 11:05 PM
Thank you Boresight. The texture parameters worked. I was using a blank texture. Doh! http://www.opengl.org/discussion_boards/ubb/redface.gif

wXm
06-26-2001, 07:44 AM
Hehe.. done that to.

but what if i want 2 textures and want to set witch texture should show most ?