-Dibuje en pantalla su número de cuenta.
-Rotelo 45º al apretar la barra espaciadora
-Escale en un factor de 0.5 cuando apriete el boton izquierdo del mouse.
-Traslade sobre (0.1,0.1,0) al apretar el botón derecho del mouse.
-Restaure todo a condiciones iniciales al apretar "R" o "r".
#include "GL/glut.h"
#include "string.h"
char etiqueta[80];
static int ang=180,ang2=180;
static float scalx=0.2,scaly=0.2;
static int transx=250, transy=250;
void reshape(int w, int h){
if (!h)
return;
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, 0, h);
glScalef(1, -1, 1);
glTranslatef(0, -h, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Dibuja (char *cadena)
{
unsigned int Nletras;
for (Nletras=0; Nletras
}
void display(void)
{
char *nombre="301212735";
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode( GL_MODELVIEW_MATRIX );
glLoadIdentity();
glColor3f(1.0, 1.0, 0.0);
glTranslatef(200,200,0);
glScalef(scalx,scaly,0);
glRotatef(ang,0,0,0);
glRotatef(ang,0,0,1);
glRotatef(180,1,0,0);
sprintf(etiqueta,"%s", nombre);
Dibuja(etiqueta);
glFlush();
}
void keyboard (unsigned char key, int x, int y){
switch (key){
case ' ':
ang=ang-45;
printf("%d\n",ang);
glutPostRedisplay();
break;
case 'r':
ang=180;
ang2=180;
transx=250;
transy=250;
scalx=0.5;
scaly=0.5;
glutPostRedisplay();
break;
case 'R':
ang=180;
ang2=180;
transx=250;
transy=250;
scalx=0.5;
scaly=0.5;
glutPostRedisplay();
break;
}}
void mouse(int button,int state,int x,int y){
if(state == GLUT_DOWN)
{
switch(button){
case GLUT_LEFT_BUTTON:
scalx=scalx/2;
scaly=scaly/2;
break;
case GLUT_RIGHT_BUTTON:
transx=transx+20;
transy=transy+20;
break;
}
}
glutPostRedisplay();
}
void init(void){
glClearColor(0.4,0.2,0.8,1.0);
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(550,300);
glutInitWindowPosition(400, 100);
glutCreateWindow("Número de cuenta");
glutDisplayFunc(display);
init();
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
No hay comentarios:
Publicar un comentario