# How to got about using these modes?

## Recommended Posts

MARS_999    1627
I am not sure on what to do, but assuming if I want to display text using xy screen coordinates I need to go back into glOrtho mode and then display the text and then go back to gluPerspective mode to do my rendering I am doing currently? What steps or methods do I need? Any tutorials? Thanks

##### Share on other sites
Endar    668
Don't quote me on this, but I have a feeling it would go something like this:

glMatrixMode(GL_PROJECTION);glLoadIdentity();// call to glOrtho// render stuffglMatrixMode(GL_PROJECTION);glLoadIdentity();// call to glPerspectiveglMatrixMode(GL_MODELVIEW);// render stuff

##### Share on other sites
_the_phantom_    11250
- switch to projection matrix
- push matrix
- call to glOrtho to setup new matrix
- swap to modelview matrix
- draw as normal
- swap to projection matrix
- pop old matrix off stack

thats probably the easiest way todo it.

##### Share on other sites
MARS_999    1627
Quote:
 Original post by phantom- switch to projection matrix- push matrix- call to glOrtho to setup new matrix- swap to modelview matrix- draw as normal- swap to projection matrix- pop old matrix off stackthats probably the easiest way todo it.

Thanks Phantom I will give it a go.

##### Share on other sites
MARS_999    1627
Well looks like no luck so far?

//draw text 	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	glOrtho(0.0, gWidth, gHeight, 0.0, -1.0, 10.0);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	glBegin(GL_QUADS);	glColor3f(1.0f, 0.0f, 0.0);	glVertex2f(0.0f, 0.0f);	glVertex2f(10.0f, 0.0f);	glVertex2f(10.0f, 10.0f);	glVertex2f(0.0f, 10.0f);	glEnd();	//switch back to perspective mode	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluPerspective(45.0f, gAspect, 3.0f, 200.0f);	glMatrixMode(GL_MODELVIEW);

##### Share on other sites
Code-R    136
you're re-loading identity on the model view matrix, and you have an unnecessary gluPrespective call. Do as phantom said, namely:

glMatrixMode(GL_PROJECTION);//ADDEDglPushMatrix();//glLoadIdentity();glOrtho(0.0, gWidth, gHeight, 0.0, -1.0, 10.0);glMatrixMode(GL_MODELVIEW);//ADDEDglPushMatrix();//glLoadIdentity();	glBegin(GL_QUADS);	glColor3f(1.0f, 0.0f, 0.0);	glVertex2f(0.0f, 0.0f);	glVertex2f(10.0f, 0.0f);	glVertex2f(10.0f, 10.0f);	glVertex2f(0.0f, 10.0f);	glEnd();//switch back to perspective modeglMatrixMode(GL_PROJECTION);glPopMatrix();glMatrixMode(GL_MODELVIEW);glPopMatrix();

##### Share on other sites
MARS_999    1627
Quote:
 Original post by Code-Ryou're re-loading identity on the model view matrix, and you have an unnecessary gluPrespective call. Do as phantom said, namely:*** Source Snippet Removed ***

No dice. My colored quad doesn't render at all...

##### Share on other sites
jyk    2094
Quote:
Original post by MARS_999
Quote:
 Original post by Code-Ryou're re-loading identity on the model view matrix, and you have an unnecessary gluPrespective call. Do as phantom said, namely:*** Source Snippet Removed ***

No dice. My colored quad doesn't render at all...
Make sure that:

1. The coordinates for your quad are within the bounds you specified in glOrtho()
2. The quad is big enough to see clearly
3. The quad is wound correctly (you might try reversing the winding and see what happens)
4. Texturing is turned off (assuming you're doing a simple quad like above)

##### Share on other sites
MARS_999    1627
Ok I am not sure what is wrong anymore. But with a simple app running Ortho mode I can see my quad. Now when I setup the initial mode as perspective and call the ortho mode afterwards to display this same quad no dice??

void Render(void){RenderText();	SwapBuffers(ghdc);}void RenderText(void){/*    glMatrixMode(GL_PROJECTION);	glPushMatrix();	glLoadIdentity();	glOrtho(0.0, gwidth, gheight, 0.0, -1.0, 10.0);	glMatrixMode(GL_MODELVIEW);	glPushMatrix();		glLoadIdentity();*/	//draw text here	glBegin(GL_QUADS);	glColor3f(1.0f, 0.0f, 0.0);	glVertex2f(0.0, 0.0);	// Bottom Left Of The Texture and Quad	glVertex2f(400.0, 0.0);		// Bottom Right Of The Texture and Quad	glVertex2f(400.0, 400.0);		// Top Right Of The Texture and Quad	glVertex2f(0.0, 400.0);		// Top Left Of The Texture and Quad    glEnd();/*   //switch back to perspective mode	glMatrixMode(GL_PROJECTION);	glPopMatrix();	glMatrixMode(GL_MODELVIEW);	glPopMatrix();*/}

Now with the code above I get a red quad in Ortho mode. When I uncomment the code to go back into Perspective mode no dice. I can render this quad fine if I setup the initial mode as Ortho.

##### Share on other sites
MARS_999    1627
Ok I got it working to display just one quad. Now for some reason my text rendering code isn't working? I can render polygons but no text?

void CFont::BuildFont(void){	HFONT font;										// Windows Font ID	base = glGenLists(256);								// Storage For 256 Characters	font = CreateFont(8,							// Height Of Font						0,								// Width Of Font						0,								// Angle Of Escapement						0,								// Orientation Angle						FW_NORMAL,						// Font Weight						FALSE,							// Italic						FALSE,							// Underline						FALSE,							// Strikeout						ANSI_CHARSET,					// Character Set Identifier						OUT_TT_PRECIS,					// Output Precision						CLIP_DEFAULT_PRECIS,			// Clipping Precision						ANTIALIASED_QUALITY,			// Output Quality						FF_DONTCARE|DEFAULT_PITCH,		// Family And Pitch						"Arial");						// Font Name	SelectObject(hdc, font);							// Selects The Font We Created	wglUseFontOutlines(hdc,								// Select The Current DC						0,								// Starting Character						255,							// Number Of Display Lists To Build						base,							// Starting Display Lists						0.0f,							// Deviation From The True Outlines						0.1f,							// Font Thickness In The Z Direction						WGL_FONT_POLYGONS,				// Use Polygons, Not Lines						gmf);}void CFont::DrawText(const char *text, float x, float y, float z, float red, float green, float blue){	if(text == NULL)		return;	else	{		glColor3f(red, green, blue);		//color of text				glPushMatrix();		glTranslatef(x, y, z);				//text position		glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);		//glScalef(.25f, .25f, .25f);        glPushAttrib(GL_LIST_BIT);			//keep other Display lists info 		glListBase(base);		glCallLists(int(strlen(text)), GL_UNSIGNED_BYTE, text);		glPopAttrib();		glPopMatrix();				glColor3f(1.0f, 1.0f, 1.0f);				glFrontFace(GL_CCW);	}}

##### Share on other sites
anist    100
are you displaying the text AFTER the quad? is depth test disabled? is your color set to one that will make the text appear? is blending disabled?

##### Share on other sites
MARS_999    1627
Quote:
 Original post by anistare you displaying the text AFTER the quad? is depth test disabled? is your color set to one that will make the text appear? is blending disabled?

Thanks for the reply. Yes to all and still no dice... :(

##### Share on other sites
Schmedly    366
Try flipping your vertical coordinates in the Ortho call or specify a different face winding for the font rendering with glFrontFace( GL_CW ). If that font code came from a tutorial, it could be assuming your Ortho context is oriented with it's origin at the top left.

##### Share on other sites
MARS_999    1627
Quote:
 Original post by SchmedlyTry flipping your vertical coordinates in the Ortho call or specify a different face winding for the font rendering with glFrontFace( GL_CW ). If that font code came from a tutorial, it could be assuming your Ortho context is oriented with it's origin at the top left.

Argh I already had the note in my font code about the default winding is CW... So no dice still. Thanks for the help though

##### Share on other sites
MARS_999    1627
Ok if I use gluPerspective I can see the text using the oultline fonts way of rendering. If I move to glOrtho() all I can see is a puny dot at the bottom left of the screen? Any ideas? Thanks

##### Share on other sites
Kalidor    1087
Quote:
 Original post by MARS_999Ok if I use gluPerspective I can see the text using the oultline fonts way of rendering. If I move to glOrtho() all I can see is a puny dot at the bottom left of the screen? Any ideas? Thanks
Quote:
 Original post by jykMake sure that:1. The coordinates for your quad are within the bounds you specified in glOrtho()2. The quad is big enough to see clearly...
That sounds like your problem. Have you checked those two points with the text?

##### Share on other sites
MARS_999    1627
I found the problem or at least a solution...

##### Share on other sites
Kalidor    1087
Quote:
 Original post by MARS_999I found the problem or at least a solution...
Cool...

Mind sharing?

##### Share on other sites
MARS_999    1627
Has to do something with glew and when you call your code. Why? Beats me. Also I need to call
glDisable(GL_CULL_FACE);//then enable after I am done rendering

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