My game world is rendered into a framebuffer and another texture gets multiplied on top by using a GLSL shader. That works perfectly fine.
Now I tried rendering another quad on top of that with a separate shader but had some difficulties getting that to work. In the end I noticed in debug mode that the first frame looks fine and after that the whole screen turns black (except the second quad).
After adding “glActiveTexture(GL_TEXTURE1);” to the last line suddenly both quads and both shaders showed up and are working fine. But I have no idea why? Any ideas why I have to change the active Texture Unit back to one?
//FrameBuffer renderpass:
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, worldColor.framebufferID);
glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(Player.xPosition-resolution.width/2*camScale, Player.xPosition+resolution.width/2*camScale, Player.yPosition+resolution.height/2*camScale, Player.yPosition-resolution.height/2*camScale, 1, -1);
cameraRender = (int)getTime();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glActiveTexture(GL_TEXTURE0);
sky.render();
skyRender = (int)getTime();
world.render();
worldRender = (int)getTime();
player.render();
playerRender = (int)getTime();
Inventory.render();
inventoryRender = (int)getTime();
Menu.render();
Cursor.render();
DebugScreen.render();
//Normal Renderpass:
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GL11.glOrtho(0, resolution.width, 0, resolution.height, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Color.white.bind();
glUseProgram(light.shaderProgram);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, worldColor.colorTextureID);
glUniform1i(light.the_location0, 0);
glActiveTexture(GL_TEXTURE1);
Tiles.vignette.bind();
glUniform1i(light.the_location1, 1);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(resolution.width, 0);
glTexCoord2f(1, 1);
glVertex2f(resolution.width, resolution.height);
glTexCoord2f(0, 1);
glVertex2f(0, resolution.height);
glEnd();
glUseProgram(0);
glUseProgram(diffuse.shaderProgram);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, Tiles.characters1.getTextureID());
glUniform1i(diffuse.the_location0, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(200, 0);
glTexCoord2f(1, 1);
glVertex2f(200, 200);
glTexCoord2f(0, 1);
glVertex2f(0, 200);
glEnd();
glUseProgram(0);
glActiveTexture(GL_TEXTURE1); // <-- why this?