elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  OpenGL ( Error Luz ). No apunta a donde deberia.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: OpenGL ( Error Luz ). No apunta a donde deberia.  (Leído 1,725 veces)
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
OpenGL ( Error Luz ). No apunta a donde deberia.
« en: 23 Julio 2011, 09:52 am »

.
Estoy realizando pruebas con OpenGL+C ( No me recomienden otro por que antes de cambiarme quiero solucionar este problema ), y estoy con las luces. mi problema radica en que la luz no apunta a donde deberia de apunter ( Algo asi como un Eje ), ya que se mueve emisor d ela luz a otra coordenada y obviamente el eje (en este caso esta representado con una espera solida) deberia estar SIEMPRE iluminado, pero no es asi...

alguien me puede ayudar?

Código
  1.  
  2. #include <windows.h>
  3. #include "include/OpenGL/CGL.h"
  4.  
  5. // Posicion de la luz X, Y, Y, {el 4to elemento indica si es en una posicion infinita 1=NO, 0=SI}
  6. float fposition[4] = {0.0f, 0.0f, 1.0f, 1.0};
  7.  
  8. void drawZones()
  9. {
  10.    ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // Borramos la pantalla y el buffer de profundidad
  11.  
  12.    ::glLoadIdentity();
  13.    //  Camara.
  14.    ::gluLookAt( 0, 0, 5,               //  Posicon X, Y, Z.
  15.                 0, 0, -1,              //  Hacia donde vemos X, Y, Z.
  16.                 0.0f, 1.0f, 0.0f );    // Cielo X, Y, Z.
  17.  
  18.    GLfloat fDirection[] = {0.0,0.0,-1.0}; // Dirrecion hacia adonde apuntamos.
  19.    //Configuramos nuestra Luz.
  20.    ::glEnable ( GL_LIGHT0 );
  21.    ::glLightfv ( GL_LIGHT0, GL_POSITION, fposition );
  22.    ::glLightfv ( GL_LIGHT0, GL_SPOT_DIRECTION, fDirection);
  23.    ::glLightf ( GL_LIGHT0, GL_SPOT_CUTOFF, 5 );
  24.  
  25.    ::glutSolidSphere(100, 4000, 4000); // Esfero que nos representara las paredes.
  26.  
  27.    //  Las siguiente son las esferas donde esta la luz.
  28.    //  Posicion del emisor de luz.
  29.    ::glPushMatrix ();
  30.        ::glColor3f ( 1.0f , 0.0f , 0.0f );
  31.        ::glTranslatef ( fposition[0],fposition[1],fposition[2] );
  32.        ::glutWireSphere ( 0.2, 50 , 50 );
  33.    ::glPopMatrix ();
  34.  
  35.    //  Posicion Destino hacia donde se emite la luz.
  36.    ::glPushMatrix();
  37.        ::glColor3f( 0.0f , 0.0f , 1.0f );
  38.        ::glTranslatef( fDirection[0],fDirection[1],fDirection[2] );
  39.        ::glutSolidSphere( 0.2, 50 , 50 );
  40.    ::glPopMatrix();
  41.    //  Mostramos.
  42.    ::glutSwapBuffers();
  43. }
  44.  
  45. void keyBoardSFunc(int key, int x, int y)
  46. {
  47.    if (key == GLUT_KEY_LEFT)
  48.        fposition[0] -= 0.1;
  49.    if (key == GLUT_KEY_RIGHT)
  50.        fposition[0] += 0.1;
  51.    if (key == GLUT_KEY_UP)
  52.        fposition[1] -= 0.1;;
  53.    if (key == GLUT_KEY_DOWN)
  54.        fposition[1] += 0.1;
  55. }
  56. void timer( int val ) {
  57.    ::glutTimerFunc       ( 10 , timer,  0);
  58.    ::glutPostRedisplay   (  );
  59. }
  60.  
  61. int main()
  62. {
  63.    CGL oWindow;
  64.  
  65.    oWindow.creaVentanaGL ( "Hola Mundo desde OpenGL" , 1024 , 726 , 0 , 0 , false );
  66.    ::glutDisplayFunc ( drawZones );
  67.    ::glutSpecialFunc ( keyBoardSFunc );
  68.    ::glutTimerFunc ( 10, timer, 0 );
  69.    ::glutMainLoop ();
  70.  
  71.    return EXIT_SUCCESS;
  72. }
  73.  
  74.  

CGL.cpp

Código
  1.  
  2.  
  3. #include "OpenGL/cgl.h"
  4.  
  5. //---------------------------------------------------------------
  6. // Nombre: Constructor
  7. // Descripcion: Constructor de la clase. Inicializa las variables
  8. // Parametros: Ninguno
  9. //---------------------------------------------------------------
  10. CGL::CGL()
  11. {
  12.    int_Win = 0;
  13. }
  14.  
  15. //---------------------------------------------------------------
  16. // Nombre: Destructor
  17. // Descripcion: Destructor de la clase
  18. // Parametros: Ninguno
  19. //---------------------------------------------------------------
  20. CGL::~CGL()
  21. {
  22.    eliminaVentanaGL();
  23. }
  24.  
  25. //---------------------------------------------------------------
  26. // Nombre: inicializaEscenaGL
  27. // Descripcion: Inicializa los parametros iniciales de la escena
  28. // Parametros:
  29. //        Glsizei ancho: Ancho de la escena
  30. //        Glsizei alto: Alto de la escena
  31. //---------------------------------------------------------------
  32. void CGL::inicializaEscenaGL(GLsizei ancho, GLsizei alto)
  33. {
  34.    if ( alto <= 0 )                                                                    // Previene de la división entre 0
  35.    {
  36.        alto=1;                                                                         // Establece la altura = 1
  37.    }
  38.    ::glViewport            ( 0 , 0 , ancho , alto );                                   // Resetea el actual puerto de visión (ViewPort)
  39.    ::glMatrixMode          ( GL_PROJECTION );                                          // Selecciona la matriz de proyección
  40.    ::glLoadIdentity        (  );                                                       // Resetea la matriz de proyección
  41.  
  42.    ::gluPerspective        ( 45.0f , (GLfloat)ancho/(GLfloat)alto , 1.0f , 300000.0f );  // Calcula el Aspect Ratio de la ventana
  43.  
  44.    ::glMatrixMode          ( GL_MODELVIEW );                                           // Selecciona la matriz de modelado
  45.    ::glLoadIdentity        (  );                                                       // Resetea la matriz de modelado
  46. }
  47.  
  48. //---------------------------------------------------------------
  49. // Nombre: iniGL
  50. // Descripcion: Inicializa los valores iniciales de OGL
  51. // Parametros: Ninguno
  52. //---------------------------------------------------------------
  53. bool CGL::iniGL(void)
  54. {
  55.    GLfloat ambientLight[]  = { 0.1f, 0.1f, 0.1f, 1.0f };
  56.    ::glShadeModel          ( GL_SMOOTH );                                  // Activa sombreado suave (Smooth Shading)
  57.    ::glClearDepth          ( 1.0f );                                       // Depth Buffer Setup
  58.    ::glEnable              ( GL_DEPTH_TEST );                              // Activa Z-Buffer
  59.    ::glDepthFunc           ( GL_LEQUAL );                                  // El tipo de Depth Testing que se va a realizar
  60.    ::glHint                ( GL_PERSPECTIVE_CORRECTION_HINT , GL_NICEST ); // Muy buena correción de perspectiva
  61.    ::glEnable              ( GL_TEXTURE_2D );                              // Activa mapeado de texturas
  62.    ::glColorMaterial       ( GL_FRONT , GL_AMBIENT_AND_DIFFUSE );
  63.    ::glClearColor          ( 0.0f , 0.0f , 0.0f , 1.0f );
  64.  
  65.    ::glLightModeli         ( GL_LIGHT_MODEL_TWO_SIDE , 1 );                // habilita ambas caras (FRONT-iluminada & BACK-oscurecida) de los poligonos
  66.    ::glLightModelfv        ( GL_LIGHT_MODEL_AMBIENT , ambientLight );      // luz ambiental de toda la escena
  67.    ::glEnable              ( GL_COLOR_MATERIAL);                           // habilita el color para los materiales (poligonos rellenos)
  68.    ::glEnable              ( GL_LIGHTING );
  69.  
  70.    return true;
  71. }
  72.  
  73. //---------------------------------------------------------------
  74. // Nombre: eliminaVentanaGL
  75. // Descripcion: Destruye toda la información sobre la ventana GL
  76. // Parametros: Ninguno
  77. //---------------------------------------------------------------
  78. void CGL::eliminaVentanaGL(void)
  79. {
  80.    ::glutDestroyWindow(  this->int_Win );
  81.    this->int_Win = 0;
  82. }
  83.  
  84. //---------------------------------------------------------------
  85. // Nombre: CrearVentanaGL
  86. // Descripcion: Crea una ventana OGL
  87. // Parametros:
  88. //            char* Titulo: Titulo de la ventana
  89. //            int ancho: Ancho de la ventana o en modo pantalla completa
  90. //            int alto: Alto de la ventana o en modo pantalla completa
  91. //            bool fullscreen: Usar pantalla completa (TRUE) o ventana (FALSE)
  92. //---------------------------------------------------------------
  93. bool CGL::creaVentanaGL(const char* Titulo, GLsizei ancho, GLsizei alto, GLsizei x, GLsizei y, bool fullscreen)
  94. {
  95.    if ( x < 0 ) { x=0; }
  96.    if ( y < 0 ) { y=0; }
  97.  
  98.    ::glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGBA );
  99.    ::glutInitWindowPosition ( x , y );
  100.    ::glutInitWindowSize ( ancho , alto );
  101.  
  102.    this->int_Win = ::glutCreateWindow( Titulo );
  103.  
  104.    ::glutSetWindow( this->int_Win );
  105.  
  106.    if ( fullscreen == true )
  107.        ::glutFullScreen();
  108.  
  109.    inicializaEscenaGL ( ancho , alto );        // Inicializamos la escena en perspectiva GL
  110.  
  111.    if ( !iniGL() ) {
  112.        eliminaVentanaGL();
  113.        return false;
  114.    }
  115.  
  116.    return true;
  117. }
  118.  
  119.  

CGL.h
Código
  1.  
  2. #ifndef _cGL_H_
  3. #define _cGL_H_
  4.  
  5. // INCLUDES //////////////////////////////////////
  6. #include <windows.h>            // Archivo cabecera para Windows
  7. #include <GL/glut.h>
  8.  
  9. class CGL
  10. {
  11.    public:
  12.        CGL                                         ();
  13.        virtual         ~CGL                        ();
  14.        bool            creaVentanaGL               (const char* Titulo, GLsizei ancho, GLsizei alto, GLsizei x, GLsizei y, bool fullscreen);
  15.        void            inicializaEscenaGL          (GLsizei ancho, GLsizei alto);      // Cambia de tamaño e inicializa la ventana GL
  16.        void            eliminaVentanaGL            (void);                           // Elimina la ventana
  17.        int             int_Win;
  18.        void            inilight                    (GLfloat ligt[]);
  19.    private:
  20.        bool            iniGL                       (void);                        // Todas la inicializaciónes de OpenGl vienen aqui
  21. };
  22.  
  23. #endif
  24.  
  25.  

Temibles Lunas!¡


En línea

The Dark Shadow is my passion.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
donde esta el error ?
Java
darkxxx 3 2,639 Último mensaje 10 Junio 2007, 23:41 pm
por coolfrog
Error OpenGL.
Programación C/C++
BlackZeroX 3 3,882 Último mensaje 5 Marzo 2011, 20:57 pm
por BlackZeroX
¿Dónde apunta el SEH handler con SAFESEH?
Bugs y Exploits
Lodos76 1 2,424 Último mensaje 21 Julio 2014, 23:15 pm
por MCKSys Argentina
Donde conseguir un tutorial de OpenGL 4.1
Programación C/C++
Seyro97 0 1,221 Último mensaje 15 Octubre 2014, 23:02 pm
por Seyro97
(Ayuda con OpenGL) La función 'SetPixelFormat' me da un error
Programación C/C++
Seyro97 0 1,529 Último mensaje 8 Junio 2015, 05:05 am
por Seyro97
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines