[HOpenGL] lighting doesn't work

Patrick Scheibe mai99dnn at studserv.uni-leipzig.de
Wed Jan 12 19:50:05 EST 2005


Hi,

These days I got the wxHaskell-OpenGL thing running. Tonight I tried for 
several hours to geht the "lights on" on in my very simple example.
I just wanted a lighted Szene where you can see the depth of the objects but 
some things irritates me.

I converted the lighting-depth-commands from the penguin sample of the wxgtk 
source to my haskell stuff. Just a few lines...

void TestGLCanvas::InitGL(void)
{
    GLfloat light0_pos[4]   = { -50.0, 50.0, 0.0, 0.0 };
    GLfloat light0_color[4] = { .6, .6, .6, 1.0 }; /* white light */
    GLfloat light1_pos[4]   = {  50.0, 50.0, 0.0, 0.0 };
    GLfloat light1_color[4] = { .4, .4, 1, 1.0 };  /* cold blue light */

    /* remove back faces */
    glDisable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
  
    /* speedups */
    glEnable(GL_DITHER);
    glShadeModel(GL_SMOOTH);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
    glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);

    /* light */
    glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light0_color);  
    glLightfv(GL_LIGHT1, GL_POSITION, light1_pos);
    glLightfv(GL_LIGHT1, GL_DIFFUSE,  light1_color);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHT1);
    glEnable(GL_LIGHTING);
    
    glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);  
}

In the HOpenGL Package (not the hOpenGL that comes with ghc!!) exists the 
command 

   enable DepthTest

I do not find a command like this in the ghc-opengl source. Is there one?
Does it matter in what order I give the lightcommands? Or isn't it important 
when I give the "light (...) $= Enable" command at first.

I attach my source and a pick of the output. Please have a look, I hope anyone 
with more experience find the mistake faster than me (Just ignore the 
wx-commands..). I don't want to spend another night experimenting with this.

Many thanks,
Cheers
Patrick

 module GLStuff where

import Graphics.Rendering.OpenGL.GL as GL
import Graphics.Rendering.OpenGL.GLU as GLU
import Graphics.UI.WX as WX
import Graphics.UI.WXCore as WXC
import Graphics.UI.GLUT as GLUT

glDisplay :: GLCanvas a -> WX.DC() -> WX.Rect -> [WX.Rect] -> IO ()
glDisplay glWin _ _ _ = do

  glCanvasSetCurrent glWin

  clearColor $= (Color4 0.0 0.0 0.0 (1.0:: GLfloat))
  clear [ColorBuffer,DepthBuffer]
  GL.color (Color4 0.8 0.5 0.0 (1.0:: GLfloat))
  preservingMatrix $ do
    rotate 5 (Vector3 0.0 1.0 (0.0::GLfloat))
    GLUT.renderObject Solid (Sphere' 0.1 20 20)
    GL.color (Color4 0.0 0.1 0.8 (1.0:: GLfloat))
    rotate 10 (Vector3 1.0 0.0 (0.0::GLfloat))
    translate (Vector3 0.5 0.0 (-0.1::GLfloat))
    GLUT.renderObject Solid (Cube 0.5)
  GL.flush

  glCanvasSwapBuffers glWin
  

glInit :: IO ()
glInit = do
  clearColor $= (Color4 0.0 0.0 0.0 (1.0:: GLfloat))

  dither $= Enabled
  shadeModel $= Smooth
  hint PerspectiveCorrection $= Fastest
  hint PolygonSmooth $= Fastest


  GL.position (Light 0) $= (Vertex4 (-51.0) 51.0 (-2.0) 0.0)
  diffuse (Light 0) $= Color4 0.6 0.6 0.6 1.0
  GL.position (Light 1) $= (Vertex4 51.0 51.0 (-2.0) 0.0)
  diffuse (Light 1) $= Color4 0.4 0.4 1.0 1.0

  light (Light 0) $= Enabled
  light (Light 1) $= Enabled
  lighting $= Enabled
  
  colorMaterial $= Just (FrontAndBack, AmbientAndDiffuse) 

  matrixMode $= Projection
  GLU.perspective 60.0 1 1 20
  GLU.lookAt (Vertex3 0.0 0.0 (-2)) (Vertex3 0.0 0.0 0.0) (Vector3 0.0 1.0 
0.0)
  matrixMode $= Modelview 0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screen1.jpg
Type: image/jpeg
Size: 13607 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/hopengl/attachments/20050113/d4897283/screen1.jpg


More information about the HOpenGL mailing list