/** * Dibuje el triángulo formado por los vértices [(-1,-1,-2), (1,-1,-2), (0,1,-2)]. */ int main(int argc, char* argv[]) { // Crear una ventana de 500x500 pixels: int cw = 500; int ch = 500; cg_init(cw, ch, NULL); // Utilizando la función glGetString, imprima por consola el número de versión de OpenGL que utiliza su sistema. printf("GL Version: %s\n", glGetString(GL_VERSION)); // specifies the red, green, blue, and alpha values used by glClear to clear the color buffers. glClearColor(1.0f, 1.0f, 1.0f, 0.0f); // Actualizar la pantalla: glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glViewport(0,0,cw, ch); glFrustum(-1,1,-1,1,1,1000); glClear(GL_COLOR_BUFFER_BIT); glPointSize(10.0f); glBegin(GL_TRIANGLES); glColor3f(0.3f, 0.8f, 0.1f); glVertex3f(-1.0f, -1.0f, -2.0f); glVertex3f(0.0f,1.0f, -2.0f); glVertex3f(-2.0f, 1.0f, -2.0f); glEnd(); cg_repaint(); int done = 0; while (!done) { SDL_Event event; while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: if (event.key.keysym.sym != SDLK_ESCAPE) break; case SDL_QUIT : done = 1; } } cg_repaint(); } // Liberar recursos: cg_close(); return 0; }
/** * 2. Determinación de superficies ocultas por medio de Z-Buffer y optimización por Backface culling. */ int main(int argc, char* argv[]) { // Crear una ventana de 750x750 pixels. int cw = 750; int ch = 750; cg_init(cw, ch, NULL); // Actualizar la pantalla: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glViewport(0,0,cw, ch); glFrustum(-1,1,-1,1,1,1000); Obj* obj = obj_load("../Models/knight.obj"); float ang = 0.0f; float pitch = 0.0f; float ang_vel = 1.0f; char done = 0; char wireframe = 0; char bfc = 0; glEnable(GL_DEPTH_TEST); char zbuff = 1; unsigned char key_pressed[1024]; memset(key_pressed, 0, 1024); while (!done) { SDL_Event event; while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: key_pressed[event.key.keysym.sym] = 1; if (event.key.keysym.sym == SDLK_z) { zbuff = !zbuff; if(zbuff) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); break; } else if (event.key.keysym.sym == SDLK_b) { bfc = !bfc; if(bfc) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); } else glDisable(GL_CULL_FACE); break; } else if (event.key.keysym.sym == SDLK_m) { wireframe = !wireframe; if(wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); break; } else if (event.key.keysym.sym != SDLK_ESCAPE) break; case SDL_QUIT : done = 1; break; case SDL_KEYUP: key_pressed[event.key.keysym.sym] = 0; } } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -50.0f); glRotatef(pitch, 1.0f, 0.0f, 0.0f); glRotatef(ang, 0.0f, 1.0f, 0.0f); glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); if(key_pressed[SDLK_RIGHT]) ang += ang_vel; if(key_pressed[SDLK_LEFT]) ang -= ang_vel; if(key_pressed[SDLK_UP]) pitch += ang_vel; if(key_pressed[SDLK_DOWN]) pitch -= ang_vel; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); obj_render(obj); cg_repaint(); } // Liberar recursos: obj_free(obj); cg_close(); return 0; }
int main(int argc, char* argv[]) { int cw = 750; int ch = 750; cg_init(cw, ch, NULL); glClearColor(0,0,1,1); // Actualizar la pantalla: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glViewport(0,0,cw, ch); glFrustum(-1,1,-1,1,1,1000); glEnable(GL_LIGHTING); // glEnable(GL_NORMALIZE); float l0[] = {1.0f,1.0f,1.0f,1.0f}; float la[] = {0.10f,0.10f,0.10f,1.0f}; float l0p[]= {1.0f,1.0f,1.0f,1.0f}; float ls[] = {1.0f,1.0f,1.0f,1.0f}; glLightfv(GL_LIGHT0, GL_AMBIENT, la); glLightfv(GL_LIGHT0, GL_DIFFUSE, l0); glLightfv(GL_LIGHT0, GL_POSITION, l0p); glLightfv(GL_LIGHT0, GL_SPECULAR, ls); glEnable(GL_LIGHT0); float cyan[] = {1.0f, 1.0f, 1.0f, 1.f}; glMaterialfv(GL_FRONT, GL_DIFFUSE, cyan); glMaterialfv(GL_FRONT, GL_SPECULAR, ls); glMateriali(GL_FRONT, GL_SHININESS, 16); float ang = 0.0f; float pitch = 0.0f; float ang_vel = 1.0f; char done = 0; char wireframe = 0; char bfc = 0; glEnable(GL_DEPTH_TEST); char zbuff = 1; unsigned char key_pressed[1024]; memset(key_pressed, 0, 1024); char use_shader = 0; char specular = 0; Shader gouraud = shader_new("shaders/gouraud_vp.glsl", "shaders/gouraud_fp.glsl"); GLint uniform_especular = shader_get_unif_loc(gouraud, "especular"); GLint uniform_tex = shader_get_unif_loc(gouraud, "tex"); Obj* objPtr ; int example = atoi(argv[1]); if (example==1 || example==3) objPtr = obj_load("../Models/knight_texturas.obj"); else if (example==2) objPtr = obj_load("../Models/box_texturas.obj"); //Cargo la imagen de disco usando SDL_image SDL_Surface* surface; // = IMG_Load("../Models/knight.png"); if (example==1 ) surface = IMG_Load("../Models/knight.png"); else if (example==2) surface = IMG_Load("../Models/box.jpg"); else if (example==3) surface = IMG_Load("../Models/knight_good.png"); // Obj* objPtr = obj_load("../Models/knight_texturas.obj"); // Obj* objPtr = obj_load("../Models/box_texturas.obj"); //Cargo la imagen de disco usando SDL_image // SDL_Surface* surface = IMG_Load("../Models/knight.png"); // SDL_Surface* surface = IMG_Load("../Models/knight_good.png"); // SDL_Surface* surface = IMG_Load("../Models/box.jpg"); if (surface==NULL) { //Si falla la carga de la imagen, despliego el mensaje de error correspondiente y termino el programa. printf("Error: \"%s\"\n", SDL_GetError()); return 1; } GLuint texture; //Creo un espacio para alojar una textura en memoria de video glGenTextures(1,&texture); //Activo la textura nro 0 glActiveTexture(GL_TEXTURE0); //Habilito la carga para la textura recien creada glBindTexture(GL_TEXTURE_2D,texture); //Cargo los datos de la imagen en la textura. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_RGB,GL_UNSIGNED_BYTE, surface->pixels); //Luego de copiada la imagen a memoria de video, puedo liberarla sin problemas SDL_FreeSurface(surface); //Seteo el filtro a usar cuando se mapea la textura a una superficie mas chica (GL_LINEAR = filtro bilineal) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //Seteo el filtro a usar cuando se mapea la textura a una superficie mas grande (GL_LINEAR = filtro bilineal) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //Seteo el comportamiento cuando encuentro coordenadas de textura fuera del rango [0,1] //GL_REPEAT es el comportamiento por defecto. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); while (!done) { SDL_Event event; while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: key_pressed[event.key.keysym.sym] = 1; if (event.key.keysym.sym == SDLK_p) { use_shader = !use_shader; break; } else if (event.key.keysym.sym == SDLK_s) { specular = !specular; break; } else if (event.key.keysym.sym == SDLK_z) { zbuff = !zbuff; if(zbuff) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); break; } else if (event.key.keysym.sym == SDLK_m) { wireframe = !wireframe; if(wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); break; } else if (event.key.keysym.sym == SDLK_b) { bfc = !bfc; if(bfc) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); } else glDisable(GL_CULL_FACE); break; } else if (event.key.keysym.sym != SDLK_ESCAPE) break; case SDL_QUIT : done = 1; break; case SDL_KEYUP: key_pressed[event.key.keysym.sym] = 0; } } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (example==1 || example==3) glTranslatef(0.0f, 0.0f, -50.0f); else if (example==2) glTranslatef(0.0f, 0.0f, -2.0f); // glTranslatef(0.0f, 0.0f, -50.0f); // glTranslatef(0.0f, 0.0f, -2.0f); glRotatef(pitch, 1.0f, 0.0f, 0.0f); glRotatef(ang, 0.0f, 1.0f, 0.0f); glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); if(key_pressed[SDLK_RIGHT]) ang += ang_vel; if(key_pressed[SDLK_LEFT]) ang -= ang_vel; if(key_pressed[SDLK_UP]) pitch += ang_vel; if(key_pressed[SDLK_DOWN]) pitch -= ang_vel; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //Informo a OpenGL que para todas las operaciones a continuaci�n utilice las texturas 2D cargadas glEnable(GL_TEXTURE_2D); if(use_shader) { shader_use(gouraud); glUniform1i(uniform_especular, specular); //Le digo al shader que el sampler2D de nombre "tex" se corresponde con GL_TEXTURE0 //que es donde cargu� mi textura. glUniform1i(uniform_tex, 0); //Luego asocio la textura con el id "texture" glBindTexture(GL_TEXTURE_2D,texture); obj_render2(objPtr); shader_stop(gouraud); } else { glBindTexture(GL_TEXTURE_2D,texture); obj_render2(objPtr); } cg_repaint(); } // while // Liberar recursos: obj_free(objPtr); shader_free(gouraud); glDeleteTextures(1,&texture); cg_close(); return 0; }
int main(int argc, char* argv[]) { // Crear una ventana de 500x500 pixels: int cw = 640; int ch = 480; cg_init(cw, ch, NULL); init_cggl(cw, ch); Model* model = model_new("knight"); int done = 0; while (!done) { SDL_Event event; while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_ESCAPE: done = 1; break; case SDLK_UP: rot_speed += 5.0f; break; case SDLK_DOWN: rot_speed -= 5.0f; break; case SDLK_RIGHT: frame += 1; if (frame >= model->md2_model->header.num_frames) frame = 0; break; case SDLK_LEFT: frame -= 1; if (frame < 0) frame = model->md2_model->header.num_frames - 1; break; case SDLK_m: if (mode == CG_TRIANGLES) mode = CG_LINES; else mode = CG_TRIANGLES; break; default: break; } break; case SDL_QUIT : done = 1; break; default: break; } } cg_clear(); paint_model(model); // Actualizar la pantalla: cg_repaint(); double delta = get_delta(); rot_x += rot_speed*delta; rot_y += rot_speed*delta; rot_z += rot_speed*delta; } // Liberar recursos: model_free(model); cgCloseCGGL(); cg_close(); return 0; }
/** * Dibuje el modelo definido por el archivo knight.obj 1 disponible en webasignatura. El * formato del archivo OBJ se encuentra definido en el anexo I de este documento. Cada * triángulo del modelo debe ser dibujado usando un tono de gris randómico en sus vértices. * Nota: Para parsear el archivo obj, puede utilizar las funciones fgets (definida en stdio.h), * strcmp, strtok (definidas en string.h), atof y atoi (definidas en stdlib.h). */ int main(int argc, char* argv[]) { // Crear una ventana de 500x500 pixels: int cw = 900; int ch = 900; cg_init(cw, ch, NULL); #ifdef WIN32 freopen( "CON", "w", stdout ); freopen( "CON", "w", stderr ); #endif printf("GL Version: %s\n", glGetString(GL_VERSION)); // Actualizar la pantalla: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glViewport(0,0,cw, ch); glFrustum(-1,1,-1,1,1,1000); //Habilito la iluminación del pipeline estático de OpenGL. glEnable(GL_LIGHTING); //Creo un Vec4 para representar el color (RGBA) y la Intensidad de la luz. //P.e.: (1,1,1,1) = Luz Blanca intensa, (0.5,0.5,0.5,1) = Luz blanca tenue, (0.5,0,0,1) = Luz roja tenue. float l0[] = {1.0f,1.0f,1.0f,1.0f}; //Creo un Vec4 para representar el color (RGBA) y la intensidad de la iluminación ambiente de la luz float la[] = {0.10f,0.10f,0.10f,1.0f}; //Creo un Vec4 para representar la posición de la luz. El cuarto elemento representa el tipo de luz: 1=puntual, 0=direccional float l0p[]= {1.0f,1.0f,1.0f,1.0f}; //Creo un Vec4 para representar el color (RGBA) y la intensidad especular de la luz float ls[] = {1.0f,1.0f,1.0f,1.0f}; //Cargo la intesidad ambiente de la Luz Nro 0 del pipline estático. glLightfv(GL_LIGHT0, GL_AMBIENT, la); //Cargo la intesidad difusa de la Luz Nro 0 del pipline estático. glLightfv(GL_LIGHT0, GL_DIFFUSE, l0); //Cargo la posición de la Luz Nro 0 del pipline estático. glLightfv(GL_LIGHT0, GL_POSITION, l0p); //Cargo la intesidad especular de la Luz Nro 0 del pipline estático. glLightfv(GL_LIGHT0, GL_SPECULAR, ls); //Prendo la Luz nro 0 del pipline estático. Hay 8 luces, representadas por las constantes GL_LIGHT0 a GL_LIGHT7 //Por defecto está todas apagadas al inicio. glEnable(GL_LIGHT0); //Creo un Vec4 para representar el color difuso(RGBA) del material del objeto a dibujar. float cyan[] = {1.0f, 0.0f, 1.0f, 1.f}; //Cargo el color difuso del la cara de adelante del objeto a dibujar. glMaterialfv(GL_FRONT, GL_DIFFUSE, cyan); //Cargo el color especular del la cara de adelante del objeto a dibujar. glMaterialfv(GL_FRONT, GL_SPECULAR, ls); //Cargo el coeficiente especular de la cara de adelante del objeto a dibujar. glMateriali(GL_FRONT, GL_SHININESS, 32); float ang = 0.0f; float pitch = 0.0f; float ang_vel = 1.0f; Obj* obj = obj_load("Models/knight.obj"); printf("num of faces %d\n", obj->numfaces); // delete printf("num of vertices %d\n", obj->numverts); // delete char done = 0; char wireframe = 0; char bfc = 0; glEnable(GL_DEPTH_TEST); char zbuff = 1; unsigned char key_pressed[1024]; memset(key_pressed, 0, 1024); while (!done) { SDL_Event event; while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: key_pressed[event.key.keysym.sym] = 1; if (event.key.keysym.sym == SDLK_z) { zbuff = !zbuff; if(zbuff) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); break; } else if (event.key.keysym.sym == SDLK_m) { wireframe = !wireframe; if(wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); break; } else if (event.key.keysym.sym == SDLK_b) { bfc = !bfc; if(bfc) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); } else glDisable(GL_CULL_FACE); break; } else if (event.key.keysym.sym != SDLK_ESCAPE) break; case SDL_QUIT : done = 1;break; case SDL_KEYUP: key_pressed[event.key.keysym.sym] = 0; } } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -50.0f); glRotatef(pitch, 1.0f, 0.0f, 0.0f); glRotatef(ang, 0.0f, 1.0f, 0.0f); glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); if(key_pressed[SDLK_RIGHT]) ang += ang_vel; if(key_pressed[SDLK_LEFT]) ang -= ang_vel; if(key_pressed[SDLK_UP]) pitch += ang_vel; if(key_pressed[SDLK_DOWN]) pitch -= ang_vel; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); obj_render(obj); cg_repaint(); } obj_free(obj); // Liberar recursos: cg_close(); // Ejemplo del modulo de Manejo de Memoria (MM): int* pint = (int *)cg_malloc(10*sizeof(int)); printf("pint is a pointer: %p\n", pint); cg_free(pint); // olvidarse de liberar este objeto produce un mensaje return 0; }
/** * http://cse.csusb.edu/tongyu/courses/cs420/notes/lighting.php * Sombreado por medio de la técnica Gouraud Shading. */ int main(int argc, char* argv[]) { // Crear una ventana de 750x750 pixels. int cw = 750; int ch = 750; cg_init(cw, ch, NULL); // Actualizar la pantalla: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glViewport(0,0,cw, ch); glFrustum(-1,1,-1,1,1,1000); //Habilito la iluminación del pipeline estático de OpenGL. glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); // GL_LIGHT0 Vec4 *vec4La0 = vec4Contructor(0.10f, 0.10f, 0.10f, 1.0f); Vec4 *vec4Ld0 = vec4Contructor(1.0f, 1.0f, 1.0f, 1.0f); Vec4 *vec4Ls0 = vec4Contructor(1.0f, 1.0f, 1.0f, 1.0f); Vec4 *vec4Lp0 = vec4Contructor(1.0f, 1.0f, 1.0f, 0.0f); loadLight(GL_LIGHT0, vec4La0, vec4Ld0, vec4Lp0, vec4Ls0); // GL_LIGHT1 Vec4 *vec4La1 = vec4Contructor(0.5f,0.5f,0.5f,1.0f); Vec4 *vec4Ld1 = vec4Contructor(0.5f, 0.3f, 0.2f, 1.0f); Vec4 *vec4Ls1 = vec4Contructor(1.0f,1.0f,1.0f,1.0f); Vec4 *vec4Lp1 = vec4Contructor(1.0f, 1.0f, 1.0f, 0.0f); loadLight(GL_LIGHT1, vec4La1, vec4Ld1, vec4Lp1, vec4Ls1); // GLfloat spot_direction[] = { -1.0, -1.0, 0.0 }; // glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5); // glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.5); // glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.2); // glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0); // glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction); // glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0); // GL_LIGHT2 Vec4 *vec4La2 = vec4Contructor( 0.2f, 0.2f, 0.2f, 1.0f); Vec4 *vec4Ld2 = vec4Contructor(0.8f, 0.8f, 0.8, 1.0f ); Vec4 *vec4Lp2 = vec4Contructor(-1.5f, 1.0f, -4.0f, 1.0f ); Vec4 *vec4Ls2 = vec4Contructor(0.5f, 0.5f, 0.5f, 1.0f ); loadLight(GL_LIGHT2, vec4La2, vec4Ld2, vec4Lp2, vec4Ls2); // TODO, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7 Obj* obj = obj_load("../Models/knight.obj"); float ang = 0.0f; float pitch = 0.0f; float ang_vel = 1.0f; char done = 0; char wireframe = 0; char gourandShading = 0; char bfc = 0; char zbuff = 1; char enableLight0 = 0; char enableLight1 = 0; char enableLight2 = 0; char enableLight3 = 0; char enableLight4 = 0; char enableLight5 = 0; char enableLight6 = 0; char enableLight7 = 0; unsigned char key_pressed[1024]; memset(key_pressed, 0, 1024); while (!done) { SDL_Event event; while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: key_pressed[event.key.keysym.sym] = 1; if (event.key.keysym.sym == SDLK_z) { zbuff = !zbuff; if(zbuff) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); break; } else if (event.key.keysym.sym == SDLK_b) { bfc = !bfc; if(bfc) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); } else glDisable(GL_CULL_FACE); break; } else if (event.key.keysym.sym == SDLK_m) { wireframe = !wireframe; if(wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); break; } else if (event.key.keysym.sym == SDLK_g) { gourandShading = !gourandShading; if(gourandShading) glShadeModel(GL_FLAT); else glShadeModel(GL_SMOOTH); break; } else if (event.key.keysym.sym == SDLK_0) { enableLight0 = !enableLight0; if(enableLight0) glEnable(GL_LIGHT0); else glDisable(GL_LIGHT0); break; } else if (event.key.keysym.sym == SDLK_1) { enableLight1 = !enableLight1; if(enableLight1) glEnable(GL_LIGHT1); else glDisable(GL_LIGHT1); break; } else if (event.key.keysym.sym == SDLK_2) { enableLight2 = !enableLight2; if(enableLight2) glEnable(GL_LIGHT2); else glDisable(GL_LIGHT2); break; } else if (event.key.keysym.sym == SDLK_3) { enableLight3 = !enableLight3; if(enableLight3) glEnable(GL_LIGHT3); else glDisable(GL_LIGHT3); break; } else if (event.key.keysym.sym == SDLK_4) { enableLight4 = !enableLight4; if(enableLight4) glEnable(GL_LIGHT4); else glDisable(GL_LIGHT4); break; } else if (event.key.keysym.sym == SDLK_5) { enableLight5 = !enableLight5; if(enableLight5) glEnable(GL_LIGHT5); else glDisable(GL_LIGHT5); break; } else if (event.key.keysym.sym == SDLK_6) { enableLight6 = !enableLight6; if(enableLight6) glEnable(GL_LIGHT6); else glDisable(GL_LIGHT6); break; } else if (event.key.keysym.sym == SDLK_7) { enableLight7 = !enableLight7; if(enableLight7) glEnable(GL_LIGHT7); else glDisable(GL_LIGHT7); break; } else if (event.key.keysym.sym != SDLK_ESCAPE) break; case SDL_QUIT : done = 1; break; case SDL_KEYUP: key_pressed[event.key.keysym.sym] = 0; } } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -50.0f); glRotatef(pitch, 1.0f, 0.0f, 0.0f); glRotatef(ang, 0.0f, 1.0f, 0.0f); glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); if(key_pressed[SDLK_RIGHT]) ang += ang_vel; if(key_pressed[SDLK_LEFT]) ang -= ang_vel; if(key_pressed[SDLK_UP]) pitch += ang_vel; if(key_pressed[SDLK_DOWN]) pitch -= ang_vel; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); obj_render(obj); cg_repaint(); } // Liberar recursos: obj_free(obj); cg_close(); return 0; }