PDA

View Full Version : Anaglyph rendering and glBlendFunc()



Huusslv
05-08-2015, 04:00 AM
Hello,

I am developing application for my University project where I am doing anaglyph rendering.
In my project I am using:

FREEGLUT
Using OpenGL 3.3 with Shaders #330
Using C++



I am a beginner with OpenGL API, but I think I have learned the basics so please bear that in mind.
So the problem I am having with is the function


glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);

which causes unwanted transparancy between different objects rendered.

My rendering function follows like this (I am also using face culling):


glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glClear(clearOptions | GL_DEPTH_BUFFER_BIT);

glUseProgram(shaderProgram);

// Sets active the left eye perspective matrix
// draw scene

glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);

// Sets active the right eye perspective matrix
// draw scene

glUseProgram(0);

glutSwapBuffers();
glutPostRedisplay();


In the attachments I have highlighted the problematic areas.
My question is what can I do so that the blending only happens with the two images of the same object (since I am doing anaglyph rendering, I have to render each object twice, I want the blending to happen only with these two images for each object).

I hope I was clear enough, if you need more information then please ask.

Thanks!

Huusslv
05-08-2015, 07:15 AM
Could this be solved by rendering the scene to two textures and than processing them in a shader?
Using this methord I think I wouldnt need to use the blending....

Got this idea from this thread: https://www.opengl.org/discussion_boards/showthread.php/172991-Anaglyphs-without-glColorMask

GClements
05-08-2015, 10:36 PM
I suggest using glColorMask().

Another option is to render each view to a separate texture then blend the textures as a final pass (this requires FBOs, but it doesn't require shaders).

But there's really no reason not to use glColorMask(). What the creator of the thread you linked to seemed to forget is that you can't actually choose the colours if the output is to a monitor. You're stuck with the monitor's primaries, and if your glasses don't match the primaries, you need different glasses. Attempting to use a different colour will just end up using a mix of primaries which will result in bleeding (the tristimulus model doesn't work for anaglyphs; a mix of primaries which looks like a particular colour to the naked eye isn't actually the same thing as a monochromatic source of that colour).