PDA

View Full Version : Multitexture - glActiveTextureARB throws exception



Arjun
06-03-2010, 03:46 AM
I'm trying to apply two textures to a fragment. As suggested by tutorials everywhere, I tried using glActiveTextureARB(GL_TEXTURE0_ARB) and glActiveTextureARB(GL_TEXTURE1_ARB) for this. My OpenGL version supports GL_ARB_multitexture, I checked. But my program crashes and burns, throwing an "Access violation" error. This happens as soon as it encounters the glActiveTextureARB line.

Can anyone please tell me why this could be happening?

mhagain
06-03-2010, 04:34 AM
What OS are you on? If you're on Windows, did you get a valid pointer to the function using wglGetProcAddress or not? Have you tried running it in a debugger, setting a breakpoint at your call to glActiveTextureARB and examining the value of the function pointer to see if it's non-NULL? Have you tried using glActiveTexture (i.e. without the "ARB" suffix) instead?

Dark Photon
06-03-2010, 05:19 AM
I'm trying to apply two textures to a fragment. As suggested by tutorials everywhere, I tried using glActiveTextureARB(GL_TEXTURE0_ARB) and glActiveTextureARB(GL_TEXTURE1_ARB) for this. My OpenGL version supports GL_ARB_multitexture, I checked. But my program crashes and burns, throwing an "Access violation" error. This happens as soon as it encounters the glActiveTextureARB line.

Can anyone please tell me why this could be happening?
Post a short GLUT test program that illustrates your problem.

I'd guess you haven't initialized an OpenGL context.

Start with this (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=278315#Post2783 15).

Arjun
06-03-2010, 06:24 AM
I'm on Windows. And you were right, the function pointer was NULL. I am ashamed to admit I hadn't bothered calling wglGetProcAddress. I assumed that, since multitexturing has been a core feature for some time now, I wouldn't have to assign the function pointers myself and simply enabling GL_ARB_multitexture would take care of it (I remember reading on some other forum that all this was "automatic").

Thanks again.

Arjun
06-03-2010, 06:29 AM
[Dark Photon] I did initialise the OpenGL context. The problem was the function pointers to glActiveTextureARB and glMultiTexCoord2f.

Apparently, multitexturing is nicer with GLSL. I'll give that a shot after this. And pick your brains if that goes boink. :)

Dark Photon
06-03-2010, 08:51 AM
[Dark Photon] I did initialise the OpenGL context. The problem was the function pointers to glActiveTextureARB and glMultiTexCoord2f.
Ok, things you set up weren't set up.

I must confess, I've become spoiled by OpenGL on Linux. The symbols are in the GL library and you just link with it. Simple as that.


Apparently, multitexturing is nicer with GLSL. I'll give that a shot after this. And pick your brains if that goes boink. :)
Definitely nicer. You just write the texturing formula you want (rather than make a separate GL call for about just about every symbol and every component in the function, trying to describe to GL via smoke signals what the formula looks like :p ).

Arjun
06-04-2010, 12:11 PM
I come to you once again, O Dark Photon, for help. Tried using shaders for multitexturing; didn't seem to work. I followed the Lighthouse3D tutorial on multitexturing using shaders:-

http://www.lighthouse3d.com/opengl/glsl/index.php?textureMulti

I'm drawing quads like this:-

//Draw the back quad
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, this->textures[0]->texture);
glEnable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, this->textures[1]->texture);
glEnable(GL_TEXTURE_2D);

glBegin(GL_QUADS);
glMultiTexCoord2f(GL_TEXTURE0_ARB, 1.0, 1.0); glMultiTexCoord2f(GL_TEXTURE1_ARB, 1.0, 1.0); glVertex3f(500.0f, 500.0f, -500.0);
glMultiTexCoord2f(GL_TEXTURE0_ARB, 0.0, 1.0); glMultiTexCoord2f(GL_TEXTURE1_ARB, 0.0, 1.0); glVertex3f(-500.0f, 500.0f, -500.0);
glMultiTexCoord2f(GL_TEXTURE0_ARB, 0.0, 0.0); glMultiTexCoord2f(GL_TEXTURE1_ARB, 0.0, 0.0); glVertex3f(-500.0f, -500.0f, -500.0);
glMultiTexCoord2f(GL_TEXTURE0_ARB, 1.0, 0.0); glMultiTexCoord2f(GL_TEXTURE1_ARB, 1.0, 0.0); glVertex3f(500.0f, -500.0f, -500.0);
glEnd();

glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);

//Draw the bottom quad
glActiveTextureARB(GL_TEXTURE2_ARB);
glBindTexture(GL_TEXTURE_2D, this->textures[1]->texture);
glEnable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE3_ARB);
glBindTexture(GL_TEXTURE_2D, this->textures[2]->texture);
glEnable(GL_TEXTURE_2D);

glBegin(GL_QUADS);
glMultiTexCoord2f(GL_TEXTURE2_ARB, 1.0, 1.0); glMultiTexCoord2f(GL_TEXTURE3_ARB, 1.0, 1.0); glVertex3f(500.0f, -500.0f, -500.0);
glMultiTexCoord2f(GL_TEXTURE2_ARB, 0.0, 1.0); glMultiTexCoord2f(GL_TEXTURE3_ARB, 0.0, 1.0); glVertex3f(-500.0f, -500.0f, -500.0);
glMultiTexCoord2f(GL_TEXTURE2_ARB, 0.0, 0.0); glMultiTexCoord2f(GL_TEXTURE3_ARB, 0.0, 0.0); glVertex3f(-500.0f, -500.0f, 500.0);
glMultiTexCoord2f(GL_TEXTURE2_ARB, 1.0, 0.0); glMultiTexCoord2f(GL_TEXTURE3_ARB, 1.0, 0.0); glVertex3f(500.0f, -500.0f, 500.0);
glEnd();

glActiveTextureARB(GL_TEXTURE2_ARB);
glDisable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE3_ARB);
glDisable(GL_TEXTURE_2D);


I'm setting the shader samplers "tex" and "l3d" mentioned in the tutorial, using glUniform1f, to 0 and 1, as the texture coordinates. Somehow, I see no visible result. Is there something I'm doing awfully wrong?

Dark Photon
06-10-2010, 05:22 PM
glEnable(GL_TEXTURE_2D);
This statement is meaningless with a fragment shader active. You can nuke these.


I'm setting the shader samplers "tex" and "l3d" mentioned in the tutorial, using glUniform1f, to 0 and 1, as the texture coordinates.
No, that's not the texture coordinates. Those're the texture unit indices (0, 1, ...) -- i.e. what you pass glActiveTexture - GL_TEXTURE0.


Somehow, I see no visible result. Is there something I'm doing awfully wrong?
Well, it's not obvious to me from what you've posted. Post a complete GLUT test program (use the link I suggested as a template).

Arjun
06-11-2010, 12:10 PM
"This statement is meaningless with a fragment shader active. You can nuke these."

I thought I needed to set the texture coordinates and then enable texturing and pass the texture coordinates to the fragment shader (I set gl_TexCoord[0] = gl_MultiTexCoord0 in the vertex shader), which would then use the "tex" and "l3d" values mentioned in the tutorials along with gl_TexCoord[0]'s 's' and 't' values to create the final texel that would be displayed.

"No, that's not the texture coordinates. Those're the texture unit indices"

Thanks for that. Didn't find it explained in those words anywhere.

I got multitexturing working now. The same code as I had before. I was just using really bad textures and couldn't really see the effect. But it's visible now.

Dark Photon
06-11-2010, 05:31 PM
glEnable(GL_TEXTURE_2D): "This statement is meaningless with a fragment shader active. You can nuke these."
I thought I needed to set the texture coordinates and then enable texturing and pass the texture coordinates to the fragment shader
All right except you don't need to "enable texturing". That tells the fixed-function pipeline whether or not to generate code in its internally-generated fragment shader to use that texture. Since you're writing the shader and populating its uniform inputs yourself, you get to decide that ;)


I got multitexturing working now. The same code as I had before. I was just using really bad textures and couldn't really see the effect. But it's visible now.
Good deal!

Arjun
06-12-2010, 03:49 PM
Oh damn, I didn't think about the fact that shaders were just a programmable alternative to the fixed function pipeline, not an entirely different mechanism. I mean, the "internally generated fragment shader" thing sort of eluded me before you mentioned it.

I got a bit ambitious after this and decided to try atmospheric scattering, as Sean O'Neill describes it on Gamasutra. Tried his code but had problems. I guess I'll post that on a different thread. Hopefully, you'll be able to point me in the right direction there too. :)

Thanks again.

Arjun
06-13-2010, 06:43 AM
Bothering you again. I'm having a bit of trouble with atmospheric scattering using shaders (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=278996#Post2789 96). I'd be glad for any help. Please? :)