/
Inicio :: Foros

 F.A.Q.F.A.Q.                  Conéctese para revisar sus mensajesConéctese para revisar sus mensajes   

Error OpenGL

 
      Índice del Foro elrincondelc.com -> Gráficos
Ver tema anterior :: Ver siguiente tema  
AutorMensaje
cazagavilan



Registrado: 14 Abr 2011
Mensajes: 75

MensajePublicado: 28/04/2012 8:22 am
Título: Error OpenGL

Hola!

Tengo este codigo y me dice que los diffuse de:
Código:
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
   glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);
   glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuse2);


no estan definidos y no entiendo por que...

Código:
#include <stdlib.h>
#include <gl\glut.h>
#include "windows.h"

static int spin = 0; // Angulo de giro

// Inicializamos propiedades de material, fuente de luz, modelo de iluminacion y bufer de profundidad
void init(void)
{
   glClearColor(0.0,0.0,0.0,0.0); // Color de fondo
   glShadeModel(GL_SMOOTH); // Como se van a colocar los colores
   // glShadeMode(GL_FLAT)
   glEnable(GL_LIGHTING);// Activando luces
   glEnable(GL_LIGHT0);
   glEnable(GL_LIGHT1);
   glEnable(GL_LIGHT2);
   glEnable(GL_DEPTH_TEST); // Activando buffer de profundidad
}

// ---------------- FUNCION DE DIBUJADO -------------------
void dibujado(void)
{
   GLfloat position0[] = {0.0, 0.0, 1.5, 1.0};
   GLfloat position1[] = {0.0, 1.5, 0.0, 1.0};
   GLfloat position2[] = {1.5, 0.0, 0.0, 1.0};
   GLfloat difusse0[] = {1.0, 0.0, 0.0, 1.0};
   GLfloat difusse1[] = {0.0, 1.0, 0.0, 1.0};
   GLfloat difusse2[] = {0.0, 0.0, 1.0, 1.0};
   GLfloat spec0[] = {1.0, 1.0, 1.0, 1.0};
   GLfloat spec1[] = {1.0, 1.0, 1.0, 1.0};
   GLfloat spec2[] = {1.0, 1.0, 1.0, 1.0};
//---------------- MATERIAL ORO --------------------
   GLfloat gold_amb[] = {0.24725, 0.1995, 0.0745, 1.0};
   GLfloat gold_dif[] = {0.75164, 0.60648, 0.22648, 1.0};
   GLfloat gold_spec[] = {0.628281, 0.555802, 0.366065, 1.0};
   GLfloat gold_shin = 51.2;

   glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
   glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);
   glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuse2);

   glLightfv(GL_LIGHT0, GL_SPECULAR, spec0);
   glLightfv(GL_LIGHT1, GL_SPECULAR, spec1);
   glLightfv(GL_LIGHT2, GL_SPECULAR, spec2);

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glPushMatrix();
   gluLookAt(5, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
   glPushMatrix();
   glRotated((GLdouble) spin, 0.0, 1.0, 0.0);
   glLightfv(GL_LIGHT0,GL_POSITION,position0);

   glTranslated(0.0, 0.0, 1.5);
   glDisable (GL_LIGHTING);

   glColor3f(1.0,0.0,0.0);
   glutWireSphere(0.1,10,10);
   glEnable(GL_LIGHTING);
   glPopMatrix();
   glPushMatrix();
   glRotated((GLdouble) spin*2, 1.0,0.0,0.0);
   glLightfv(GL_LIGHT1, GL_POSITION, position1);

   glTranslated(0.0,1.5,0.0);
   glDisable(GL_LIGHTING);
   glColor3f(0.0,1.0,0.0);
   glutWireSphere(0.1,10,10);
   glEnable(GL_LIGHTING);
   glPopMatrix();
   glPushMatrix();
   glRotated((GLdouble) spin*4, 0.0,0.0,1.0);
   glLightfv(GL_LIGHT2, GL_POSITION, position2);
   glTranslated(1.5,0.0,0.0);
   glDisable(GL_LIGHTING);
   glColor3f(0.0,0.0,1.0);
   glutWireSphere(0.1,10,10);
   glEnable(GL_LIGHTING);
   glPopMatrix();
   glMaterialfv(GL_FRONT, GL_AMBIENT, gold_amb);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, gold_dif);
   glMaterialfv(GL_FRONT, GL_SPECULAR, gold_spec);
   glMaterialf(GL_FRONT, GL_SHININESS, gold_shin);
   glutSolidTeapot(1);
   glPopMatrix();
   glFlush();
}

//-------------------- FUNCION REDIMENSION ------------------
void redimensionar( int ancho, int alto)
{
   glViewport(0,0, (GLsizei) ancho, (GLsizei) alto);
   glMatrixMode(GL_PROJECTION); // Activamos la pila de modelado
   glLoadIdentity();
   gluPerspective(40.0, (GLfloat) ancho/ (GLfloat) alto, 1.0,20.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
}

//-------------------- FUNCION TECLADO ----------------
void teclado(unsigned char key, int x, int y)
{
   switch(key)
   {
      case 27:
         exit(0);
         break;
   }
}

//-----------------------FUNCION ANIMACION -----------------
void animacion()
{
   spin = (spin+1) % 360;
   Sleep(50);
   glutPostRedisplay();
}

//--------------- PRINCIPAL ------------------
int main( int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
   glutInitWindowSize(800, 600);
   glutInitWindowPosition(100,100);
   glutCreateWindow(argv[0]);
   init();
   glutDisplayFunc(dibujado);
   glutReshapeFunc(redimensionar);
   glutIdleFunc(animacion);
   glutKeyboardFunc(teclado);
   glutMainLoop();
   return 0;
}
Volver arriba
daltomi



Registrado: 28 Abr 2007
Mensajes: 335
Ubicación: Argentina

MensajePublicado: 28/04/2012 10:50 am
Título:

Es que diffuse no es lo mismo que difusse.
Además, si quieres un mejor efecto de esfera de luz reemplaza glutWireSphere por glutSolidSphere.

Saludos.
Volver arriba
Dirección AIM
      Índice del Foro elrincondelc.com -> Gráficos
Página 1 de 1Todas las horas están en GMT - 8 Horas

 
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas

(c) ElRincondelC.com

Un proyecto de UrlanHeat.com