Archived

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

Text Questions

This topic is 5781 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 have a few questions about text in Open GL. Currently I am using the glPrint function presented in the NeHe lessons (number 13 or 14 I think) but printing even the smallest amount of text to the screen cuts the fps in at least half. Is there a faster way to print text? Also, is there any way for the user to enter text kind of like a "cin" statement with iostream? I figure I could write something to capture the key presses of the user and use that as a "cin", but Open GL runs so fast that if they held the key down for longer than a split second it would register like fifty keys. Thanks.

Share this post


Link to post
Share on other sites
Easy: don''t use the method in tutorial 13. I''ve had to tell people this at least a dozen times. I think the method in tutorial 17 is the decent one (too lazy to check ).

OpenGL doesn''t have anything to do with input. What are you using for input? Answering that makes answering your question easier.

Share this post


Link to post
Share on other sites
Ok, thanks for the first part.

What I meant about input is for a way to do something like this in open gl:

cout << "Enter name ... " << endl;
cin >> name;

Anything along those lines? Probably not ...

Thanks again

Share this post


Link to post
Share on other sites
The code in Lesson 17 doesn't allow printing variables to the screen does it? If it doesn't then is there another way that is fast and allows variables to be printed?

Edited by - jag_oes on February 19, 2002 9:04:31 PM

Share this post


Link to post
Share on other sites
Take a look at my code printing code. I created a rather simple R_Printf() function that works just like printf().

http://www.lowping.com/demosh/temp/r_text.c
http://www.lowping.com/demosh/temp/r_text.h

LMKWYT

Share this post


Link to post
Share on other sites
Okay, I''ll address your questions one at a time.

Displaying Text:
I would suggest writing your own function to display text using textured quads, one for each character. A single texture storing the entire character set is rather efficient, and, considering the minimal number of characters you''ll need to display at any one time, this method does not present a noticable speed hit.

Getting Strings:
I''m assuming what you want is to get a string from the user while the OpenGL application is running. Quite simply, you want the routine to record the event only if there has been a pause between each key stroke. The method I would suggest would be the following:

// assume keyqueue and keyqueueindex form a simple queue
// containing the keystrokes.
void GetKeyPresses(char *keyqueue, int keyqueueindex)
{
static int RepeatKeyFlag = 0;
int i = 0;
int nokeys = 1;

// decide if any keys are being pressed
for (; i < 256; i++)
{
if (GetAsyncKeyState(i))
{
nokeys = 0;
if (!RepeatKeyFlag)
{
RepeatKeyFlag = 1;
keyqueue[keyqueueindex++]=i;
return;
}
}
}
RepeatKeyFlag = !nokeys;
}

I assume you can read C code . Good luck.

Share this post


Link to post
Share on other sites