following scenario:
i'm creating an OpenGL texture and a framebuffer and associated objects
GLuint frameBuffer = 0, colorBuffer, depthBuffer;
glGenFramebuffers(1, &frameBuffer);
int maskRenderingWidth = 1 * settings.width, maskRenderingHeight = 1 * settings.height;
//define texture
glUseProgram(screenMaskRenderingProgramId);
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, maskRenderingWidth, maskRenderingHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glUseProgram(offscreeenMaskRenderingProgramId);
//setup framebuffer stuff
glGenRenderbuffers(1, &colorBuffer);
glGenRenderbuffers(1, &depthBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, maskRenderingWidth, maskRenderingHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, maskRenderingWidth, maskRenderingHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
glDrawBuffers(1, DrawBuffers);
I then render a polygon to that framebuffer which i put into a texture. Afterwards I draw another polygon but this time to the screen buffer. Finally I span a quad on the whole screen and pass the uv coords (0,0), (0,1), (1,1) and (1,0) and the previously created texture to it.
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glUniform1i(textureLocation,0);
What i want to achieve is, if that texture has at some texture coords certain values i want to draw the corresponding texture values, otherwise i want the output on coord (u,v) to be untouched.
if(textureProj(mask, uv_coords).a == 1) {
gl_FragColor = textureProj(mask, uv_coords);
}
After some trying i figured out that always everything from the texture is drawn. It seems my texture is somehow corrupt as isinf and isnan return true for textureProj(mask, uv_coords) for every uv_coord. How could that be possible and someone has an idea what might be broken here?
in vec4 uv_coords;
uniform sampler2D mask;
void main() {
vec4 c = textureProj(mask, uv_coords);
bvec4 inf = isinf(c);
if(inf.r == true && inf.g == true && inf.b == true && inf.a == true) {
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
});
This yields a completely white screen. Same applies for
inf = isnan(c)
Anyone has an idea whats going on here?
EDIT:
I forgot to mention that if I leave out the if clause in the fragment shader and just do
in vec4 uv_coords;
uniform sampler2D mask;
void main() {
vec4 c = textureProj(mask, uv_coords);
gl_FragColor = c; });
the texture is drawn properly. Makes it even more strange.
EDIT2:
ok, i've read that not setting gl_FragColor gives undefined behavior. so my approach will be to upload the two textures to that specific fragment shader and render everything in one pass