Sign in to follow this  
MARS_999

How to got about using these modes?

Recommended Posts

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 this post


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

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// call to glPerspective

glMatrixMode(GL_MODELVIEW);

// render stuff

Share this post


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

thats probably the easiest way todo it.


Thanks Phantom I will give it a go.

Share this post


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


Link to post
Share on other sites
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);
//ADDED
glPushMatrix();
//
glLoadIdentity();
glOrtho(0.0, gWidth, gHeight, 0.0, -1.0, 10.0);
glMatrixMode(GL_MODELVIEW);
//ADDED
glPushMatrix();
//
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);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

Share this post


Link to post
Share on other sites
Quote:
Original post by Code-R
you'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 this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
Quote:
Original post by Code-R
you'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 this post


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


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


Link to post
Share on other sites
Quote:
Original post by anist
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?


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

Share this post


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


Link to post
Share on other sites
Quote:
Original post by Schmedly
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.


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 this post


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


Link to post
Share on other sites
Quote:
Original post by MARS_999
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
Quote:
Original post by jyk
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
...
That sounds like your problem. Have you checked those two points with the text?

Share this post


Link to post
Share on other sites

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