| | |
How to write text to glut window with the keyboard in c++?
![]() |
•
•
Join Date: Aug 2009
Posts: 3
Reputation:
Solved Threads: 0
How can I draw text in a glut window with the keyboard;
I have tried doing cin with
and then in the draw function
the intention here was to get the string from cin and put it in the string variable and then draw it to the screen. I know how to get
input with cin and put it in a variable with a console program, but i don't know how to do it with the glut keyboard. I also know how to draw text to the screen with glut. I have other questions but I will post them in seperate threads. Much thanks, Jody Bush
I have tried doing cin with
void TextBox::Keys(unsigned char key,int x,int y){
switch(key){
case 13://enter key
cin >> String;
DrawString = true;
break;
case 27:
exit(0);
break;
}and then in the draw function
fontx = tx + 3;
fonty = ty + (th+8)/2;
if(DrawString == true){
glColor3f(0.0,0.0,0.0);
Font(GLUT_BITMAP_HELVETICA_12,(char*)String,fontx,fonty);
}the intention here was to get the string from cin and put it in the string variable and then draw it to the screen. I know how to get
input with cin and put it in a variable with a console program, but i don't know how to do it with the glut keyboard. I also know how to draw text to the screen with glut. I have other questions but I will post them in seperate threads. Much thanks, Jody Bush
0
#2 14 Days Ago
You could use glutBitmapCharacter
Combined with function you can make this :
That is provided by lighthouse, Their link
Now all you need is a little bit of logic.
For example :
and :
You can then call this function also in you draw function.
Combined with function you can make this :
void renderBitmapString(
float x,
float y,
float z,
void *font,
char *string) {
char *c;
glRasterPos3f(x, y,z);
for (c=string; *c != '\0'; c++) {
glutBitmapCharacter(font, *c);
}
}Now all you need is a little bit of logic.
For example :
string input = "";
void keyBoard(unsigned char key, int x, int y){
input += key;
void updateString();
}and :
void updateString(){
glutBimapString(0,0,0, GLUT_BITMAP_9_BY_15, input.c_str());
}You can then call this function also in you draw function.
void drawFunc()
{
glClear(someBITSGoesHerE);
glLoadIdentity();
updateString();
//blah blah
}I give up! 1) What word becomes shorter if you add a letter to it? 2) What does this equal : (.5u - .5a)(.5u-.5b)(.5u-.5c) ... 3) What is the 123456789 prime numer?
![]() |
Similar Threads
- Win32 Application Helo (C++)
- How often do you read/write to Text Files as a PHP Developer? (PHP)
- how to write text on image dynamically through drag and drop control in C# (ASP.NET)
- Beginner Q - UI update, different thread, different class. (C#)
- To write a text file in FTP server (ASP)
- Write text on top of Form (C++)
- Write text to an 'Edit Control' - (C++/MFC) (C++)
- Create and write a text file that saved in network folder (ASP.NET)
- write to text file using fprintf() (C)
- Interactive text file (C++)
Other Threads in the Game Development Forum
- Previous Thread: school project
- Next Thread: Game-ready model shops
| Thread Tools | Search this Thread |
3d advertising ai algorithm ban c++ cambridge camera censorship china competition console development engine fov fpx game gamer games gaming gauntanamo government idaho in-gameadvertisement intellectualproperty laracroft live manhunt math mathematics matrix mercenaries microsoft mmorpg modded msn naked news nintendo obama palin physics pirate playstation politics projection ps3 rpg search software sony stephenhawking stocks studio technology terrorism tombraider uk videogame web wii world-of-warcraft xbox xbox-live xbox360






