PDA

View Full Version : Texture mapping



11-28-2002, 12:55 PM
I'm trying to do texture mapping in opengl with fltk.
I can't seem to make texture mapping work

I just followed some tutorial, and I don't know what the line does exactly.

Here is my code

Initialize part
glEnable (GL_DEPTH_TEST);
int width, height;

unsigned char* data = readBMP("test.bmp", width, height);

glBindTexture (GL_TEXTURE_2D, 1);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0 ,GL_RGB,GL_UNSIGNED_BYTE,data);

reading BMP seems working because I can see that data has some reasonable values.

Here is drawing part
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_MODELVIEW);
glColor3f(0.5,1.0,1.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 1);
glBegin (GL_QUADS);
glTexCoord2f (0.0f,0.0f);
glVertex3f (-0.5f, -0.5f, 0.0f);
glTexCoord2f (1.0f, 0.0f);
glVertex3f (0.5f, -0.5f, 0.0f);
glTexCoord2f (1.0f, 1.0f);
glVertex3f (0.5f, 0.5f, 0.0f);
glTexCoord2f (0.0f, 1.0f);
glVertex3f (-0.5f, 0.5f, 0.0f);
glEnd ();
glDisable(GL_TEXTURE_2D);
glFlush();

This is all I have for opengl code.

Am I missing something here?

GameMaker
11-28-2002, 02:46 PM
Do you call glGenTextures first?

11-29-2002, 12:10 AM
Do I really need that code?
I thought that if I have just one texture, then I can just use number 1 to designate the texture.
Is the code required?

M/\dm/\n
11-29-2002, 12:22 AM
Take a look at NeHe tutorials. That should explain if not all, then most of your questions http://www.opengl.org/discussion_boards/ubb/smile.gif And I think, you should forget about standart textures, nowdays hw is huge enough to handle MipMaped textures with no problems http://www.opengl.org/discussion_boards/ubb/smile.gif

Relic
11-29-2002, 12:46 AM
"Standard" texture is not a good terminology for that. Here immediate mode texture vs. texture objects is meant, not mipmapping.
Texture object _zero_ is the immediate mode texture for all texture targets. That's the one which can be used without texture object initialization. You don't need glBindTexture if you only have one texture.


[This message has been edited by Relic (edited 11-29-2002).]