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..???

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.

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....

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.

commented: Showed me a light...thanks !! +1

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.