#include
#include
void timer(int value);
void init(void);
void display(void);
void reshape (int w, int h);
void mouse(int button, int state, int x, int y);
void timer(int value);
void idle();
int opcion=0;
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
glShadeModel (GL_FLAT);
}
void display(void)
{
float a,b,c,x,y,ancho,alto;
int i;
a=rand()%10;
a=a/10;
b=rand()%10;
b=b/10;
c=rand()%10;
c=c/10;
glColor3f (a, b, c);
glLoadIdentity ();
gluLookAt (2.0,0.0,6.0,2.0,0.0, 0.0, 0.0, 5, 0.0);
glPushMatrix();
glTranslatef(-0.5,-2.3,0.0);
switch(opcion)
{
case 0:
glBegin(GL_LINE_LOOP);
for (i=0;i<2;i++)
glVertex3f(rand()%6,rand()%6,1);
glEnd();
break;
case 1:
glBegin(GL_LINE_LOOP);
for (i=0;i<3;i++)
glVertex3f(rand()%6,rand()%6,1);
glEnd();
break;
case 2:
glBegin(GL_LINE_LOOP);
x=rand()%6;
y=rand()%6;
ancho=rand()%6;
alto=rand()%6;
glVertex3f(x,y,1);
glVertex3f(ancho,y,1);
glVertex3f(ancho,alto,1);
glVertex3f(x,alto,1);
glEnd();
break;
default:
break;
}
glPopMatrix();
glFlush ();
}
void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON)
{
if(state == GLUT_DOWN)
{
opcion++;
if(opcion==3)
opcion=0;
}
}
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
void idle()
{
int j;
for(j=0;j<30000000;j++){}
display();
}
void timer(int value)
{
int j;
glutTimerFunc(5000,timer,1);
glClear (GL_COLOR_BUFFER_BIT);
for(j=0;j<30000000;j++){}
display();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE GLUT_RGB);
glutInitWindowSize (700, 700);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Reporte");
init ();
glutIdleFunc(idle);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutTimerFunc(5000,timer,1);
glutMainLoop();
return 0;
}
No hay comentarios.:
Publicar un comentario