Académique Documents
Professionnel Documents
Culture Documents
#include <windows.h>
#include <iostream>
#include <C:\GLUT\include\GL\glut.h>
using namespace std;
void punts(void){
glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,1.0); //
glOrtho(0.0,50000.0,0.0,50000.0,0.0,50000.0);
//glFlush();
glutSwapBuffers();
}
}
//glFlush();
glutSwapBuffers();
}
int main(int argc, char *argv[]){
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(400, 400);
glutInitWindowPosition(100, 100);
glutCreateWindow("NARCO_PAPU");
glutDisplayFunc(punts);
glutMainLoop();
}
//cambia el color de la pantalla
#include <windows.h>
#include <iostream>
#include <C:\GLUT\include\GL\glut.h>
using namespace std;
void punts(void){
for(int i=0; i<5;i++){
float a=rand()%10;
float b=rand()%10;
float c=rand()%10;
a=a/10;
b=b/10;
c=c/10;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0); //
glOrtho(0.0,50000.0,0.0,50000.0,0.0,50000.0);
glClearColor(a,b,c,0.0);
glFlush();
glutSwapBuffers();
for(int j=0; j<10100;j++){ //retraso :V
cout<<"----";
}
}
glFlush();
glutSwapBuffers();
}
int main(int argc, char *argv[]){
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(400, 400);
glutInitWindowPosition(100, 100);
glutCreateWindow("NARCO_PAPU");
glutDisplayFunc(punts);
glutMainLoop();
}
--------------------------------------------------------------------------------------------
//Traslacin
//Dibuja un cuadrado y avanza a la Derecha, Izquierda, Arriba y Abajo
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#define ancho 320
#define altura 240
#define profundidad 500
int posx=0, posy=0;
void ejesxy() {
glColor3f(0.0, 0.5, 1.0);
glBegin(GL_LINES);
glVertex2f(-ancho/2, 0);
glVertex2f(ancho/2, 0);
glVertex2f(0, altura/2);
glVertex2f(0, -altura/2);
glEnd();
}
void DibujaCuadrado() {
glClear(GL_COLOR_BUFFER_BIT);
ejesxy();
glPushMatrix();
glTranslatef(posx, posy,0);
glBegin(GL_QUADS);
glColor3f(0.5, 1.0, 0.0); glVertex2f(0,70);
glColor3f(1.0, 1.0, 0.0); glVertex2f(0,0);
glColor3f(0.5, 1.0, 0.0); glVertex2f(70,0);
glColor3f(1.0, 1.0, 0.0); glVertex2f(70,70);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
void TecladoMovimiento(int tecla, int x, int y) {
switch(tecla) {
case GLUT_KEY_UP : posy++;break;
case GLUT_KEY_DOWN : posy--;break;
case GLUT_KEY_RIGHT : posx++;break;
case GLUT_KEY_LEFT : posx--;break;
}
glutPostRedisplay();
}
int main(int argc, char** argv) {
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowPosition(100, 0);
glutInitWindowSize(ancho, altura);
glutCreateWindow("Traslacin 2D ");
glOrtho(-(ancho/2), (ancho/2), -(altura/2), (altura/2), -profundidad, profundidad);
glClearColor(1, 1, 1, 0);
glutDisplayFunc(DibujaCuadrado);
glutSpecialFunc(TecladoMovimiento);
glutMainLoop();
return 0;
}
//Rotacion de un cuadrado de 2D en su mismo eje
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#define ancho 320
#define altura 240
#define profundidad 500
int angulo=0;
void EjesXY() {
glColor3f(1.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex2i(-ancho/2, 0);
glVertex2i(ancho/2, 0);
glVertex2i(0, altura/2);
glVertex2i(0, -altura/2);
glEnd();
}
void DibujaCuadrado() {
glClear(GL_COLOR_BUFFER_BIT);
EjesXY();
glPushMatrix();
glRotatef(angulo, 0, 0, 1);
glBegin(GL_QUADS);
glColor3f(1, 0, 0);glVertex2i(50,50);
glColor3f(1, 1, 0);glVertex2i(-50, 50);
glColor3f(1, 0, 0);glVertex2i(-50, -50);
glColor3f(1, 1, 0);glVertex2i(50, -50);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
void CoordenadasXY() {
glColor3f(0, 0, 1);
glBegin(GL_LINES);
glVertex2i(-320, 0);
glVertex2i(320, 0);
glVertex2i(0, -240);
glVertex2i(0, 240);
glEnd();
}
void DibujaCuadrado() {
glClear(GL_COLOR_BUFFER_BIT);
CoordenadasXY();
glPushMatrix();
glEnd();
glPopMatrix();
glutSwapBuffers();
}
glClearColor(1, 1, 1, 1);
glutDisplayFunc(DibujaCuadrado);
glutSpecialFunc(TecladoScala);
glutMainLoop();
return 0;
}
//Traslacin, rotacion, reduccion
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#define ancho 320
#define altura 240
#define profundidad 500
int posx=0, posy=0, angulo=0;
float esc=1;
void ejesxy() {
glColor3f(0.0, 0.5, 1.0);
glBegin(GL_LINES);
glVertex2f(-ancho/2, 0);
glVertex2f(ancho/2, 0);
glVertex2f(0, altura/2);
glVertex2f(0, -altura/2);
glEnd();
}
void DibujaCuadrado() {
glClear(GL_COLOR_BUFFER_BIT);
ejesxy();
glPushMatrix();
glTranslatef(posx, posy,0);
glRotatef(angulo, 0, 0, 1);
glScalef(esc, esc, esc);
glBegin(GL_QUADS);
glColor3f(1, 0, 0);glVertex2i(50,50);
glColor3f(1, 1, 0);glVertex2i(-50, 50);
glColor3f(1, 0, 0);glVertex2i(-50, -50);
glColor3f(1, 1, 0);glVertex2i(50, -50);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
void TecladoMovimiento(unsigned char tecla, int x, int y) {
switch(tecla) {
case 'w' : posy++;break;
case 's' : posy--;break;
case 'd' : posx++;break;
case 'a' : posx--;break;
case 'l':
case 'L': angulo++; break;
case 'r':
case 'R': angulo--; break;
case 'z':
case 'Z':esc=esc*1.01; break;
case 'm':
case 'M':esc=esc*0.99; break;
}
glutPostRedisplay();
}
int main(int argc, char** argv) {
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowPosition(100, 0);
glutInitWindowSize(ancho, altura);
glutCreateWindow("Traslacin 2D ");
glOrtho(-(ancho/2), (ancho/2), -(altura/2), (altura/2), -profundidad, profundidad);
glClearColor(1, 1, 1, 0);
glutDisplayFunc(DibujaCuadrado);
glutKeyboardFunc(TecladoMovimiento);
glutMainLoop();
return 0;
}
----------------------------------------------------------------
// Rotacion de un objeto 3d (Tetera)
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#include <conio.h>
int angulo=45;
void DibujaObjeto3D() {
glClear(GL_COLOR_BUFFER_BIT); glPushMatrix();
glRotatef(angulo, 1, 1, 1);
glColor3f(1, 0, 0);
glutWireTeapot(140);
glPopMatrix(); glutSwapBuffers();
}
glPushMatrix();
glTranslatef(posx+100,posy,0);
glRotatef(45,1,1,1);
glColor3f(1.0,0.0,1.0);
glutWireTeapot(50);
glPopMatrix();
glPushMatrix();
glTranslatef(posx+200,posy,0);
glRotatef(45,1,1,1);
glColor3f(1.0,1.0,1.0);
glutWireTeapot(50);
glPopMatrix();
glutSwapBuffers();
}
void TecladoEspecial(int tecla, int x, int y){
switch(tecla){
case GLUT_KEY_UP :posy++; break;
case GLUT_KEY_DOWN :posy--; break;
case GLUT_KEY_RIGHT :posx++; break;
case GLUT_KEY_LEFT :posx--; break;
}
glutPostRedisplay();
}
void Teclado(unsigned char tecla, int x, int y) {
switch(tecla) {
case 'w':posy++;
case 'W':posy++; break;
case 's':posy--;
case 'S':posy--; break;
case 'd':posx++;
case 'D':posx++; break;
case 'a':posx--;
case 'A':posx--; break;
}
glutPostRedisplay();
}
void TecladoF(int tecla, int x, int y){
switch(tecla){
case GLUT_KEY_F1 :posy++; break;
case GLUT_KEY_F2 :posy--; break;
case GLUT_KEY_F3 :posx++; break;
case GLUT_KEY_F4 :posx--; break;
}
glutPostRedisplay();
}
int main(int argc, char** argv){
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(ancho,alto);
glutInitWindowPosition(200,200);
glutCreateWindow("Figuras Glut");
glOrtho(-(ancho/2),(ancho/2),-(alto/2),(alto/2),-profundidad,profundidad);
glClearColor(1,1,0.5,0);
glutDisplayFunc(DibujaObjeto3D);
glutKeyboardFunc(Teclado);
glutMainLoop();
return 0;
}
//Traslacin
//Dibuja un cuadrado y avanza a la Derecha, Izquierda, Arriba y Abajo
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#define ancho 200
#define altura 200
#define profundidad 100
int posx=0, posy=0;
void DibujaCuadrado() {
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(posx, posy,0);
glPopMatrix();
glutSwapBuffers();
}
void TecladoMovimiento(int tecla, int x, int y) {
switch(tecla){
case GLUT_KEY_UP : if(posy<100){posy++;}break;
case GLUT_KEY_DOWN : if(posy>-100){posy--;}break;
case GLUT_KEY_RIGHT : if(posx<100){posx++;}break;
case GLUT_KEY_LEFT : if(posx>-100){posx--;}break; }
glutPostRedisplay();
}
int main(int argc, char** argv) {
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowPosition(100, 0);
glutInitWindowSize(ancho, altura);
glutCreateWindow("Traslacin 2D ");
glOrtho(-(ancho), (ancho), -(altura), (altura), -profundidad, profundidad);
glClearColor(1, 1, 1, 0);
glutDisplayFunc(DibujaCuadrado);
glutSpecialFunc(TecladoMovimiento);
glutMainLoop();
return 0;
}
//Marco Genaro Vilca Mamani 141046
//Dibuja un cuadrado y avanza a la Derecha, Izquierda, Arriba, abajo y cambia de color
#include <windows.h>
#include <iostream>
#include <C:\GLUT\include\GL\glut.h>
//using namespace std;
int ejex=0, ejey=0;
int a,b,c;
void Cuadrado() {
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(ejex, ejey,0);
glBegin(GL_QUADS);
glColor3f(a, b, c);
glVertex2i(100,100);
glVertex2i(-100, 100);
glVertex2i(-100, -100);
glVertex2i(100, -100);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
void TecMovimiento(int tecla, int x, int y) {
switch(tecla){
case GLUT_KEY_UP : if(ejey<100){ejey++; if(ejey==100){a=1; b=0; c=1;}}break;
case GLUT_KEY_DOWN : if(ejey>-100){ejey--; if(ejey==-100) {a=0; b=1; c=1;}}break;
case GLUT_KEY_RIGHT : if(ejex<100){ejex++; if(ejex==100) {a=0.5; b=0; c=1;}}break;
case GLUT_KEY_LEFT : if(ejex>-100){ejex--; if(ejex==-100){a=0; b=1; c=0;}}break; }
glutPostRedisplay();
}
int main(int argc, char** argv) {
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowPosition(100, 0);
glutInitWindowSize(200, 200);
glutCreateWindow("Cuadrado cambia color ");
glOrtho(-200, 200, -200, 200, -100, 100);
glClearColor(1, 1, 1, 0);
glutDisplayFunc(Cuadrado);
glutSpecialFunc(TecMovimiento);
glutMainLoop();
return 0;
}