Trabajo opengl
Upcoming SlideShare
Loading in...5
×
 

Trabajo opengl

on

  • 4,350 views

 

Statistics

Views

Total Views
4,350
Views on SlideShare
4,350
Embed Views
0

Actions

Likes
0
Downloads
209
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Trabajo opengl Trabajo opengl Document Transcript

  • Tablero de ajedrezCon puntos se creara un tablero de ajedrez. Recordar que eltablero consta de de 8 cuadros por ocho cuadros.Código:#include <GL/glut.h>#include <GL/gl.h>#include <GL/glu.h>void inicializa(void){glClearColor(0.0,1.0,1.0,0.0); //color de fondoglMatrixMode(GL_PROJECTION); //Modo de proyeccionglLoadIdentity(); //Establece los parametros de proyecciongluOrtho2D(0.0, 1000.0, 0.0, 1000.0); //vista ortogonal}void dibuja(void) //funcion dibuja{glClear(GL_COLOR_BUFFER_BIT); //borra pantallaglColor3f(1.0 , 1.0 , 1.0);glPointSize(50);glBegin(GL_POINTS);glVertex2i(100,100);glVertex2i(300,100);glVertex2i(500,100);glVertex2i(700,100);glVertex2i(200,200);glVertex2i(400,200);
  • glVertex2i(600,200);glVertex2i(800,200);glVertex2i(100,300);glVertex2i(300,300);glVertex2i(500,300);glVertex2i(700,300);glVertex2i(200,400);glVertex2i(400,400);glVertex2i(600,400);glVertex2i(800,400);glVertex2i(100,500);glVertex2i(300,500);glVertex2i(500,500);glVertex2i(700,500);glVertex2i(200,600);glVertex2i(400,600);glVertex2i(600,600);glVertex2i(800,600);glVertex2i(100,700);glVertex2i(300,700);glVertex2i(500,700);glVertex2i(700,700);glVertex2i(200,800);glVertex2i(400,800);glVertex2i(600,800);glVertex2i(800,800);glColor3f(0.0 , 0.0 , 0.0);glColor3f(0.0 , 0.0 , 0.0);
  • glPointSize(50);glVertex2i(200,100);glVertex2i(400,100);glVertex2i(600,100);glVertex2i(800,100);glVertex2i(100,200);glVertex2i(300,200);glVertex2i(500,200);glVertex2i(700,200);glVertex2i(200,300);glVertex2i(400,300);glVertex2i(600,300);glVertex2i(800,300);glVertex2i(100,400);glVertex2i(300,400);glVertex2i(500,400);glVertex2i(700,400);glVertex2i(200,500);glVertex2i(400,500);glVertex2i(600,500);glVertex2i(800,500);glVertex2i(100,600);glVertex2i(300,600);glVertex2i(500,600);glVertex2i(700,600);glVertex2i(200,700);glVertex2i(400,700);glVertex2i(600,700);glVertex2i(800,700);
  • glVertex2i(100,800);glVertex2i(300,800);glVertex2i(500,800);glVertex2i(700,800);glEnd();glFlush(); //forza dibujo}int main (int argc, char** argv) //metodo main{glutInit(&argc, argv); //incializa GLUTglutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); //establece el modo de visualizaciónglutInitWindowSize(500,500); //tamaño de la ventanaglutInitWindowPosition(0,0); //posicion inicial de la ventanaglutCreateWindow("tablero"); //nombre de la ventanainicializa();glutDisplayFunc(dibuja); //Envia los graficos a la ventana de visualizaciónglutMainLoop(); //muestra todo y esperareturn 0; //retorna un valor de cero}
  • EstrellaCon solo utilizar líneas, se realizara una estrella con 5 lineas,cruzadas.Código://mi primer ventana#include <GL/glut.h>#include <GL/gl.h>#include <GL/glu.h>void inicializa(void){glClearColor(0.0,0.0,0.0,0.0); //color de fondoglMatrixMode(GL_PROJECTION); //Modo de proyeccionglLoadIdentity(); //Establece los parametros de proyecciongluOrtho2D(0.0, 1000.0, 0.0, 1000.0); //vista ortogonal}void dibuja(void) //funcion dibuja{glClear(GL_COLOR_BUFFER_BIT); //borra pantallaglLineWidth(2);glBegin(GL_LINES);glVertex2i(150,150);glVertex2i(250,350);glVertex2i(250,350);glVertex2i(350,150);
  • glVertex2i(350,150);glVertex2i(100,250);glVertex2i(100,250);glVertex2i(400,300);glVertex2i(400,300);glVertex2i(150,150);glEnd();glFlush(); //forza dibujo}int main (int argc, char** argv) //metodo main{glutInit(&argc, argv); //incializa GLUTglutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); //establece el modo de visualizaciónglutInitWindowSize(500,500); //tamaño de la ventanaglutInitWindowPosition(0,0); //posicion inicial de la ventanaglutCreateWindow("mi primera ventana"); //nombre de la ventanainicializa();glutDisplayFunc(dibuja); //Envia los graficos a la ventana de visualizaciónglutMainLoop(); //muestra todo y esperareturn 0; //retorna un valor de cero}
  • Cubo con líneasDe igual manera que otras prácticas realizadas, su utilizaranlíneas, para crear un cubo.Código:#include <GL/glut.h>#include <GL/gl.h>#include <GL/glu.h>void inicializa(void){glClearColor(0.0,1.0,1.0,0.0); //color de fondoglMatrixMode(GL_PROJECTION); //Modo de proyeccionglLoadIdentity(); //Establece los parametros de proyecciongluOrtho2D(0.0, 1000.0, 0.0, 1000.0); //vista ortogonal}void dibuja(void) //funcion dibuja{glClear(GL_COLOR_BUFFER_BIT); //borra pantallaglLineWidth(2);glBegin(GL_LINES);//enfrenteglVertex2i(50,50);glVertex2i(50,300);glVertex2i(50,300);glVertex2i(300,300);glVertex2i(300,300);glVertex2i(300,50);
  • glVertex2i(300,50);glVertex2i(50,50);//atrasglVertex2i(150,150);glVertex2i(150,400);glVertex2i(150,400);glVertex2i(400,400);glVertex2i(400,400);glVertex2i(400,150);glVertex2i(400,150);glVertex2i(150,150);//linea izquierdaglVertex2i(50,300);glVertex2i(150,400);//linea derechaglVertex2i(300,300);glVertex2i(400,400);//linea izquierda abajoglVertex2i(50,50);glVertex2i(150,150);//linea derecha abajoglVertex2i(300,50);glVertex2i(400,150);glEnd();glFlush(); //forza dibujo}
  • int main (int argc, char** argv) //metodo main{glutInit(&argc, argv); //incializa GLUTglutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); //establece el modo de visualizaciónglutInitWindowSize(500,500); //tamaño de la ventanaglutInitWindowPosition(0,0); //posicion inicial de la ventanaglutCreateWindow("mi primera ventana"); //nombre de la ventanainicializa();glutDisplayFunc(dibuja); //Envia los graficos a la ventana de visualizaciónglutMainLoop(); //muestra todo y esperareturn 0; //retorna un valor de cero}
  • Cubo delineado.En esta práctica se utilizara (GL_QUADS). Se crearan las caras delcuadro y se delineara con ayuda de los conocimientos de lapráctica anterior.Código:#include <GL/glut.h>#include <GL/gl.h>#include <GL/glu.h>void inicializa(void){glClearColor(0.0,1.0,1.0,0.0); //color de fondoglMatrixMode(GL_PROJECTION); //Modo de proyeccionglLoadIdentity(); //Establece los parametros de proyecciongluOrtho2D(0.0, 1000.0, 0.0, 1000.0); //vista ortogonal}void dibuja(void) //funcion dibuja{glClear(GL_COLOR_BUFFER_BIT); //borra pantallaglColor3f(1.0 , 0.0 , 0.0);glPointSize(50);glBegin(GL_QUADS);//ATRASglColor3f(0.0 , 0.9 , 0.0);glVertex2d(100,150);glVertex2d(300,100);glVertex2d(300,350);
  • glVertex2d(100,350);//ABAJOglColor3f(0.0 , 0.0 , 0.0);glVertex2d(200,100);glVertex2d(400,100);glVertex2d(300,150);glVertex2d(100,150);//izquierdoglColor3f(0.0 , 0.0 , 0.0);glVertex2d(100,150);glVertex2d(200,100);glVertex2d(200,300);glVertex2d(100,350);//derechoglColor3f(1.1 , 1.1 , 1.1);glVertex2d(300,150);glVertex2d(400,100);glVertex2d(400,300);glVertex2d(300,350);//arribaglColor3f(1.2 , 0.0 , 0.0);glVertex2d(200,300);glVertex2d(400,300);glVertex2d(300,350);
  • glVertex2d(100,350);//enfrenteglColor3f(1.5 , 1.5 , 0.0);glVertex2d(200,100);glVertex2d(400,100);glVertex2d(400,300);glVertex2d(200,300);glEnd();glColor3f(0.0 , 0.0 , 0.0);glBegin(GL_LINES);glLineWidth(3);glVertex2i(100,150);glVertex2i(200,100);glVertex2i(200,300);glVertex2i(100,350);glVertex2i(200,100);glVertex2i(400,100);glVertex2i(400,300);glVertex2i(200,300);glEnd();glColor3f(0.0 , 0.0 , 0.0);glBegin(GL_LINES);glLineWidth(3);glVertex2i(200,300);glVertex2i(400,300);glVertex2i(300,350);glVertex2i(100,350);
  • glEnd();//loscuadrosglFlush(); //forza dibujo}int main (int argc, char** argv) //metodo main{glutInit(&argc, argv); //incializa GLUTglutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); //establece el modo de visualizaciónglutInitWindowSize(500,500); //tamaño de la ventanaglutInitWindowPosition(0,0); //posicion inicial de la ventanaglutCreateWindow("mi primera ventana"); //nombre de la ventanainicializa();glutDisplayFunc(dibuja); //Envia los graficos a la ventana de visualizaciónglutMainLoop(); //muestra todo y esperareturn 0; //retorna un valor de cero}
  • Muñeco con triángulosEn esta práctica, se ocuparan los triángulos y los polígonos.Triángulos para crear el cuerpo, polígonos para crear la copa.Código:#include <GL/glut.h>#include <GL/gl.h>#include <GL/glu.h>void inicializa(void){glClearColor(0.0,1.0,1.0,0.0); //color de fondoglMatrixMode(GL_PROJECTION); //Modo de proyeccionglLoadIdentity(); //Establece los parametros de proyecciongluOrtho2D(0.0, 2000.0, 0.0, 2000.0); //vista ortogonal}void dibuja(void) //funcion dibuja{glClear(GL_COLOR_BUFFER_BIT); //borra pantallaglBegin(GL_TRIANGLES);glColor3f(0.0 , 0.0 , 0.0);//gorroglVertex2f(440,760);glVertex2f(600,880);glVertex2f(760,760);glEnd();//cabeza
  • glColor3f(1.0 , 0.0 , 0.0);glBegin(GL_TRIANGLES);glVertex2f(520,760);glVertex2f(600,640);glVertex2f(680,760);glEnd();//corbataglColor3f(0.0 , 0.0 ,0.0);glBegin(GL_TRIANGLES);glVertex2f(560,640);glVertex2f(600,600);glVertex2f(640,640);glEnd();//cuerpazoglBegin(GL_QUADS);glVertex2f(480,640);glVertex2f(480,360);glVertex2f(720,360);glVertex2f(720,640);glEnd();//brazo izquierdpglColor3f(1.0 , 1.1 , 0.0);glBegin(GL_TRIANGLES);glVertex2f(480,640);glVertex2f(360,360);glVertex2f(280,440);glEnd();//brazo derechoglColor3f(1.0 , 1.1 , 0.0);
  • glBegin(GL_TRIANGLES);glVertex2f(720,640);glVertex2f(920,400);glVertex2f(840,360);glEnd();//mano izquierdaglColor3f(1.0 , 1.1 , 0.0);glBegin(GL_TRIANGLES);glVertex2f(240,520);glVertex2f(280,440);glVertex2f(240,400);glEnd();//mano derechaglColor3f(1.0 , 1.1 , 0.0);glBegin(GL_TRIANGLES);glVertex2f(960,520);glVertex2f(960,400);glVertex2f(920,400);//pata derechaglColor3f(0.0,0.0,0.0);glBegin(GL_TRIANGLES);glVertex2f(640,360);glVertex2f(800,280);glVertex2f(640,280);glEnd();//abajo pataglColor3f(1.0 , 1.1 , 0.0);glBegin(GL_TRIANGLES);glVertex2f(800,120);
  • glVertex2f(720,200);glVertex2f(800,280);glEnd();//pata abjao abajoglColor3f(1.0 , 1.1 , 0.0);glBegin(GL_TRIANGLES);glVertex2f(800,120);glVertex2f(880,160);glVertex2f(960,120);glEnd();//pata abajo izquierdaglColor3f(1.0 , 1.1 , 0.0);glBegin(GL_TRIANGLES);glVertex2f(400,40);glVertex2f(480,80);glVertex2f(560,40);glEnd();glColor3f(1.0 , 00, 0.0);glBegin(GL_POLYGON);glVertex2f(840,120);glVertex2f(880,120);glVertex2f(920,80);glVertex2f(920,40);glVertex2f(880,0);glVertex2f(840,0);glVertex2f(800,40);glVertex2f(800,80);glEnd();
  • //trofeo feoglColor3f(1.0 , 00, 0.0);glBegin(GL_POLYGON);glVertex2f(920,600);glVertex2f(1000,600);glVertex2f(960,560);glVertex2f(1040,440);glVertex2f(1040,360);glVertex2f(1000,400);glVertex2f(920,560);glEnd();glColor3f(1.0 , 1.1 , 0.0);glBegin(GL_TRIANGLES);glVertex2f(1000,600);glVertex2f(1120,600);glColor3f(1.0 , 0.0,0.0);glVertex2f(1060,360);glEnd();glColor3f(1.0 , 00, 0.0);glBegin(GL_POLYGON);glVertex2f(1080,360);glVertex2f(1080,440);glVertex2f(1160,560);glVertex2f(1160,560);glVertex2f(1120,600);glVertex2f(1200,600);
  • glVertex2f(1200,560);glEnd();glColor3f(1.0 , 1.1 , 0.0);glBegin(GL_TRIANGLES);glVertex2f(560,360);glVertex2f(560,40);glVertex2f(480,280);glEnd();glColor3f(1.0 , 00, 0.0);glBegin(GL_TRIANGLES);glVertex2f(1000,320);glVertex2f(1060,360);glVertex2f(1120,320);glEnd();glFlush(); //forza dibujo}int main (int argc, char** argv) //metodo main{glutInit(&argc, argv); //incializa GLUTglutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); //establece el modo de visualización
  • glutInitWindowSize(500,500); //tamaño de la ventanaglutInitWindowPosition(0,0); //posicion inicial de la ventanaglutCreateWindow("mi primera ventana"); //nombre de la ventanainicializa();glutDisplayFunc(dibuja); //Envia los graficos a la ventana de visualizaciónglutMainLoop(); //muestra todo y esperareturn 0; //retorna un valor de cero}
  • CasitaEn esta práctica se ocuparan los cuadrados, triángulos,polígonos, líneas y si es necesario círculos y degradados, paracrear una casa.Código:#include <GL/glut.h>#include <GL/gl.h>#include <math.h>void inicializa(void){glClearColor(0.0,1.0,1.0,0.0); //color de fondoglMatrixMode(GL_PROJECTION); //Modo de proyeccionglLoadIdentity(); //Establece los parametros de proyecciongluOrtho2D(0.0, 2000.0, 0.0, 2000.0); //vista ortogonal}void circuloc(int x, int y, int t, int radio){ int angulo=0; glPointSize(t); glBegin(GL_POINTS); //glColor3f (1.0, 0.0, 1.0); glVertex2f(x,y); //glColor3f(0,0.0,0.0); for (angulo=0;angulo<=360; angulo+=1){ glVertex2f(x + sin(angulo) * radio, y + cos(angulo) *radio);} glEnd();}void circulo(int x, int y, int radio)
  • { int angulo=0; glBegin(GL_TRIANGLE_FAN); // glColor3f (1.0, 0.0, 1.0); glVertex2f(x,y); for (angulo=0;angulo<=360; angulo+=1){ glVertex2f(x + sin(angulo) * radio, y + cos(angulo) *radio);} glEnd();}void dibuja(void) //funcion dibuja{glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(0,680);glVertex2f(0,640);glVertex2f(1640,640);glVertex2f(1640,680);glEnd();//techoglColor3f(1.0 , 00, 0.0);glBegin(GL_POLYGON);glVertex2f(920,1200);glVertex2f(840,1280);glVertex2f(400,1280);glVertex2f(320,1200);glEnd();//cuerpo de casa
  • glColor3f(0.0 , 0.0, 0.0);glBegin(GL_QUADS);glVertex2f(360,1200);glVertex2f(880,1200);glVertex2f(880,600);glVertex2f(360,600);glEnd();//ventana izquierdaglColor3f(1.0 , 1.0, 1.0);glBegin(GL_QUADS);glVertex2f(360,1120);glVertex2f(360,1000);glVertex2f(480,1000);glVertex2f(480,1120);glEnd();//ventana derechaglColor3f(1.0 , 1.0, 1.0);glBegin(GL_QUADS);glVertex2f(760,1120);glVertex2f(760,1000);glVertex2f(880,1000);glVertex2f(880,1120);glEnd();//linea cuerpo izquierdaglColor3f(0.0 , 1.0, 0.0);glBegin(GL_QUADS);glVertex2f(480,1160);glVertex2f(480,600);glVertex2f(520,600);
  • glVertex2f(520,1160);glEnd();glColor3f(0.0 , 1.0, 0.0);glBegin(GL_QUADS);glVertex2f(720,1160);glVertex2f(720,600);glVertex2f(760,600);glVertex2f(760,1160);glEnd();//triangulo ttechoglColor3f(1.0 , 1.0 , 0.0);glBegin(GL_TRIANGLES);glVertex2f(480,1160);glVertex2f(600,1240);glVertex2f(760,1160);glEnd();//cuadro abajo de triangulo techoglColor3f(1.0, 0.0,0.0);glBegin(GL_QUADS);glVertex2f(520,1160);glVertex2f(520,1000);glColor3f(0.0 , 0.0,1.0);glVertex2f(720,1000);glColor3f(0.0 , 0.0,0.0);glVertex2f(720,1160);glEnd();glColor3f(0.0, 1.0,0.0);glBegin(GL_QUADS);glVertex2f(600,1160);
  • glVertex2f(600,1000);glVertex2f(640,1000);glVertex2f(640,1160);glEnd();//vcentanalesglColor3f(1.0,1.0,0.0);glBegin(GL_QUADS);glVertex2f(520,1000);glVertex2f(520,920);glVertex2f(560,920);glVertex2f(560,1000);glEnd();glColor3f(1.0,1.0,1.0);glBegin(GL_QUADS);glVertex2f(560,1000);glVertex2f(560,920);glVertex2f(600,920);glVertex2f(600,1000);glEnd();glColor3f(1.0,1.0,0.0);glBegin(GL_QUADS);glVertex2f(600,1000);glVertex2f(600,920);glVertex2f(640,920);glVertex2f(640,1000);glEnd();glColor3f(1.0,1.0,1.0);glBegin(GL_QUADS);glVertex2f(640,1000);
  • glVertex2f(640,920);glVertex2f(680,920);glVertex2f(680,1000);glEnd();glColor3f(1.0,1.0,0.0);glBegin(GL_QUADS);glVertex2f(680,1000);glVertex2f(680,920);glVertex2f(720,920);glVertex2f(720,1000);glEnd();//linea horizontal cuerpo casaglColor3f(0.0,1.0,0.0);glBegin(GL_QUADS);glVertex2f(360,920);glVertex2f(360,880);glVertex2f(880,880);glVertex2f(880,920);glEnd();//ventana izquierda abajaoglColor3f(1.0,1.0,1.0);glBegin(GL_QUADS);glVertex2f(360,800);glVertex2f(360,680);glVertex2f(480,680);glVertex2f(480,800);glEnd();//ventana derecha abajoglColor3f(1.0,1.0,1.0);
  • glBegin(GL_QUADS);glVertex2f(760,800);glVertex2f(760,680);glVertex2f(880,680);glVertex2f(880,800);glEnd();//puertaglColor3f(1.0,0.0,1.0);glBegin(GL_QUADS);glVertex2f(520,840);glVertex2f(520,600);glVertex2f(720,600);glVertex2f(720,840);glEnd();//dentro de puertaglColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(560,800);glVertex2f(560,640);glVertex2f(640,640);glVertex2f(640,800);glEnd();//manijaglColor3f(0.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(640,720);glVertex2f(640,680);glVertex2f(680,680);glVertex2f(680,720);
  • glEnd();//cocheraglColor3f(1.0 , 00, 0.0);glBegin(GL_POLYGON);glVertex2f(360,880);glVertex2f(80,880);glVertex2f(40,800);glVertex2f(360,800);glEnd();glColor3f(1.0 , 00, 0.0);glBegin(GL_QUADS);glVertex2f(0,320);glVertex2f(0,280);glColor3f(1.0 , 1.0,0.0);glVertex2f(1680,280);glColor3f(1.0 , 1.0,0.0);glVertex2f(1680,320);glEnd();glColor3f(1.0 , 00, 0.0);glBegin(GL_QUADS);glVertex2f(520,320);glVertex2f(520,600);glColor3f(1.0 , 1.0,0.0);glVertex2f(720,600);glColor3f(1.0 , 1.0,0.0);glVertex2f(720,320);glEnd();//cuerpo cocheraglColor3f(1.0,0.0,1.0);glBegin(GL_POLYGON);
  • glVertex2f(80,800);glVertex2f(80,600);glVertex2f(360,600);glVertex2f(360,800);glEnd();glColor3f(1.0 , 1.0,0.0);glBegin(GL_QUADS);glVertex2f(0,280);glVertex2f(0,240);glVertex2f(1680,240);glVertex2f(1680,280);glEnd();//carreteraglColor3f(0.0 , 0.0,0.0);glBegin(GL_QUADS);glVertex2f(0,240);glVertex2f(0,0);glVertex2f(1680,0);glVertex2f(1680,240);glEnd();//barras de carretyeraglColor3f(1.0 , 1.0,1.0);glBegin(GL_QUADS);glVertex2f(40,160);glVertex2f(40,120);glVertex2f(440,120);glVertex2f(440,160);glEnd();
  • glColor3f(1.0 , 1.0,1.0);glBegin(GL_QUADS);glVertex2f(520,160);glVertex2f(520,120);glVertex2f(920,120);glVertex2f(920,160);glEnd();glColor3f(1.0 , 1.0,1.0);glBegin(GL_QUADS);glVertex2f(1080,160);glVertex2f(1080,120);glVertex2f(1560,120);glVertex2f(1560,160);glEnd();//pastoglColor3f(0.0 , 1.0,0.0);glBegin(GL_QUADS);glVertex2f(0,600);glVertex2f(0,320);glVertex2f(520,320);glVertex2f(520,600);glEnd();glColor3f(0.0 , 1.0,0.0);glBegin(GL_QUADS);glVertex2f(720,600);glVertex2f(720,320);glVertex2f(1680,320);glVertex2f(1680,600);glEnd();
  • //carro izquierdaglColor3f(1.0,0.0,0.0);glBegin(GL_POLYGON);glVertex2f(400,440);glVertex2f(240,440);glVertex2f(160,360);glVertex2f(480,360);glEnd();glColor3f(1.0 , 0.0,0.0);glBegin(GL_QUADS);glVertex2f(160,360);glVertex2f(160,280);glVertex2f(600,280);glVertex2f(600,360);glEnd();//ventanas carro izquierdoglColor3f(0.0 , 0.0,0.0);glBegin(GL_QUADS);glVertex2f(200,400);glVertex2f(200,320);glVertex2f(280,320);glVertex2f(280,400);glEnd();glColor3f(0.0 , 0.0,0.0);glBegin(GL_QUADS);glVertex2f(320,400);glVertex2f(320,320);glVertex2f(400,320);glVertex2f(400,400);
  • glEnd();//trailerglColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(920,360);glVertex2f(920,240);glVertex2f(1160,240);glVertex2f(1160,360);glEnd();glColor3f(1.0 , 1.0 , 1.0);glBegin(GL_TRIANGLES);glVertex2f(960,360);glVertex2f(1000,440);glVertex2f(1000,360);glEnd();glColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(1000,440);glVertex2f(1000,360);glVertex2f(1160,360);glVertex2f(1160,440);glEnd();//ventana trailer cuadradaglColor3f(1.0,1.0,1.0);glBegin(GL_QUADS);glVertex2f(1040,440);glVertex2f(1040,360);
  • glVertex2f(1120,360);glVertex2f(1120,440);glEnd();//base de treaileerglColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(880,240);glVertex2f(880,160);glVertex2f(1440,160);glVertex2f(1440,240);glEnd();//caja de trailerglColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(1200,520);glVertex2f(1200,240);glVertex2f(1440,240);glVertex2f(1440,520);glEnd();//cosa que le sale al trailerglColor3f(1.0,0.0,1.0);glBegin(GL_QUADS);glVertex2f(840,320);glVertex2f(840,160);glVertex2f(880,160);glVertex2f(880,320);glEnd();//a estoes parte de las ventanas de la casaglColor3f(1.0,0.0,1.0);
  • glBegin(GL_QUADS);glVertex2f(360,1080);glVertex2f(360,1040);glVertex2f(480,1040);glVertex2f(480,1080);glEnd();glColor3f(1.0,0.0,1.0);glBegin(GL_QUADS);glVertex2f(360,760);glVertex2f(360,720);glVertex2f(480,720);glVertex2f(480,760);glEnd();glColor3f(1.0,0.0,1.0);glBegin(GL_QUADS);glVertex2f(760,1080);glVertex2f(760,1040);glVertex2f(880,1040);glVertex2f(880,1080);glEnd();glColor3f(1.0,0.0,1.0);glBegin(GL_QUADS);glVertex2f(760,760);glVertex2f(760,720);glVertex2f(880,720);glVertex2f(880,760);glEnd();//barandalglColor3f(1.0,0.0,0.0);
  • glBegin(GL_QUADS);glVertex2f(0,720);glVertex2f(0,600);glVertex2f(40,600);glVertex2f(40,720);glEnd();glColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(920,720);glVertex2f(920,600);glVertex2f(960,600);glVertex2f(960,720);glEnd();glColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(1000,720);glVertex2f(1000,600);glVertex2f(1040,600);glVertex2f(1040,720);glEnd();glColor3f(0.6,0.4,0.2);glBegin(GL_QUADS);glVertex2f(1080,720);glVertex2f(1080,600);glVertex2f(1240,600);glVertex2f(1240,720);glEnd();//troncoglColor3f(0.6,0.4,0.2);
  • glBegin(GL_QUADS);glVertex2f(1120,720);glVertex2f(1120,600);glVertex2f(1160,600);glVertex2f(1160,720);glEnd();//ramasglBegin(GL_LINES);//llantasglColor3f(0.6,0.4,0.2);circulo(240,240,50);circulo(240,240,25);glEnd();glColor3f(0.6,0.4,0.2);circulo(520,240,50);circulo(520,240,25);glEnd();glColor3f(0.6,0.4,0.2);circulo(1000,80,100);circulo(1000,80,50);glEnd();glColor3f(0.6,0.4,0.2);circulo(1360,80,100);circulo(1360,80,50);glColor3f(0.0,0.6,0.2);glBegin(GL_QUADS);glVertex2f(1000,760);
  • glVertex2f(1000,720);glVertex2f(1400,720);glVertex2f(1400,760);glEnd();glColor3f(0.0,0.6,0.2);glBegin(GL_QUADS);glVertex2f(1040,840);glVertex2f(1040,800);glVertex2f(1320,800);glVertex2f(1320,840);glEnd();glColor3f(0.0,0.6,0.2);glBegin(GL_QUADS);glVertex2f(1080,920);glVertex2f(1080,880);glVertex2f(1280,880);glVertex2f(1280,920);glEnd();glColor3f(0.0,0.6,0.2);glBegin(GL_QUADS);glVertex2f(1120,1000);glVertex2f(1120,960);glVertex2f(1240,960);glVertex2f(1240,1000);glEnd();glColor3f(0.0,0.6,0.2);glBegin(GL_QUADS);glVertex2f(1160,1080);glVertex2f(1150,1040);
  • glVertex2f(1200,1040);glVertex2f(1200,1080);glEnd();//barandal, despues del troncoglColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(1280,720);glVertex2f(1280,600);glVertex2f(1320,600);glVertex2f(1320,720);glEnd();glColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(1360,720);glVertex2f(1360,600);glVertex2f(1400,600);glVertex2f(1400,720);glEnd();glColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(1440,720);glVertex2f(1440,600);glVertex2f(1480,600);glVertex2f(1480,720);glEnd();glColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(1520,720);glVertex2f(1520,600);
  • glVertex2f(1560,600);glVertex2f(1560,720);glEnd();glColor3f(1.0,0.0,0.0);glBegin(GL_QUADS);glVertex2f(1600,720);glVertex2f(1600,600);glVertex2f(1640,600);glVertex2f(1640,720);glEnd();glFlush(); //forza dibujo}int main (int argc, char** argv) //metodo main{glutInit(&argc, argv); //incializa GLUTglutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); //establece el modo de visualizaciónglutInitWindowSize(500,500); //tamaño de la ventanaglutInitWindowPosition(0,0); //posicion inicial de la ventanaglutCreateWindow("tablero"); //nombre de la ventanainicializa();glutDisplayFunc(dibuja); //Envia los graficos a la ventana de visualizaciónglutMainLoop(); //muestra todo y esperareturn 0; //retorna un valor de cero}
  • OsoPrimera práctica en la cual oficialmente se ocuparan los círculospara crear con solo círculos un oso.Código:#include <GL/glut.h>#include <GL/gl.h>#include <math.h>void inicializa(void){glClearColor(0.0,1.0,1.0,0.0); //color de fondoglMatrixMode(GL_PROJECTION); //Modo de proyeccionglLoadIdentity(); //Establece los parametros de proyecciongluOrtho2D(0.0, 2000.0, 0.0, 2000.0); //vista ortogonal}void circuloc(int x, int y, int t, int radio){ int angulo=0; glPointSize(t); glBegin(GL_POINTS); //glColor3f (1.0, 0.0, 1.0); glVertex2f(x,y); //glColor3f(0,0.0,0.0); for (angulo=0;angulo<=360; angulo+=1){ glVertex2f(x + sin(angulo) * radio, y + cos(angulo) *radio);} glEnd();}void circulo(int x, int y, int radio){
  • int angulo=0; glBegin(GL_TRIANGLE_FAN); // glColor3f (1.0, 0.0, 1.0); glVertex2f(x,y); for (angulo=0;angulo<=360; angulo+=1){ glVertex2f(x + sin(angulo) * radio, y + cos(angulo) *radio);} glEnd();}void dibuja(void) //funcion dibuja{//cara y orejasglClear(GL_COLOR_BUFFER_BIT);glColor3f(0.6 , 0.4, 0.2);circulo(400,1000,120);circulo(800,1000,120);circulo(600,840,200);glEnd();//cuerpoglColor3f(0.6 , 0.4, 0.2);glBegin(GL_QUADS);glVertex2f(520,640);glVertex2f(520,360);glVertex2f(680,360);glVertex2f(680,640);glEnd();//brazosglColor3f(0.6 , 0.4, 0.2);glBegin(GL_QUADS);glVertex2f(360,640);
  • glVertex2f(360,560);glVertex2f(520,560);glVertex2f(520,640);glEnd();glColor3f(0.6 , 0.4, 0.2);glBegin(GL_QUADS);glVertex2f(680,640);glVertex2f(680,560);glVertex2f(840,560);glVertex2f(840,640);glEnd();//piernasglColor3f(0.6 , 0.4, 0.2);glBegin(GL_QUADS);glVertex2f(440,360);glVertex2f(440,280);glVertex2f(520,280);glVertex2f(520,360);glEnd();glColor3f(0.6 , 0.4, 0.2);glBegin(GL_QUADS);glVertex2f(680,360);glVertex2f(680,280);glVertex2f(760,280);glVertex2f(760,360);glEnd();//patasglColor3f(0.6 , 0.4, 0.2);circulo(360,320,120);
  • circulo(840,320,120);glEnd();//manosglColor3f(0.6 , 0.4, 0.2);circulo(320,600,120);circulo(880,600,120);glEnd();//ojosglColor3f(0.0 , 0.0, 0.0);circulo(520,920,40);circulo(680,920,40);glEnd();//ocicoglColor3f(1.0 , 1.0, 1.0);circulo(600,800,80);glEnd();glColor3f(0.0 , 0.0, 0.0);circulo(600,800,40);glEnd();glFlush(); //forza dibujo}int main (int argc, char** argv) //metodo main{glutInit(&argc, argv); //incializa GLUTglutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); //establece el modo de visualizaciónglutInitWindowSize(500,500); //tamaño de la ventana
  • glutInitWindowPosition(0,0); //posicion inicial de la ventanaglutCreateWindow("tablero"); //nombre de la ventanainicializa();glutDisplayFunc(dibuja); //Envia los graficos a la ventana de visualizaciónglutMainLoop(); //muestra todo y esperareturn 0; //retorna un valor de cero}
  • Cubo con cubitosSe realizara un cubo hecho de cubos más pequeños y delineados,hasta crear una práctica parecida a la de cubo con líneas,sustituyendo estas por cubos.Código:#include <GL/glut.h>#include <GL/gl.h>void inicializa(void){glClearColor(1.0,1.0,1.0,0.0); //color de fondoglMatrixMode(GL_PROJECTION); //Modo de proyeccionglLoadIdentity(); //Establece los parametros de proyecciongluOrtho2D(0.0, 800.0, 0.0, 800.0); //vista ortogonal}void cubo (int x, int y,int t,int l){ double a=.8,b=.6;glColor3f(1.0 , 1.0 , 0.0);glBegin(GL_QUADS);glVertex2f(x,y);glVertex2f(x+t,y);glVertex2f(x+t,y+t);glVertex2f(x,y+t);glColor3f(1.0 , 0.0 , 1.0);glVertex2f(x,y+t);glVertex2f(x+t,y+t);glVertex2f(x+t+(t*a),y+t+(t*b));glVertex2f(x+(t*a),y+t+(t*b));
  • glColor3f(1.0 , 0.0 , 0.0);glVertex2f(x+t,y+t);glVertex2f(x+t+(t*a),y+t+(t*b));glVertex2f(x+t+(t*a),y+(t*b));glVertex2f(x+t,y);glEnd();glColor3f(0.0 , 0.0 , 0.0);glLineWidth(l);glBegin(GL_LINES);glVertex2f(x,y);glVertex2f(x+t,y);glVertex2f(x+t,y);glVertex2f(x+t,y+t);glVertex2f(x+t,y+t);glVertex2f(x,y+t);glVertex2f(x,y);glVertex2f(x,y+t);glVertex2f(x+t,y+t);glVertex2f(x+t,y+t);glVertex2f(x+t+(t*a),y+t+(t*b));glVertex2f(x+t+(t*a),y+t+(t*b));glVertex2f(x+(t*a),y+t+(t*b));glVertex2f(x,y+t);glVertex2f(x+t+(t*a),y+t+(t*b));glVertex2f(x+(t*a),y+t+(t*b));
  • glVertex2f(x+t,y+t);glVertex2f(x+t+(t*a),y+t+(t*b));glVertex2f(x+t+(t*a),y+t+(t*b));glVertex2f(x+t+(t*a),y+(t*b));glVertex2f(x+t+(t*a),y+(t*b));glVertex2f(x+t,y);glVertex2f(x+t,y+t);glEnd(); }void dibuja(void) //funcion dibuja{glClear(GL_COLOR_BUFFER_BIT); //borra pantallaglColor3f(1.0 , 0.0 , 0.0);for(int k=0;k<=7;k++){cubo(240-20*k*.8,200-20*k*.6,20,5);}for(int j=0;j<=12;j++){cubo(260+20*j,220,20,5);}for(int i=0;i<=9;i++){cubo(260,240+20*i,20,5);}for(int k=0;k<=9;k++){cubo(260-20*k*.8,420-20*k*.6,20,5);}for(int j=0;j<=10;j++){cubo(280+20*j,420,20,5);
  • }for(int k=0;k<=9;k++){cubo(500-20*k*.8,220-20*k*.6,20,5);}for(int i=0;i<=8;i++){cubo(500,240+20*i,20,5);}for(int k=0;k<=10;k++){cubo(500-20*k*.8,420-20*k*.6,20,5);}for(int i=0;i<=10;i++){cubo(100,100+20*i,20,5);}for(int j=0;j<=10;j++){cubo(120+20*j,100,20,5);cubo(120+20*j,300,20,5);}for(int i=0;i<=10;i++){cubo(340,100+20*i,20,5);}
  • glFlush(); //forza dibujo}int main (int argc, char** argv) //metodo main{glutInit(&argc, argv); //incializa GLUTglutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); //establece el modo de visualizaciónglutInitWindowSize(500,500); //tamaño de la ventanaglutInitWindowPosition(100,100); //posicion inicial de la ventanaglutCreateWindow("Ventana"); //nombre de la ventanainicializa();glutDisplayFunc(dibuja); //Envia los graficos a la ventana de visualizaciónglutMainLoop(); //muestra todo y esperareturn 0; //retorna un valor de cero}
  • Muñeco con formas.
  • Animación circuloAl hacer un círculo, se le pondrá movimiento, para que cubra surecorrido las orillas de la pantalla.Código:#include <unistd.h>#include <GL/glut.h>#include <GL/gl.h>#include <math.h>int x=1, y=1,z=1,w=1;void inicializa(void){glClearColor(0.0,0.0,1.0,0.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0, 700.0, 0.0, 700.0);// el ancho y largo de nuestra pantalla}void circulo(int x, int y, int radio){ int angulo=0; glBegin(GL_TRIANGLE_FAN); glColor3f (0.5, 0.5, 0.5); glVertex2f(x,y); glColor3f(0,0.0,0.0); for (angulo=0;angulo<=360; angulo+=6){ glVertex2f(x + sin(angulo) * radio, y + cos(angulo) *radio);} glEnd();}void dibuja(void){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//abajo
  • if(x>=1 && x<500){circulo(100+1*x,100,40);x++;}// derecha para arribaif (x==500 && y>=1 && y<500 ) {circulo(600,100+1*y,40);y++;}//arriba para izquierdaif (x==500 && y==500 && z>=1 && z<500) {circulo (600-z,600,40);z++;}//izquerda hacia abajoif (x==500 && y==500 && z==500 && w>=1 && w<500){circulo (100,600-w,40);w++;}if(w==500){ x=1;y=1; z=1; w=1;}glFlush();glutSwapBuffers();}int main (int argc, char** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA| GLUT_DEPTH);glutInitWindowSize(700,700);glutInitWindowPosition(10,10);glutCreateWindow("Ventana");inicializa();glutDisplayFunc(dibuja);glutIdleFunc(dibuja);glutMainLoop();return 0;}
  • Animación sistema solar.Movimiento circular, será lo que tendrán nuestros planetas(círculos) . Se realizaran las “orbitas” y sobre su circunferencia deestas, giraran.Código:#include <unistd.h>#include <GL/glut.h>#include <GL/gl.h>#include <math.h>int rad=100;double ang=0,a=0,b=0,c=0, d=0, e=0, f=0;void inicializa(void){glClearColor(0.0,0.0,0.0,0.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0, 1000.0, 0.0, 1000.0);// el ancho y largo de nuestra pantalla}void circulo(int x, int y, int radio){ int angulo=0; glBegin(GL_TRIANGLE_FAN); glVertex2f(x,y); for (angulo=0;angulo<=360; angulo++){ glVertex2f(x + sin(angulo) * radio, y + cos(angulo) *radio);} glEnd();}
  • void circuloc(int x, int y, int t, int radio){ int angulo=0; glPointSize(t); glBegin(GL_POINTS); glVertex2f(x,y); for (angulo=0;angulo<=360; angulo+=1){ glVertex2f(x + sin(angulo) * radio, y + cos(angulo) *radio);} glEnd();}void dibuja(void){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//esto glColor3f(1.0,0.0,0.0);circulo( 500+ sin(ang) * 0,500 + cos(ang) * 0,50); //funcion circuloglColor3f(1.0,1.0,1.0);circuloc(500,500,1,100);circuloc(500,500,1,150);circuloc(500,500,1,200);circuloc(500,500,1,250);circuloc(500,500,1,300);circuloc(500,500,1,350);circuloc(500,500,1,400);circuloc(500,500,1,450);glColor3f(0.8,0.4,0.1);circulo( 500+ sin(a) * 100,500 + cos(a) * 100,5);
  • glColor3f(0.6,0.3,0.1);circulo( 500+ sin(b) * 150,500 - cos(b) * 150,7); glColor3f(0.1,0.7,0.8);circulo( 500+ sin(c) * 200,500 + cos(c) * 200,10); glColor3f(0.8,0.07,0.2);circulo( 500+ sin(d) * 250,500 - cos(d) * 250,10);glColor3f(0.9,0.6,0.2);circulo( 500+ sin(e) * 300,500 + cos(e) * 300,18);glColor3f(0.2,0.9,0.7);circulo( 500+ sin(f) * 350,500 - cos(f) * 350,14);glColor3f(0.2,0.7,0.9);circulo( 500+ sin(ang) * 400,500 + cos(ang) * 400,12);glColor3f(0.0,0.1,0.9);circulo( 500+ sin(a) * 450,500 - cos(a) * 450,12);a+=0.01; //a=a+0.1;b+=0.02;c+=0.03;d+=0.04;e+=0.05;f+=0.06;ang=ang+0.01; //velocidad entre mas grande mas rapido y entre menos mas lentofor(int j=1;j<=10000000;j++){}//pausaif(ang==360){ang=0;}// se repite idefinidamenteglFlush(); //forzar dibujadoglutSwapBuffers(); //y esto}
  • int main (int argc, char** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA| GLUT_DEPTH);//esto tambienglutInitWindowSize(1000,1000);glutInitWindowPosition(10,10);glutCreateWindow("Ventana");inicializa();glutDisplayFunc(dibuja);glutIdleFunc(dibuja);//esto es lo que cambiaglutMainLoop();return 0;}
  • Movimiento en ocho.Con círculos, se simulara un ocho, es decir pegar los círculos,para que dentro de estos, se mueva una pequeña bolita, quehará un movimiento en forma de ocho.Código:#include <unistd.h>#include <GL/glut.h>#include <GL/gl.h>#include <math.h>int x=1, x2=1,y=1;double a=6.15, b=6.15;void inicializa(void){glClearColor(0.0,0.0,0.0,0.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0, 700.0, 0.0, 700.0);// el ancho y largo de nuestra pantalla}void circulo(int x, int y, int radio){ int angulo=0; glBegin(GL_TRIANGLE_FAN); glVertex2f(x,y); for (angulo=0;angulo<=360; angulo+=6){ glVertex2f(x + sin(angulo) * radio, y + cos(angulo) *radio);} glEnd();} void dibuja(void){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glColor3f(1.0, 1.0, 1.0);
  • circulo(300, 300, 70);circulo(300,180,70);glColor3f(0.0,0.0,0.0);circulo(300,300,50);circulo(300,180,50);glColor3f(1.0,0.0,0.0);if(a>=6.15 && a<=12.41){circulo(300+ sin (a)*60,300- cos(a)*60,10);a=a+0.01;}else{circulo(300 + sin (b) *60,180-cos(b)*-60,10);b=b + 0.14;if(b>12.4){a=6.15;b=6.15;}for(int j=0; j<=10000000; j++) {}}glFlush();glutSwapBuffers();}int main (int argc, char** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA| GLUT_DEPTH);glutInitWindowSize(700,700);glutInitWindowPosition(10,10);glutCreateWindow("Ventana");inicializa();
  • glutDisplayFunc(dibuja);glutIdleFunc(dibuja);glutMainLoop();return 0;}