Sign in to follow this  

Ortho Mode causing problems with Object Selection

This topic is 4583 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 am using the code below to create a crosshairs tracked by the mouse.
	//////////////////////////Draw CrossHairs//////////////////////////
	glEnable(GL_TEXTURE_2D);
													// Storage For Window Dimensions
	GetClientRect(g_hWnd, &g_rRect);
	glMatrixMode(GL_PROJECTION);								// Select The Projection Matrix

	glPushMatrix();												// Store The Projection Matrix
		glLoadIdentity();											// Reset The Projection Matrix	

		glOrtho(0,g_rRect.right,0,g_rRect.bottom,-1,1);				// Set Up An Ortho Screen
		glMatrixMode(GL_MODELVIEW);									// Select The Modelview Matrix
		glTranslated(mouse_x,g_rRect.bottom-mouse_y,0.0f);			// Move To The Current Mouse Position
		Object(16,16,8);											// Draw The Crosshair
		glDisable(GL_TEXTURE_2D);
		glMatrixMode(GL_PROJECTION);								// Select The Projection Matrix

	glPopMatrix();												// Restore The Old Projection Matrix

	glMatrixMode(GL_MODELVIEW);								// Select The Modelview Matrix
	//////////////////////////////////////////////////////////////////////////////

	
I am also using object selection to detect when an object is clicked, and then dispatching a shot/fire to where the object is. The object selection and collision detection/handling works fine until the above code is introduced to display the crosshairs. The firing still occurs, but the object ID is not picked up. Im using the code from an Object Selection Tutorial which assigns object IDs to a matrix each time an object is drawn in order to track whether that object is clicked on. Any ideas why the above code would be causing problems?? Im guessing its something to do with changing the Projection/ModelView matrices - the Object Selection method changes between them to, though it does appear to reset them.

Share this post


Link to post
Share on other sites
wait, nvrm, just remembered the correct way to do it.

glMatrixMode(GL_PROJECTION);
glPushMatrix();

glLoadIdentity();
glOrtho(0,800,0,600,-1,1);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

// anything you want orthodraphic here

glMatrixMode(GL_PROJECTION);
glPopMatrix();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

Share this post


Link to post
Share on other sites

This topic is 4583 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this