Jump to content
  • Advertisement


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

Surg AKA Kunark


This topic is 5720 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

Hi, I am new to programing, exspecialy OpenGL programming, I have one book that is useless called C++ for Dummies, and I would like to know, how i can get text, to go to the screen using a simple command, hopefully something like GLcout << ("My text to go on screen", MaybeAColourSetting, SomesizeIhope, X-cordinate, Y-cordinate). I know im askin alot, but im so new to this, and this one thin wasn''t in the NeHe tutorials. LOL, thats what i been learning off of. So, i use the very first lesson in NeHe as my setting up if you need to know what my source looks like. TY

Share this post

Link to post
Share on other sites
NeHe''s tutorials 13, 14 and 15 show you how to dispaly font, although I''m afraid there isn''t any simple OpenGL command it still isn''t very difficult if you follow the tutorials.

Share this post

Link to post
Share on other sites
its harder than u think
there are 2 ways: the slow way, and the fast way
i'll explain the fast way : use polygons for the letters and use a font texture

here is my console code:


struct tFont
char name[64];
CTexture tex;
int height;

tFont fonts[2];
int numFonts = 0;
int curFont = 0;

float textX, textY;
float fontColor[4];

void conSetColor(float r, float g, float b, float a)
fontColor[0] = r;
fontColor[1] = g;
fontColor[2] = b;
fontColor[3] = a;

void conCreateFont(LPSTR strFontName, int height)

char bmpName[255];

FILE *fi = fopen(strFontName, "rt");

fscanf(fi, "%s", fonts[numFonts].name);
fscanf(fi, "%s", bmpName);


fonts[numFonts].height = height;


void conSelectFont(int i)
curFont = i;

void conDrawChar(unsigned char c, int x, int y )

float cPosX, cPosY;

float fontSZ = fonts[curFont].height;
float texSz = fonts[curFont].tex.GetWidth();

float origX = 0;
float origY = 0;
float sizeX = texSz / 16;
float sizeY = texSz / 16;

y = y + (texSz / 16);

cPosX = (c % 16) * (texSz / 16);
cPosY = (c / 16) * (texSz / 16);

CVector2 tl, tr, bl, br;

tl.x = (cPosX + origX) / texSz;
tl.y = (cPosY + origY) / texSz;

tr.x = (cPosX + origX + sizeX) / texSz;
tr.y = (cPosY + origY) / texSz;

br.x = (cPosX + origX + sizeX) / texSz;
br.y = (cPosY + origY + sizeY) / texSz;

bl.x = (cPosX + origX) / texSz;
bl.y = (cPosY + origY + sizeY) / texSz;

textX += fontSZ + FONT_SPACE;

glTexCoord2f(bl.x, bl.y);
glVertex2f(x, y );

glTexCoord2f(br.x, br.y);
glVertex2f(x + fontSZ, y );

glTexCoord2f(tr.x, tr.y);
glVertex2f(x + fontSZ, y - fontSZ);

glTexCoord2f(tl.x, tl.y);
glVertex2f(x, y - fontSZ);


void conTextOut(int x, int y, const char *strString, ...)
char strText[256];
va_list argumentPtr;

if (strString == NULL)

va_start(argumentPtr, strString);

vsprintf(strText, strString, argumentPtr);


textX = x - strlen(strString) * fonts[curFont].height / 2;

glMatrixMode( GL_MODELVIEW );

glMatrixMode( GL_PROJECTION );

gluOrtho2D(0, curConfig.scrWidth, curConfig.scrHeight, 0);


glAlphaFunc(GL_GREATER, 0.0f);

glBindTexture(GL_TEXTURE_2D, fonts[curFont].tex.texnum);

int i = 0;
while (strText[i++] != 0)
conDrawChar(strText[i - 1], textX, y);

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

glMatrixMode( GL_MODELVIEW );


a font file contains the font name and the path to the font image
remeber to flip the font image vertically or change the code (i was 2 lazy to 2 it myself)

[edited by - Ilici on April 18, 2003 2:40:57 PM]

Share this post

Link to post
Share on other sites
Glut has a number of functions that allows you to display text in your OpenGL windows. The fonts aren''t that brilliant though so most people tend to store each letter as a texture and use them.

http://www.gametutorials.com had a tutorial on this subject. Try that.

Share this post

Link to post
Share on other sites
Hi, the newb is back, lol, Ok i got text to work, now say i want to add more lines of text, after the screen is full, how do i reset the screen. So i can add some more. Also i would like to know how i can make like a timer, so that it shows the startup screen for a certain amount of time, then shows the text.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!