Jump to content
  • Advertisement
Sign in to follow this  
carleton

OpenGL drawing on top of a glDrawPixels() call

This topic is 4108 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!