Codigo Utilizado
#include
"stdafx.h"
#include
<GL/glut.h>
#include
<iostream>
int const
ANCHO_VENTANA=600;
int const
ALTO_VENTANA=600;
float
ver1[]={0,0,0};
float
ver2[]={0,0,6};
float
ver3[]={6,0,6};
float
ver4[]={6,0,0};
float
ver5[]={3,4,3};
void
reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5, 11, -5, 8, 11, -5);
glMatrixMode(GL_MODELVIEW);
}
void
display()
{
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glLoadIdentity();
glBegin(GL_TRIANGLES);
//cara derecha
glColor3f(1,0,1);//rojo
y azul
glVertex3fv(ver3);
glVertex3fv(ver4);
glVertex3fv(ver5);
//cara trasera
glColor3f(0,1,0);//verde
glVertex3fv(ver1);
glVertex3fv(ver4);
glVertex3fv(ver5);
//cara
frontal
glColor3f(1,1,0);//rojo
verde
glVertex3fv(ver2);
glVertex3fv(ver3);
glVertex3fv(ver5);
//cara izquierda
glColor3f(1,1,0);//rojo
y verde
glVertex3fv(ver1);
glVertex3fv(ver2);
glVertex3fv(ver5);
glEnd();
//cara base
glBegin(GL_QUADS);
glColor3f(0,1,1);
glVertex3fv(ver1);
glVertex3fv(ver2);
glVertex3fv(ver3);
glVertex3fv(ver4);
glEnd();
glFlush();
}
void myinit()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glClearColor(1.0,
1.0, 1.0, 1.0);
}
int
main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE
| GLUT_RGB| GLUT_DEPTH);
glutInitWindowPosition(50, 50);
glutInitWindowSize(ANCHO_VENTANA,
ALTO_VENTANA);
glutCreateWindow("TRIANGULO");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
myinit();
glutMainLoop();
return
0;
}
No hay comentarios:
Publicar un comentario