drawing on top of a glDrawPixels() call

Started by
2 comments, last by Brother Bob 16 years, 11 months ago
I would like to prefix this by saying I don't know a great deal about OpenGL programming. But I am neck deep in it, so I must move forward;) I am working on an application that draws images on the screen. Two to be exact. They live side by side so the user can do a comparison. I need to draw a circle on top of both images. When I draw that circle (either before or after the glDrawPixels() to draw the images), the circle always shows up behind the image. I can see only part of the circle, the part that is being drawn outside of the images. Before calling the code to display the image or the circle:

	CRect rect;
	GetClientRect(rect);

	glViewport( 0, 0, rect.Width(), rect.Height());
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, (GLdouble) rect.Width(), 0.0, (GLdouble) rect.Height());
	glMatrixMode(GL_MODELVIEW);

	glRasterPos2i(0, 0);
	glClearColor(0.5, 0.5, 0.5, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);

When I am displaying the image I am doing this, basically:

	glPixelTransferf(GL_RED_SCALE, 1.0);
	glPixelTransferf(GL_GREEN_SCALE, 1.0);
	glPixelTransferf(GL_BLUE_SCALE, 1.0);
	glDisable(GL_BLEND);
	glRasterPos2i(xOffset, 2);
	glDrawPixels(x, y, GL_RGB, GL_UNSIGNED_BYTE, image);

And this is how I am drawing the circle:

	glBegin(GL_LINE_LOOP);
	for(float i = 0; i < PI*2; i += increments)
	{
		x = radius * sin(i) + xmid;
		y = radius * cos(i) + ymid;
		glVertex2f( x, y);
	}
	glEnd();

Carleton
Advertisement
You're drawing both the image and the circle at a depth of Z=0. With the default depth compare function, GL_LESS, the circle is not drawn where the image was drawn, because it fails the depth test. It's not obvious from your code or description if depth test is enabled or not, but it sure sounds like it is. If it is, disable it when drawing the image so it won't pollute the depth buffer.
Thank you. I switch to using the glVertex3f() and setting the z to 1 and now the circle is on top, but...

When I change the flag to stop drawing the circle, there is still a circle cut out of the image. I have a feeling that I need to clear the scissor buffer or something to eliminate the circle. How is that done?

Carleton
Clear the depth buffer. Add the GL_DEPTH_BUFFER_BIT bit to the mask in glClear.

This topic is closed to new replies.

Advertisement