944,149 Members | Top Members by Rank

Ad:
Nov 7th, 2009
0

How to write text to glut window with the keyboard in c++?

Expand Post »
How can I draw text in a glut window with the keyboard;
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bushimports is offline Offline
5 posts
since Aug 2009
Nov 9th, 2009
0
Re: How to write text to glut window with the keyboard in c++?
You could use glutBitmapCharacter

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);
  }
}
That is provided by lighthouse, Their link

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
}
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,865 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Game Development Forum Timeline: school project
Next Thread in Game Development Forum Timeline: Game-ready model shops





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC