I am confused about textures and cubemaps in OpenGL.
Let's say I want basic texture mapping. I do:
GLuint texture0;
glGenTextures(1, &texture0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture0);
and then I set up glTexImage2D
and call glUniform1i(glGetUniformLocation(shader_program, "texture_sampler"), GL_TEXTURE0)
and all is well.
Now, I also want to use a cubemap for environment mapping. I thought, also using this post as reference, that I should do like this:
GLuint texture1;
glGenTextures(1, &texture1);
glActiveTexture(GL_TEXTURE0+1);
glBindTexture(GL_TEXTURE_CUBE_MAP, texture1);
and then glUniform1i(glGetUniformLocation(shader_program, "cubemap_sampler"), GL_TEXTURE0+1)
.
However, this does not work, and only renders a black object.
On the other hand, if I do not run glActiveTexture(GL_TEXTURE0+1)
but instead stick to GL_TEXTURE0
everything is fine.
According to my understanding, this is not how it should be...
Can anyone shed some light as to what is going on?
I am using GLSL #version 440
.