Hello, I want to show a small transparent texture B over a large texture A.
I want only the texture A for VAO[0]
and only texture B for VAO[1]
but openGL don't understand that and mix texture A with texture B over the vao[0] and over the vao[1] too.
Here is my shader.fp :
Code :#version 150 core // Entrée in vec2 coordTexture; // Uniform uniform sampler2D texBackground; // my textureA uniform sampler2D texMenu; // my texture B // Sortie out vec4 outColor; void main() { vec4 colBackground = texture(texBackground, coordTexture); vec4 colMenu = texture(texMenu, coordTexture) * vec4(1.0, 1.0, 1.0, 0.5); outColor = mix(colBackground, colMenu, 0.5); }
Here is my load textures :
loadTexture(0) for texture A and loadTexture(1) for texture B
Code :void GameRender::loadTexture(int const &IdTexture) { // generate texture names VTexture.push_back(0); glGenTextures(1, &VTexture.back()); GLenum err; while((err = glGetError()) != GL_NO_ERROR) { std::cerr << "(gameRender.cpp) OpenGL generate textures, error : " << err << std::endl; return -1; } // utilisation des textures if(!IdTexture) glActiveTexture(GL_TEXTURE0); else glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, VTexture.back()); // specify a two-dimensional texture image if(PVImage_) glTexImage2D(GL_TEXTURE_2D, 0, 3, PVImage_.data()->back().size().width, PVImage_.data()->back().size().height, 0, GL_RGB, GL_UNSIGNED_BYTE, it->data); // set textures parameters // GL_NEAREST : Returns the value of the texture element that is nearest (in Manhattan distance) to the specified texture coordinates. // GL_TEXTURE_MAG_FILTER : The texture magnification function is used whenever the level-of-detail function used when sampling from the // texture determines that the texture should be magified. // GL_TEXTURE_MIN_FILTER : The texture minifying function is used whenever the level-of-detail function used when sampling from the texture // determines that the texture should be minified. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); }
And now my paint, I'm working with QT :
Code :void GameRender::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef (0.0, 0.0, -5.0); GLint uniformId = glGetUniformLocation(programID, "resolution"); // activation du shader glUseProgram(getProgramID()); glUniform2i(uniformId, width_, height_); glBindBuffer(GL_ARRAY_BUFFER, vbo[1]); glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, VTexture.front()); glUniform1i(glGetUniformLocation(programID, "texBackground"), 0); // dessine les objets au format triangles vao[0].bind(); glDrawArrays(GL_TRIANGLES, 0, 6); vao[0].release(); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, VTexture.back()); glUniform1i(glGetUniformLocation(programID, "texMenu"), 1); vao[1].bind(); glDrawArrays(GL_TRIANGLES, 0, 6); vao[1].release(); // lance le shader glUseProgram(0); }
Thank you, sorry for my bad english :-)