CODIGO openGL(CPU lineas)
#include <GL/glut.h>
GLfloat tx= 1.0f;
GLfloat ty = 1.0f;
GLfloat ax = 0.0f;
GLfloat ay = 0.0f;
GLfloat escala = 1.0f;
void reshape(int width, int height){
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-15,15,-15,15,-15,15);
glMatrixMode(GL_MODELVIEW);
}
void DibujaCPU(void)
{
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_LINE_LOOP);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (5.0, 0.0, 0.0);
glVertex3f (5.0, 9.0, 0.0);
glVertex3f (0.0, 9.0, 0.0);
glEnd();
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_LINE_LOOP);
glVertex3f (5.0, 0.0, 3.0);
glVertex3f (5.0, 9.0, 3.0);
glVertex3f (0.0, 9.0, 3.0);
glVertex3f (0.0, 0.0, 3.0);
glEnd();
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_LINE_LOOP);
glVertex3f (3.0, 5.0, 0.0);
glVertex3f (4.0, 5.0, 0.0);
glVertex3f (4.0, 6.0, 0.0);
glVertex3f (3.0, 6.0, 0.0);
glEnd();
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_LINE_LOOP);
glVertex3f (1.0, 7.0, 0.0);
glVertex3f (4.0, 7.0, 0.0);
glVertex3f (4.0, 8.0, 0.0);
glVertex3f (1.0, 8.0, 0.0);
glEnd();
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_LINE_LOOP);
glVertex3f (0.0, 9.0, 0.0);
glVertex3f (5.0, 9.0, 0.0);
glVertex3f (5.0, 9.0, 3.0);
glVertex3f (0.0, 9.0, 3.0);
glEnd();
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_LINE_LOOP);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (5.0, 0.0, 0.0);
glVertex3f (5.0, 0.0, 3.0);
glVertex3f (0.0, 0.0, 3.0);
glEnd();
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_LINE_LOOP);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (0.0, 9.0, 0.0);
glVertex3f (0.0, 9.0, 3.0);
glVertex3f (0.0, 0.0, 3.0);
glEnd();
}
void display(){
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(tx,ty,0.0f);
glScalef(escala, escala, escala);
glRotatef(ax, 1.0f, 0.0f, 0.0f);
glRotatef(ay, 0.0f, 1.0f, 0.0f);
DibujaCPU();
glFlush();
glutSwapBuffers();
ax+=0.1f;
ay+=0.1f;
}
void init(){
glClearColor(0,0,0,0);
glEnable(GL_DEPTH_TEST);
}
void idle()
{
display();
}
void Teclado(unsigned char key, int x, int y){
switch (key){
case 'a'://presionar tecla a
if( ty<10.0 ){ty = ty + 1.0;}//se mueve en y positivo(arriba)
if(ty>0.1 && ty<4){escala = ty;}//y aumenta
break;
case 'b'://presionar tecla b
if( ty>-10.0 ){ty = ty - 1.0;}//se mueve en y negatibo(abajo)
if(ty>0.1 && ty<4){escala = ty;}//y disminuye
break;
case 'd'://presionar tecla d
if( tx<10.0 ){tx = tx + 1.0;}//se mueve en x positivo(Derecha)
break;
case 'i'://presionar tecla i
if( tx>-10.0 ){tx = tx - 1.0;}//se mueve en x negativo(Izquierda)
break;
}
switch (key) {
case 27:
exit(0);
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowPosition(400,200);
glutInitWindowSize(800,500);
glutCreateWindow("Ruben De La Cruz Venegas");
init();glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutKeyboardFunc(Teclado);
glutMainLoop();
return 0;}
CODIGO openGL(CPU solido)
#include <GL/glut.h>
GLfloat tx= 1.0f;
GLfloat ty = 1.0f;
GLfloat ax = 0.0f;
GLfloat ay = 0.0f;
GLfloat escala = 1.0f;
void reshape(int width, int height){
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-15,15,-15,15,-15,15);
glMatrixMode(GL_MODELVIEW);
}
void DibujaCPU(void)
{
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_POLYGON);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (5.0, 0.0, 0.0);
glVertex3f (5.0, 9.0, 0.0);
glVertex3f (0.0, 9.0, 0.0);
glEnd();
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_POLYGON);
glVertex3f (5.0, 0.0, 3.0);
glVertex3f (5.0, 9.0, 3.0);
glVertex3f (0.0, 9.0, 3.0);
glVertex3f (0.0, 0.0, 3.0);
glEnd();
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_POLYGON);
glVertex3f (3.0, 5.0, 0.0);
glVertex3f (4.0, 5.0, 0.0);
glVertex3f (4.0, 6.0, 0.0);
glVertex3f (3.0, 6.0, 0.0);
glEnd();
glColor3f (0.0, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex3f (1.0, 7.0, 0.0);
glVertex3f (4.0, 7.0, 0.0);
glVertex3f (4.0, 8.0, 0.0);
glVertex3f (1.0, 8.0, 0.0);
glEnd();
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_POLYGON);
glVertex3f (0.0, 9.0, 0.0);
glVertex3f (5.0, 9.0, 0.0);
glVertex3f (5.0, 9.0, 3.0);
glVertex3f (0.0, 9.0, 3.0);
glEnd();
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_POLYGON);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (5.0, 0.0, 0.0);
glVertex3f (5.0, 0.0, 3.0);
glVertex3f (0.0, 0.0, 3.0);
glEnd();
glColor3f (0.25, 0.25, 0.25);
glBegin(GL_POLYGON);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (0.0, 9.0, 0.0);
glVertex3f (0.0, 9.0, 3.0);
glVertex3f (0.0, 0.0, 3.0);
glEnd();
}
void display(){
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(tx,ty,0.0f);
glScalef(escala, escala, escala);
glRotatef(ax, 1.0f, 0.0f, 0.0f);
glRotatef(ay, 0.0f, 1.0f, 0.0f);
DibujaCPU();
glFlush();
glutSwapBuffers();
ax+=0.1f;
ay+=0.1f;
}
void init(){
glClearColor(0,0,0,0);
glEnable(GL_DEPTH_TEST);
}
void idle()
{
display();
}
void Teclado(unsigned char key, int x, int y){
switch (key){
case 'a'://presionar tecla a
if( ty<10.0 ){ty = ty + 1.0;}//se mueve en y positivo(arriba)
if(ty>0.1 && ty<4){escala = ty;}//y aumenta
break;
case 'b'://presionar tecla b
if( ty>-10.0 ){ty = ty - 1.0;}//se mueve en y negatibo(abajo)
if(ty>0.1 && ty<4){escala = ty;}//y disminuye
break;
case 'd'://presionar tecla d
if( tx<10.0 ){tx = tx + 1.0;}//se mueve en x positivo(Derecha)
break;
case 'i'://presionar tecla i
if( tx>-10.0 ){tx = tx - 1.0;}//se mueve en x negativo(Izquierda)
break;
}
switch (key) {
case 27:
exit(0);
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowPosition(400,200);
glutInitWindowSize(800,500);
glutCreateWindow("Ruben De La Cruz Venegas");
init();glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutKeyboardFunc(Teclado);
glutMainLoop();
return 0;}
No hay comentarios.:
Publicar un comentario