Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

How to got about using these modes?

This topic is 4481 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 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
Advertisement
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
- 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 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!