Wednesday, 29 April 2015

OpenGL program to display entered key


#include<GL/glut.h>
int flag=0;

void print(int x,int y,int z,char *string){
glRasterPos2f(x,y);
int i;
 int len=(int)strlen(string);

    for(i=0; i<len;i++){
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,string[i]);
        //in built func to print the text bit vz
    }
}

void display(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glPushMatrix();
switch(flag){
case 1: {print(0,0,0,"A"); break;}
case 2: {print(0,0,0,"B"); break;}
case 3: {print(0,0,0,"C");break;}
case 4: {print(0,0,0,"D");break;}
case 5: {print(0,0,0,"E");break;}
case 6: {print(0,0,0,"F");break;}
case 7: {print(0,0,0,"G");break;}
case 8: {print(0,0,0,"H");break;}
case 9: {print(0,0,0,"I");break;}
case 10: {print(0,0,0,"J");break;}
case 11: {print(0,0,0,"K");break;}
case 12: {print(0,0,0,"L");break;}
case 13: {print(0,0,0,"M");break;}
case 14: {print(0,0,0,"N");break;}
case 15: {print(0,0,0,"O");break;}
case 16: {print(0,0,0,"P");break;}
case 17: {print(0,0,0,"Q");break;}
case 19: {print(0,0,0,"S");break;}
case 20: {print(0,0,0,"T");break;}
case 21: {print(0,0,0,"U");break;}
case 22: {print(0,0,0,"V");break;}
case 23: {print(0,0,0,"W");break;}
case 24: {print(0,0,0,"X");break;}
case 25: {print(0,0,0,"Y");break;}
case 26: {print(0,0,0,"Z");break;}
}
glPopMatrix();
glFlush();
}

void init(){
glClearColor(1,1,1,1);
glColor3f(1,0,0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1,1,-1,1);
}

void keyboard(unsigned char key,int x,int y){
switch(key){
case 'a': {flag=1; glutPostRedisplay(); break;}
case 'b': {flag=2; glutPostRedisplay();break;}
case 'c': {flag=3; glutPostRedisplay();break;}
case 'd': {flag=4; glutPostRedisplay();break;}
case 'e': {flag=5; glutPostRedisplay();break;}
case 'f': {flag=6; glutPostRedisplay();break;}
case 'g': {flag=7; glutPostRedisplay();break;}
case 'h': {flag=8; glutPostRedisplay();break;}
case 'i': {flag=9; glutPostRedisplay();break;}
case 'j': {flag=10; glutPostRedisplay();break;}
case 'k': {flag=11;glutPostRedisplay(); break;}
case 'l': {flag=12;glutPostRedisplay(); break;}
case 'm': {flag=13; glutPostRedisplay();break;}
case 'n': {flag=14; glutPostRedisplay();break;}
case 'o': {flag=15;glutPostRedisplay(); break;}
case 'p': {flag=16; glutPostRedisplay();break;}
case 'q': {flag=17;glutPostRedisplay(); break;}
case 'r': {flag=18;glutPostRedisplay(); break;}
case 's': {flag=19;glutPostRedisplay(); break;}
case 't': {flag=20;glutPostRedisplay(); break;}
case 'u': {flag=21;glutPostRedisplay(); break;}
case 'v': {flag=22;glutPostRedisplay(); break;}
case 'w': {flag=23;glutPostRedisplay(); break;}
case 'x': {flag=24;glutPostRedisplay(); break;}
case 'y': {flag=25;glutPostRedisplay(); break;}
case 'z': {flag=26;glutPostRedisplay(); break;}
case '1': {exit(0);}
}

}

void main(int argc,char** argv){

glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow(":-(");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
init();
glutMainLoop();

}

No comments:

Post a Comment

Total Pageviews