Help with translating initials??

Hello
Just started a module in OpenGL programming, learning on few stuff, can ne one help me with this small program, i’ve created the initials of my name but when i press ‘t’ i want the letters to translate.
Can neone help me on how to do this??

   
#include "glut.h"

void init (void)
{
	glClearColor (1.0,1.0,1.0,0.0);

		glMatrixMode (GL_PROJECTION);
		gluOrtho2D( 0.0,200.0,0.0,150.0);
}

void lineSegment(void)
{
	glClear(GL_COLOR_BUFFER_BIT);

	glColor3f(1.0,0.0,0.0);

	glBegin(GL_LINES);
		glVertex2i(10,15);
		glVertex2i(10,100);

		glVertex2i(10,100);
		glVertex2i(45,15);

		glVertex2i(45,100);
		glVertex2i(45,15);

		glVertex2i(60,15);
		glVertex2i(60,100);
		
		glVertex2i(80,50);
		glVertex2i(60,100);

		glVertex2i(80,50);
		glVertex2i(100,100);

		glVertex2i(100,100);
		glVertex2i(100,15);

//glColor3f(0.0,0.0,0.0);
//		for(int k=0; k<10;k++)
//		{
// glRasterPos2i(100,100 - k*10);
		
//		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'D');
//		}

		
	glEnd();

		glFlush();
}

void main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE| GLUT_RGB);
	glutInitWindowPosition(50,100);
	glutInitWindowSize(400,300);
	glutCreateWindow("My Initials N.M.");

	init();
	glutDisplayFunc(lineSegment);
	glutMainLoop();
}
 

When the users press the key you should update a variable somewhere like:

key_callback()
{
  if( key == whatever)
  {
     position += some_value;
     postRedisplay();
  }
}

This will update the variable and force glut to redraw the contents of the window.

In your display function you can then translate (before you start to render your initials) using the updated variable and everything will move, just make sure you have switched to modelview matrix mode and then you can use glTranslate to do the job, if you need more information about transformations there are lots of tutorials out there.

Mikael

I would think you would need to add the glutKeyboardFunc() to your main() before you call glutMainLoop() so your program knows that you are accepting keyboard interrupts. Then in your keyboard function you would need to check that the character passed would be the letter ‘t’. So something like this would be desirable…

void keyboard( unsigned char key, int x, int y )
{
   if( key == 't' )
   {
      // Do something
   }
}

 // Inside main()
glutDisplayFunc(lineSegment);
glutKeyboardFunc( keyboard );
glutMainLoop();

This is how I have handled keyboard interrupts in the past. I hope this helps you.