Skip to main content
gamedev.net
🔒 Locked

need graphical console

Started by supervlad Sep 18, 2006 at 12:24 PM 9 replies 1.7k views
Original Post
supervlad
supervlad
I'm developing an opengl application. I would like to have a graphical console in the application so that I can see messages as the application runs. Do you guys know where I can get a free console that I can plug into my application? The simpler the better. I checked out Crazy Eddie's Gui System, at www.cegui.org.uk, but it's too much for my needs. thanks for any help.
SirMike
SirMike
Have you considered writing one by yourself? It's pretty simple. Just writing text onto the screen. You can put everything in one or two classes and code it during one evening.
-- SirMike - http://www.sirmike.org
supervlad
supervlad
I'm fairly new to opengl. The idea was to put off writing my own console until a later time so that I can concentrate on other things. I guess I'm gonna have to do it myself. I really need one.

I can already output text. I figure I'll need to use scissor testing. Besides that, not sure what else I'll need.

What would be a good aproach to writing a console? Maybe some tips from you guys that have already made one.

Thanks
Lord_Evil
Lord_Evil
You could use some array or list that collects all the messages and then put them on your screen. For example, use a std::list, add new messages to the tail and remove from the head if you're out of space (lines you want to display).

Note, however, that using bitmap fonts is very slow, it would be faster to use texture mapped fonts but more difficult to implement.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
supervlad
supervlad
So basically: store the message lines in some kind of list, and then output the list to the screen using a scissors to clip where the output will be going. Got it.

I got my font building here code from here:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=24

I guess they're bitmap fonts. I checked out he's texture-mapped fonts tutorial, but it's windows dependent. I'm using linux. That sucks.

thanks

Lord_Evil
Lord_Evil
Well, basically texture mapped fonts work as follows:

- Create a quad for every character you want to display (e.g. in a display list as you did with your bitmap font). The quads vertices are specified in screen coordinates (with z beeing 0 or at your near clip plane) and contain the texture coordinates for ech character.

- Bind the font texture.

- Set the projection matrix to identity so that no projection will be used.

- Set the modelview matrix to identiy to eliminate camera position

- Render each character by using the display list and moving the position with glTranslatef(...)

Make shure you have blending enabled. If you can't load texures with alpha channels, use a key color to set the alpha when loading. For example, using purple as key color, when loading the texture use a 4 component color format like GL_RGBA and set the alpha component to 0 for each purple pixel.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
supervlad
supervlad
I don't know enough to follow your mini-tutorial, yet. But I'm sure it will come in handy when I finally know enough to implement it.
roel
roel
Use glut for fonts.
supervlad
supervlad
I'm already using glut. Nice!
I didn't know glut did fonts.
roel
roel
Now you do! good luck! ;)

I use something like this:

void drawText(char* text, float x, float y){	//... do magic matrix stuff here	//go!	glRasterPos3f(x,y,0);	for(;*text!=0;text++)		glutBitmapCharacter(GLUT_BITMAP_8_BY_13,*text);	//... restore magic matrix stuff here}
Lord_Evil
Lord_Evil
Well that's bitmap characters again. You should consider using texture mapped fonts once you're more familiar with OpenGL.

Its really simple. Creating a set of quads is as simple as:

glNewList(chars[character],GL_COMPILE_AND_EXECUTE);	glBegin(GL_QUADS);				//topleft	glTexCoord2f(tex[character].left,tex[character].top);	glVertex3f(0.0f,0.0f,0.0f);	//bottom left	glTexCoord2f(tex[character].left,tex[character].bottom);	glVertex3f(0.0f,-m_size.y,0.0f);	//bottom right	glTexCoord2f(tex[character].right,tex[character].bottom);	glVertex3f(m_size.x,-m_size.y,0.0f);				//top right	glTexCoord2f(tex[character].right,tex[character].top);	glVertex3f(m_size.x,0.0f,0.0f);	glEnd();glEndList();

Note: m_size is a 2D vector specifying the size of each character. tex is an array of Rectangles specifying the float texture coordinates of each character in the texture.


Now create a texture which contains the characters. I'd suggest a 8-bit Bitmap since those are read easily an can be used as alpha map.

Rendering is also simple:

Enable blending.
Bind your font texture.
Set your text color. (glColor3f(...))
Render the text by calling the display list for each character and move the position of the next character by m_size.x (width of a character).

I'll send you some code once I have a simple example.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.