problem with passing textures to GLSL Shaders

hello ,

i am a newbie in opengl but i have given a difficult task of creating an ray cast application for which i need to pass 4- 5 textures to my glsl shaders. i have 2 issues


when i pass textures to my shaders like this , i get the output image on my screen

    texture_locationTemp = glGetUniformLocation(p2, "temporarytexture");
glUniform1i(texture_locationTemp, 1); 
texture_locationVol = glGetUniformLocation(p2, "VolumeTexture");  
glUniform1i(texture_locationVol, 2);
    texture_locationDir = glGetUniformLocation(p2, "Directiontexture"); 

glBindTexture(GL_TEXTURE_2D,  swapLogic[ 1- currentSurface]);
glBindTexture(GL_TEXTURE_3D, Volumetex3d);
glBindTexture(GL_TEXTURE_2D, texIDBack);

But when i pass textures like this (Starting from location GL_TEXTURE0 instead of GL_TEXTURE1), i get the distored image.

texture_locationTemp = glGetUniformLocation(p2, “temporarytexture”);
glUniform1i(texture_locationTemp, 0);
texture_locationVol = glGetUniformLocation(p2, “VolumeTexture”);
glUniform1i(texture_locationVol, 1);
texture_locationDir = glGetUniformLocation(p2, “Directiontexture”);

glBindTexture(GL_TEXTURE_2D,  swapLogic[ 1- currentSurface]);
glBindTexture(GL_TEXTURE_3D, Volumetex3d);
glBindTexture(GL_TEXTURE_2D, texIDBack);

i am not able to understand this starange behavior , seems like    
 GL_TEXTURE0 does not work.


ISSUE 2 is related to issue 1)

in the beginning before starting rendering ( before onpaint method),
i m creating 7-8 2d textures and 1-2 3d textures which i will pass further to my shaders during final rendering step… and this code is executed only once during execution…

Gluint Volumetex3d = textureHandlerObj.Create3DTexture(path,rawdata);

Gluint texIDEmptySpaceTexture = Create3DTextureEmptyScpaceTexture();

Gluint crop2dTex = Create2DTexture(viewPort.width,viewPort.height);

Gluint texIDBack = Create2DTexture(viewPort.width,viewPort.height);

Gluint texIDfront = Create2DTexture(viewPort.width,viewPort.height);

the issue is that if i change the order of creation of these textures, the output on my screen changes…

for instance if i change the order to

Gluint Volumetex3d = textureHandlerObj.Create3DTexture(path,rawdata);

Gluint texIDEmptySpaceTexture = Create3DTextureEmptyScpaceTexture();

Gluint crop2dTex = Create2DTexture(viewPort.width,viewPort.height);

[b]Gluint texIDfront = Create2DTexture(viewPort.width,viewPort.height);

Gluint texIDBack = Create2DTexture(viewPort.width,viewPort.height);[/b]

now texidFront is created before textureIdBack…

code inside all this functions like similar to this ( using GL_TEXTURE_2D for 2d texture and GL_TEXTURE_3D for 3d texture)…

     GLuint img;
glGenTextures(1, &img);
glBindTexture(GL_TEXTURE_2D, img);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB,  width, height, 0,  GL_RGBA, GL_FLOAT, data);

i dont understand why order of creation of this textures effect my output…

what i think can be a bug is

if i use the order no 1 then the the texture binded to GL_TEXTURE_2D after the end of the function is texIdfront but if i use order no 2 then it is texIdBack

i think this binding switch is somewhere casuing the problem due to which these textures are not passed to shaders properly which cause the distortion.

but i m not able to find out what i am missing and what i have to do to make it work for any order ( why it deopends upon order)…

PLZ HELP … :frowning:

I’ve never seen that behavior. Are you sure you have a shader bound (glUseProgram) before calling glUniform?

I can also suggest a debugger

yes i m pretty sure that i m using the glUseprogram…

as i have told i m getting output if i use a particular sequence of code …

like using GL_TEXTURE1 instead of GL_TEXTURE0 inside glActiveTexture function.

and also if i used particular order of Texture creation…

so shader is definitely being used.

i need a debugger , which allow me to put breakpoints inside my shader file.

i m an Idiot … unknowingly i have commented some of my code due to which i was getting the weird results…

this topic can be closed… :slight_smile: