My problem is: glGetUniformLocation() always give me -1.
Althogh it fails to set the sampler, the shader program works almost correct, excepts only the first texture is working.
The glslcompiler would strip out the unused variables hence their locations will be -1. To resolve this, you must use the variable at hand. In your case, you are not using the sp_cloud and sp_bump samplers hence their locations will be -1.
To resolve this, u must use the sampler in the shader.
Another thing, you dont have to declare a uniform in the vertex shader if that uniform is only used in the fragment shader.
But what Alfonse is saying is correct. Perhaps the book has a typo and adding in a space to the variable name will also give that variables location as -1 since the variable does not exist. Remove the trailing space.
First of all, I’m sure the image is loaded correctly.
And the mixture mechanism in fragment shader is working correctly, while I’ve tested it using a const vec4 as cloud color.
But when I use the sampler of the cloud (should be GL_TEXTURE1), it always give me the color on the ground (GL_TEXTURE0). Is there anything wrong on the texture object?
THe reason why your multitexturing is not working is b/c u have multiple textures. Now u r setting the sampler uniform locations to 0,1 and 2 so u must bind the textures to the texture targets 0 1 and 2 like this if ur shader is using three samplers,
glTexParameteri affects the currently bound texture object for the active texture unit (ie. not the texture unit by itself), so you will need to bind the texture you want to modify before calling it.
Because texture parameters are stored with the texture object, you don’t need to re-apply every time you bind the texture object in this way either, just once at texture initialization will do.
glEnable(GL_TEXTURE_2D) is no longer needed for shaders, since shader programs will use the texture bound to the texture unit whether you have enabled or disabled the texture unit for fixed-function. glTexEnvi is also deprecated in core OpenGL, and probably isn’t needed if you are solely using shaders.
I have binded different layers, in a different way.
In my texture class, it has a layer property and a id property. In the “apply()” method of texture class, it has things like this:
So if I call "apply()"method on 3 different texture objects that has different layer, they should be activated to those layers.
Is “layer” an OpenGL enumerator, or is it an integer starting at 0? Because if it’s the latter, you need to do what Dan said and add GL_TEXTURE0 to the layer in your glActiveTexture call.
Are you correctly passing the values 0 to 2 as uniform values (layer - GL_TEXTURE0), rather than “layer” which is GL_TEXTURE0…GL_TEXTURE2.
ps. The OpenGL spec guarantees that