Wireframe not drawing with glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); - opengl

my renderer works fine if I use
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
but as soon I switch to
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
Nothing is drawn on screen. For some camera config I can sort of see some dots on the border of the screen, but nothing sensical. I am doing some postprocessing on the framebuffer where the image is drawn. What can it be?

Related

Drawing a stationary background

In my program, I am trying to use an image and draw it as a stationary background. The foreground does have some models loaded inside a camera and runnig fine.
However, when I apply a background image, the whole model and other objects don't appear and I can only see the background image appearing over the screen.
I did the disable the Depth_Test before drawing the background and then re-enabled it before drawing the model.
glDisbale(GL_DEPTH_TEST);
bgImage.draw(0,0); //draw the background image. Width and height parameters previously while initializing image
glEnable(GL_DEPTH_TEST);
cam.begin();
//stuff drawn inside
cam.end();
Also tried clearing the Depth Buffer/Depth Color bit after the bgImage.draw but nothing changes.
You need to disable depth writes so that the background doesn't hogs the depth buffer.
glDepthMask(GL_FALSE);
background();
glDepthMask(GL_TRUE);
Or you simply clear only the depth buffer after drawing the background:
glDisable(GL_DEPTH_TEST);
background(); // instead of clearing the color
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);

OpenGL alpha blending sometimes creating black quads

I'm trying to make simple shading for a 2D OpenGL scene by placing semi-transparent black quads over the scene, but in certain places instead of darkening the scene it completely blacks it out. I'm using glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA) for the shader quads, and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) for all the other drawing underneath.
This normally works, dimming the area under the semi-transparent quad, but in certain situations it behaves oddly. When the area under the semi-transparent quad has only had one quad drawn behind it, it behaves normally. When another quad (or multiple quads) are drawn on top of the back quad, it sometimes behaves normally, sometimes blacks out the quad entirely, or sometimes blacks out everything beneath the last-drawn quad (e.g. if I had a red texture with a blue dot on top of it, the red beneath would be blacked out, but the blue dot would remain unchanged).
I thought this looked like the quads drawing in the wrong order, but I have GL_DEPTH_TEST disabled, so I'm not sure if this is odd behavior from the blending, misorder, or something else entirely. Any ideas as to what could be causing this?

Painting app using FBO in OpenGL

I am working on an application in C++ and OpenGL (using Cinder library).
It is simply getting mouse input, and in the draw method draws circles on the mouse position to the FBO. After that the FBO is drawn to the screen. The FBO isn't cleared everytime, so the previous circles are still in it. The problem is that when I draw new circle to the FBO, it isn't drawn on top of it, but instead under the previous content of the FBO. The FBO is created only with width and height parameters and no other settings. It's also cleared in the setup().

OpenGL AntiAliasing and Background Quad

I'm drawing a background behind my 3D scene which works as expected (code below). I'm also anti-aliasing the scene using the accumulation buffer (chapter 10 of the red book).
...loop several times (say, n) through code that jitters and draws the image (jittering is moving the image to a slightly different position), accumulating the data with
glAccum(GL_ACCUM, 1.0/n)
and finally calling
glAccum(GL_RETURN, 1.0)
However, I do not want to anti-alias the background. The problem is that calling glAccum with GL_RETURN copies (overwrites) the values in the color buffer (rather than using the depth test and blend functions, etc) to mask the values being written to the color buffer.
How can I draw the background before or after anti-aliasing the 3D scene so that the background looks just like it does when I draw the 3D scene without anti-aliasing?
// Draw the background.
glMatrixMode GL.GL_PROJECTION
glLoadIdentity
glMatrixMode GL.GL_MODELVIEW
glLoadIdentity
glPolygonMode GL_FRONT_AND_BACK, GL_FILL
glDisable glcDepthTest
glBegin bmQuads
// Call glColor and glVertex here.
glEnd
glEnable glcDepthTest
If you're just after the appearance, and not looking for a rendering acceleration, don't jitter the background. Your loop would draw the background, apply the jitter, then draw the foreground. Since the background never moves, the accumulated background would be aliased.

Why do my semi-opaque vertices make background objects brighter in OpenGL?

I am rendering 4 vertices (a square) in front of a colored cube. The vertices are colored white, but are blended at 0.5f.
Related: Why does my colored cube not work with GL_BLEND?
Please could someone tell me why the colored cube appears brighter when obscured by the semi-opaque square?
Cube rendered without square in front:
Normal cube http://img408.imageshack.us/img408/2853/normalcube.png
And, rendered with the square:
Cube with square http://img142.imageshack.us/img142/6255/brightsquare.png
Please see the code used to create the colored cube, the code used to actually draw the cube, and the code where the cube and square are rendered.
This is the code in my init function:
glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
I'd say it's because your semi-transparent square gets added to the existing pixels, thus incrementing their intensity.
The documentation for glBlendFunc() recommends setting the second parameter to GL_ONE_MINUS_SRC_ALPHA, that is the boilerplate for implementing transparency. Try it.