Login  Register

Texture JOGL -> GLSL

Posted by AlexRNL on May 16, 2011; 10:06am
URL: https://forum.jogamp.org/Texture-JOGL-GLSL-tp2947210.html

Hi guys!

I'm currently working on a JOGL project and I've run into something strange.

I'm using shaders to process my texture here is the (simplified) code that i'm using :

Shader setup
gl.glShaderSource(vertexShader, vertexFile.length, vertexFile, null);
gl.glShaderSource(fragmentShader, fragmentFile.length, fragmentFile, null);

gl.glCompileShader(vertexShader);
gl.glCompileShader(fragmentShader);
programShader = gl.glCreateProgram();

gl.glAttachShader(programShader, vertexShader);
gl.glAttachShader(programShader, fragmentShader);
		
processGLErrors(gl.glGetError(), "b4");
textureLocation = gl.glGetUniformLocation(programShader, "Texture"); //FIXME should be after linking...
processGLErrors(gl.glGetError(), "text-loc");

gl.glLinkProgram(programShader);

xMinLocation = gl.glGetUniformLocation(programShader, "xMi");

Rendering loop
currentTrace.getTexture() is a com.sun.opengl.util.texture.Texture object
gl.glUseProgram(programShader);

currentTrace.getTexture().enable();
currentTrace.getTexture().bind();
gl.glUniform1i(textureLocation, currentTrace.getTexture().getTextureObject());
gl.glUniform1f(xMinLocation, xMin);

gl.glBegin(GL.GL_QUADS);
//Drawing
gl.glEnd();
currentTrace.getTexture().disable();
gl.glUseProgram(0);

First, I realized that the binding of the texture was not necessary because I'm doing it 'manually' in my shader. But when I remove the lines, it wasn't working all the time...

Also, when I'm using that code, i'm getting a correct result (textures applied and processed by the shader). But it I have an invalid operation error just after getting the location of Texture which appeared to be normal because I should only do that after the linking. When I moved the line after the linking, it wasn't working anymore!! The shaders were still working but there was no texture.

Do any of you have a clue of why this is happening?
Thanks :)