#### Archived

This topic is now archived and is closed to further replies.

# Displaying Text In Special Cases...

## Recommended Posts

OK, I now have my app running the way I want it to, and I can use glTranslate and glRasterpPos to manually print a bitmapped font somewhere, but now I am ready to start working on the chat section of the engine so I can spew the data that my server and client are sending to eachother. How is it I can display characters at a set font-size in the upper-left of the window, like in most odern games? I thought about making textures of the text and then drawing two triangles and mapping the texture onto them to make out sentences, but that''s a waste. I am sure there''s a way to do this. Could somebody please inform e on what I need to do? Thanks. -The Great Sephiroth

#### Share this post

##### Share on other sites
You can use glRasterPos2i in Ortho Mode to create a system like the one you are looking to create - did you want to make a Q3-console style printout? I''d think that it''d just take a little work, like maybe starting a linked list of the strings that your console would print and just appending them etc.

At this point, I''m doing the ''pointless'' texture mapped font thing you mentioned in the second half of your post. I finally broke down and bought an OpenGL book last night, and it certainly seems like there are other, better ways to do this than they way I am doing it.

#### Share this post

##### Share on other sites
Thing is, I use the projection mode since this is a 3D game. Is it possible to use that in projection mode? I would think that rendering an entire scene in projection, switching to ortho, printing all the text, and switching back to projection, would kill a framerate.

-The Great Sephiroth

#### Share this post

##### Share on other sites
I dont think that mode switching would infact kill the frame rate, in fact someone posted a way of doing it on here a while ago which involves pushing and popping of OGL states to it can be switched faster

#### Share this post

##### Share on other sites
So every time I draw a frame, I could do my world/actor drawing in projection, then call a function to print any text still in say a five-line buffer, where it switches to ortho, draws, then flips back to projection and returns. And this wouldn''t kill my framerate?

Final question about this new technique. Once I am in ortho mode, do I have to translate anything, or can I just set the raster position and go from there? Oh, and how would I vary the text size in this mode?

-The Great Sephiroth

#### Share this post

##### Share on other sites
Most modern games with regular "text editing" fonts in chat (EQ et al) probably draw to a bitmap using GDI (or libttf, or whatever) and then upload that as a texture, and then draw that texture on a quad in ortho mode at the end of the frame.

#### Share this post

##### Share on other sites
OK, just one problem with this whole ortho mode. How do i go into and out of it. I''ve never used it before and glMatrixMode(GL_ORTHO) spews an error because GL_ORTHO is undefined. I am used to modelview and projection myself. And earlier when I posted I draw in projection, I wasn''t thinking. I draw in modelview.

-The Great Sephiroth

#### Share this post

##### Share on other sites
	glMatrixMode(GL_PROJECTION);	glPushMatrix();	glLoadIdentity();	glOrtho(left, right, down, up, near, far);		// do your thing in ortho mode		glPopMatrix();	// back to how it was

It doesn't kill your framerate at all. Whenever you see a 3D program that has a 2D interface, this is likely how it was done. That's how OpenGL was designed and is why there is a stack of matrices to play with. glPushMatrix() throws a new matrix on top the current one that you can do whatever you want with. When done, glPopMatrix() returns you to the previous matrix, and it's just like before.

You also may prefer gluOrtho2D, it's a (thin) frontend to glOrtho

[edited by - tortoise on September 3, 2003 1:02:54 AM]

#### Share this post

##### Share on other sites
Thanks, I thought it was a new matrix mode. Now what are near and far in ortho? Clipping ranges??

-The Great Sephiroth

#### Share this post

##### Share on other sites
While I use the ortho way, I found a very interesting way to map your text to screen coordinates without using ortho mode. Here's the source:

glPushAttrib (GL_TRANSFORM_BIT | GL_VIEWPORT_BIT);	glMatrixMode (GL_PROJECTION);	glPushMatrix ();		glLoadIdentity ();		glMatrixMode (GL_MODELVIEW);		glPushMatrix ();			glLoadIdentity ();			glViewport (x_ - 1, y_ - 1, 0, 0);			glRasterPos2f (0.0, 0.0);                glPopMatrix ();		glMatrixMode (GL_PROJECTION);	glPopMatrix ();glPopAttrib ();glPushAttrib (GL_LIST_BIT);	glListBase (listBase - 32);	glCallLists (strlen (output), GL_UNSIGNED_BYTE, output);glPopAttrib ();

Here x_ and y_ are the screen location of the text (aligned to OGL's standard coordinate system with (0,0) at the bottom-left; this can be fixed, see later), listBase is the start of the display lists for the font and output is the text.

You can easily flip this so you're using the top-left of the screen as (0,0) by using
y_ = SCREEN_HEIGHT - y_;
somewhere before that code itself.

I guess it's just a matter of whether it's faster to switch back and forth from ortho to perspective mode or to change the viewport.

I imagine it'd be about equal, so I can't really say... anyone know?

EDIT: slightly mangled source

-Auron

[edited by - Auron on September 3, 2003 1:37:52 AM]

#### Share this post

##### Share on other sites
quote:
Original post by The Great Sephiroth
Now what are near and far in ortho? Clipping ranges??

Yep. Generally they're set between -1.0 and 1.0, which is what gluOrtho2D does.

Grab a copy of the red book, it explains this all really well (with diagrams that clarify things nicely). If you're programming in OpenGL you can't afford to be without this book.

[edited by - tortoise on September 3, 2003 7:22:18 AM]

• ### Forum Statistics

• Total Topics
628401
• Total Posts
2982456

• 9
• 10
• 9
• 19
• 24