glActiveTexture does not switch texture unit

Started by
3 comments, last by 21st Century Moose 10 years, 9 months ago

Hi

I'm trying to pass 2 textures to fragment shader. But in shader only one texture is avaible.

I found that problem is in glActiveTexture.

After call with any args, like glActiveTexture(GL_TEXTURE1), glActiveTexture(GL_TEXTURE2) .... i alway end in texture unit 0

here is part of code:


glActiveTexture(GL_TEXTURE0);

     // debug
     GLenum e = glGetError(); // e = 0
     GLint nn; 
     glGetIntegerv(GL_ACTIVE_TEXTURE, &nn); // nn = GL_ACTIVE_TEXTURE = GL_TEXTURE0 

glBindTexture(GL_TEXTURE_2D, leftEyeTextureHandle);

glActiveTexture(GL_TEXTURE1); // !!! <- it does not work

     //debug
     GLenum e = glGetError(); // e = 0
     GLint nn; 
     glGetIntegerv(GL_ACTIVE_TEXTURE, &nn); // nn = GL_ACTIVE_TEXTURE = GL_TEXTURE0 !!!!!! 

glBindTexture(GL_TEXTURE_2D, rightEyeTextureHandle);

I already cheacked:

- GL_EXTENSIONS for GL_ARB_multitexture

- tested "clean" example for multitexturing program and it work on same computer (GL_ACTIVE_TEXTURE gives GL_TEXTURE1 ...after glActiveTexture(GL_TEXTURE1));

- glActiveTextureARB

- GL_MAX_TEXTURE_IMAGE_UNITS = 20

- GL_MAX_TEXTURE_UNITS = 4

- tests on other computers (gfx ati / nvidia)

Problem is in opengl state but i can't figure where is problem.

Is there any "switch" to turn off multitexturing ?

fragment program:


#version 150

uniform sampler2D left;
uniform sampler2D right;

in vec2 UV;

out vec3 color;

void main(){
	if (mod(trunc(gl_FragCoord.x), 2.0) < 0.5)
	{ 
		color = texture(left, UV); 
	} else { 
		color = texture(right, UV); 
	}
}
Advertisement

Found solution!

Problem was in init of glActiveTexture:


PFNGLACTIVETEXTUREARBPROC pglActiveTexture = NULL;

#define glActiveTexture pglActiveTexture;

pglActiveTexture = (PFNGLACTIVETEXTUREPROC) wglGetProcAddress("glActiveTextureARB");

For some reason when i replace:

glActiveTexture(GL_TEXTURE1);

with

pglActiveTexture(GL_TEXTURE1);

it start working.

Why not use glew. That way you do not have to worry about setting up all the extension.

Why not use glew. That way you do not have to worry about setting up all the extension.

Because i'm writing mod to game, and everything i do, is in intercepted SwapBuffer.

I do not load any libs.

You can statically link to GLEW and not need to load any libs.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement