You are on page 1of 7

#include <Windows.

h> //profe en mi caso yio tengo el Glut en la sgte direccion


#include <C:\GLUT\include\GL\glut.h> //direccion de la izquierda
#ifdef __APPLE__
#else
#include <GL/glut.h>
#endif

#include <stdlib.h>

#include <iostream>

static double t;
static double a = 0;

static float xx = 0.0, yy = 0.0, zz = -3.0;


static GLfloat theta[] = {0.0,0.0,0.0};
static int b = 0;
static int c = 0;
static int d = 1;
static GLint eje = 2;
static int slices = 20;
static int stacks = 20;
GLdouble radio=0.2;

const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };


const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };


const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

static int Ventana;


static int menu_id;
static int submenu1, submenu2, submenu3, submenu4, submenu5, submenu6, submenu7,
submenu8;
static int value = 0;
void menu(int num){
if(num == 0){
glutDestroyWindow(Ventana);
exit(0);
}else{
value = num;
}
glutPostRedisplay();
}
void createMenu(void){
submenu1 = glutCreateMenu(menu);
glutAddMenuEntry("Rojo", 1);
glutAddMenuEntry("Verde", 2);
glutAddMenuEntry("Azul", 3);
glutAddMenuEntry("Amarillo", 4);
glutAddMenuEntry("Morado", 5);
glutAddMenuEntry("Anaranjado", 6);
glutAddMenuEntry("Negro", 7);
glutAddMenuEntry("Celeste", 8);

submenu2 = glutCreateMenu(menu);
glutAddMenuEntry("Rojo", 9);
glutAddMenuEntry("Verde", 10);
glutAddMenuEntry("Azul", 11);
glutAddMenuEntry("Amarillo", 12);
glutAddMenuEntry("Morado", 13);
glutAddMenuEntry("Anaranjado", 14);
glutAddMenuEntry("Blanco", 15);
glutAddMenuEntry("Celeste", 16);

submenu3 = glutCreateMenu(menu);
glutAddMenuEntry("red", 17);

submenu4 = glutCreateMenu(menu);
glutAddMenuEntry("Salir", 18);

glutAddSubMenu("Color de la esfera", submenu1);


glutAddSubMenu("Color del tablero", submenu2);
glutAddSubMenu("Esfera solida", submenu3);
glutAttachMenu(GLUT_LEFT_BUTTON);
}

static void resize(int width, int height){


const float ar = (float) width / (float) height;

glViewport(0, 0, width, height);


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(25.0,ar,0.1,30.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}

static void key(unsigned char key, int x, int y){


switch (key){
case 27 :
case 'q':
exit(0);
break;

case '+':
slices++;
stacks++;
break;

case '-':
if (slices>3 && stacks>3){
slices--;
stacks--;
}
break;

case 'd':
if(xx <0.7){
xx = xx +0.03;
d = -1;
c = -1;
b = 0;
a = t*90.0;
// a = 0.0;
}

break;

case 'a':
if(xx >- 0.7){
xx = xx - 0.03;
d = 1;
c = 1;
b= 0;
a = t*90.0;
// a = t*90.0;
// a = 0.0;
}
break;

case 's':
if(yy >-0.33){
yy = yy -0.03;
zz = zz + 0.04;
b = 1;
d = 1;
c= 0;
a = t*90.0;
// a = 0.0;
}
break;

case 'w':
if(yy<0.65){
yy = yy +0.03;
zz = zz - 0.04;
b= -1;
d = -1;
c = 0;
a = t*90.0;
/// a = 0.0;
}

break;
}

glutPostRedisplay();
}

static void idle(void){


glutPostRedisplay();
}

void Cubo(){ //se formar�n varios cubos para formar el tablero


glBegin(GL_POLYGON);
glVertex3f(-0.99,0.2,-0.99);
glVertex3f(-0.99,0.2,-0.79);
glVertex3f(-0.79,0.2,-0.79);
glVertex3f(-0.79,0.2,-0.99);
glEnd();
}

void casillaAzul(){
glColor3f(0.0,0.0,1.0);
Cubo();

void casillaNegra(){
glColor3f(0.0,0.0,0.0);
Cubo();

void tablero(){
glColor3f(0.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex3f(1.02,0.2,-1.0);
glVertex3f(1.02,0.2,1.01);
glVertex3f(-1.0,0.2,1.01);
glVertex3f(-1.0,0.2,-1.0);
glEnd();
casillaNegra();
double traslacion1=0.0;
for(int j=0;j<10;j++){
if(j%2==0){
casillaNegra();
for(int i=0;i<9;i++){
if(i%2==0){
glTranslatef(0.2,0.0,0.0);
casillaAzul();
}
else{
glTranslatef(0.2,0.0,0.0);
casillaNegra();
}
traslacion1+=0.2;
}
}
else{
casillaAzul();
for(int i=0;i<9;i++){
if(i%2==0){
glTranslatef(0.2,0.0,0.0);
casillaNegra();
}
else{
glTranslatef(0.2,0.0,0.0);
casillaAzul();
}
traslacion1+=0.2;
}
}
glTranslatef(-traslacion1,0.0,0.0);
traslacion1=0.0;
glTranslatef(0.0,0.0,0.2);
}
}

void relieve(){
glBegin(GL_LINE_LOOP);
glVertex3f(-1.0,0.05,-1.0);
glVertex3f(-1.0,0.05,1);
glVertex3f(1.0,0.05,1.0);
glVertex3f(1.0,0.05,-1.0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(-1.0,0.05,1.0);
glVertex3f(-1.0,-0.05,1.0);
glVertex3f(1.0,-0.05,1.0);
glVertex3f(1.0,0.05,1.0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(1.0,0.05,-1.0);
glVertex3f(1.0,0.05,1.0);
glVertex3f(1.0,-0.05,1.0);
glVertex3f(1.0,-0.05,-1.0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(-1.0,0.05,-1.0);
glVertex3f(1.0,0.05,-1.0);
glVertex3f(1.0,-0.05,-1.0);
glVertex3f(-1.0,-0.05,-1.0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(-1.0,0.05,1.0);
glVertex3f(-1.0,0.05,-1.0);
glVertex3f(-1.0,-0.05,-1.0);
glVertex3f(-1.0,-0.05,1.0);
glEnd();

void graficos(){
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
// glEnable(GL_LIGHTING);

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);


glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);


glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
}

static void display(void){

t = glutGet(GLUT_ELAPSED_TIME) / 1200.0;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1,0,1);

glPushMatrix();
glTranslated(xx,yy,zz);
glRotated(60,1,0,0);
glRotated(a,b,c,d);
glutWireSphere(radio,slices,stacks);
glPopMatrix();

glPushMatrix();
glLoadIdentity();
gluLookAt(0,3,3,0,1,1,0,1,0);
glColor3f(0.165, 0.165, 0.165);
relieve();
tablero();
glPopMatrix();

if(value == 1){
glColor3d(1,1,1);
//glColor3d(1,0,1);

}else if(value == 2){

}else if(value == 3){

}else if(value == 4){

glutSwapBuffers();
}

int main(int argc, char *argv[]){

glutInit(&argc, argv);
glutInitWindowSize(700,480);
glutInitWindowPosition(50,50);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

glutCreateWindow("TABLERO CON ESFERA INCLUIDA - PC 02 COMPUTACION VISUAL");

//window = glutCreateWindow("Project 1");


createMenu();
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);
glClearColor(1,1,1,1);

graficos();

glutMainLoop();

return EXIT_SUCCESS;
}

You might also like