PDA

View Full Version : problem of opengl extention



wf
02-24-2002, 12:52 PM
I use
glActiveTextureARB
glMultiTexCoord2fARB
to do multi_texturing.

It is working. But after I use this, the drawing code after this seems can not bind textures any more.

Is it the bug of opengl extention?
Or I need to do something after things done?

the following is my code:

//initializing multi texturing
g_misc.glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glActiveTextureARB");
g_misc.glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC) wglGetProcAddress("glMultiTexCoord2fARB");

if(!g_misc.glActiveTextureARB | | !g_misc.glMultiTexCoord2fARB)
{
g_able_multi_texturing=0;
g_out.Insert("This version of OpenGL does not support multitexturing!\n");
}
else
g_able_multi_texturing=1;

g_misc.cloud_texture_index =
CMy_misc_func::load_general_texture("fog.bmp");

g_misc.glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, g_tex_general[g_play_ground_box_texture[BOX_RIGHT]].ID);
g_misc.glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, g_tex_general[g_misc.cloud_texture_index].ID);

glBegin(GL_QUADS);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f - wrap, 0.0f);
glVertex3f(x + width, y, z);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 0.0f);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f - wrap, 0.0f);
glVertex3f(x + width, y, z + depth);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 1.0f);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f - wrap, 1.0f);
glVertex3f(x + width, y + height, z + depth);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 1.0f);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f - wrap, 1.0f);
glVertex3f(x + width, y + height, z);
glEnd();

SirKnight
02-24-2002, 01:49 PM
When your finished drawing you should disable your textures like this:
glActiveTextureARB( GL_TEXTURE0_ARB );
glDisable( GL_TEXTURE_2D );
glActiveTextureARB( GL_TEXTURE1_ARB );
glDisable( GL_TEXTURE_2D );

Now if you are not using GL_TEXTURE_2D for one or more of the texture units then replace GL_TEXTURE_2D in the disable func with what ever your using. So if for example your using a cube map in texture unit 1 you should do this:

glActiveTextureARB( GL_TEXTURE1_ARB );
glDisable( GL_TEXTURE_CUBE_MAP_ARB );

-SirKnight

wf
02-24-2002, 02:40 PM
Hi, thanks for the reply.
But seems not work. I do not use any features other than GL_TEXTURE_2D. There is anything else I should take care of?
Thank in advance.

the code again:
g_misc.glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, g_tex_general[g_play_ground_box_texture[BOX_RIGHT]].ID);
g_misc.glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, g_tex_general[g_misc.cloud_texture_index].ID);

glBegin(GL_QUADS);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f - wrap, 0.0f);
glVertex3f(x + width, y, z);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 0.0f);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f - wrap, 0.0f);
glVertex3f(x + width, y, z + depth);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 1.0f);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f - wrap, 1.0f);
glVertex3f(x + width, y + height, z + depth);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 1.0f);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f - wrap, 1.0f);
glVertex3f(x + width, y + height, z);
glEnd();

g_misc.glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);
g_misc.glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);

//glDisable(GL_TEXTURE_2D);

kon
02-24-2002, 11:30 PM
I prefer activating textures starting with the biggest one and ending with GL_TEXTURE0_ARB. The same for disabling: Start with biggest active texture stage so that at the end you disable GL_TEXTURE0_ARB. Now you know that you always are in stage 0. In your code just exchange the order of GL_TEXTURE0_ARB and GL_TEXTURE1_ARB calls and when drawing another textured object don't forget enabling texturing again.

kon

wf
02-25-2002, 03:37 AM
thank a lot, it is working.
I did not change anything other than the ordering and I works fine. I think it is a bug in openGL extension.

The code again and thanks again:

static float wrap = 0;
wrap += 0.0015f;

g_misc.glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, g_tex_general[g_misc.cloud_texture_index].ID);
g_misc.glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, g_tex_general[g_play_ground_box_texture[BOX_RIGHT]].ID);

glBegin(GL_QUADS);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f - wrap, 0.0f);
glVertex3f(x + width, y, z);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 0.0f);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f - wrap, 0.0f);
glVertex3f(x + width, y, z + depth);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 1.0f);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f - wrap, 1.0f);
glVertex3f(x + width, y + height, z + depth);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 1.0f);
g_misc.glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f - wrap, 1.0f);
glVertex3f(x + width, y + height, z);
glEnd();

g_misc.glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);
g_misc.glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);

Nutty
02-25-2002, 04:00 AM
It's not a bug, it seems you were previously leaving your active texture unit to be unit 1, when you assumed it would be unit 0.

Nutty

wf
02-25-2002, 04:19 AM
emmmmm, thx!
I think you are right.