0

Hello World ! I have problem regarding displaying a text which should not be affected by model view transformation...I have to display a cross-hair at the center screen for targetting enemies...when I put cross hair in the middle of center, it gets affected by some model view trasformation...as in pC game..scores are written either on RHS and LHS are not affected by camera rotation....how they do this ? Plz help me...somebody..anybody..???

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by pcgamer2008
0

Make two "layers" for your game. Have one render the 3D world (perspective) and the other for rendering the HUD (orthographic).

Only apply your camera transformations to your 3D world layer and set your camera position to 0,0,0 for the HUD layer.

0

I have seen PC games which provides score either on RHS AND LHS , but not affected by camera rotation...how remains at their same position..how they do this...
The way you mentioned above ...how can we design two layers...hello buddy...can you give me some technical hint.....I am struggling to so this and consumed several hours of mine....

1

You could use two functions for drawing like this.

void RenderOverlay( GLenum mode )
{
	glViewport(0, 0, (GLsizei) WINDOW_WIDTH, (GLsizei) WINDOW_HEIGHT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glTranslatef(0,0,0); //dont actually have to do since it is default 0
	//also have rotation at 0
	ORTHO_WIDTH = ORTHO_HEIGHT*((GLdouble)WINDOW_WIDTH/(GLdouble)WINDOW_HEIGHT);
	glOrtho(0, ORTHO_WIDTH, 0, ORTHO_HEIGHT, -1, 20);

	glMatrixMode(GL_MODELVIEW);

	glLoadIdentity();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();
		//draw your crosshair and other HUD elements
		glPushMatrix();
			glBegin(GL_QUADS);
			
			glEnd();
		glPopMatrix();
	glPopMatrix();
}

void RenderScene( GLenum mode )
{
	glViewport(0, 0, (GLsizei) WINDOW_WIDTH, (GLsizei) WINDOW_HEIGHT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();


	camera.Position();
	
	gluPerspective(60, (GLfloat) WINDOW_WIDTH/ (GLfloat) WINDOW_HEIGHT, 0.1, 60.0);

	glMatrixMode(GL_MODELVIEW);

	glLoadIdentity();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();
		//draw world objects
		glPushMatrix();
			glBegin(GL_QUADS);
			
			glEnd();
		glPopMatrix();
	glPopMatrix();
}

I doubt you can use this code directly but hopefully you can get an idea of the method I'm showing.

Votes + Comments
Showed me a light...thanks !!
0

hello sfuo !!! thanks for technical help...I will try to determine the logic in my code from above code...thanks for showing that we can mix 2D with 3D....:)

"EFFORT NEVER DIES"-real experience

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.