
Hi there, this isn't probably the right place but my question is more opengl specific, so I decided to send a mail to this list. Is anyone in here who has done any opengl thing with wxhaskell? My problem is, that the sample in the wxhaskell code under /samples/contrib/GLCanvas.hs doesn't show anything except of a white screen. But there aren't any error messages and I don't know if this is a problem of the samplecode or a problem of mine. I use ghc 6.2.1 and the wxhaskell from the cvs, but I think that doesn't matter because the stable version shows the same effect. It would be a great help if anyone has a small working sample and can send me this. Cheers Patrick

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

Patrick Scheibe wrote:
/* remove back faces */ glDisable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); [...] 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?
[ I cut-n-paste a bit from a previous mail on this list... :-) ] This is one of the design principles of the new API: Instead of separately setting a "cheap" aspect of the OpenGL state (here: the depth comparison function) and enabling/disabling the associated functionality (here: the depth test), a single state variable (here: depthFunc) of a Maybe type is used. So e.g. disabling the depth test is simply done by depthFunc $= Nothing or querying its state by df <- get depthFunc case df of Nothing -> ... -- the depth test is disabled Just func -> ... -- the depth test is enabled and func is used as the -- comparison function Therefore, what you are looking for is: depthFunc $= Just Less
Does it matter in what order I give the lightcommands? Or isn't it important when I give the "light (...) $= Enable" command at first.
No, this should not matter.
I attach my source and a pick of the output. [...]
I don't have wxHaskell installed currently, so I've quickly ported your example to GLUT (see attachment) with a few small changes: * Now culling is disabled and the depth function is enabled. * A reshape callback has been added and the projection matrix is set there. * A simple keyboard callback for exit has been added. * clearColor is set only once. Strangely enough, things work for me, see the attached picture. Does this GLUT program work on your platform? Does a 1:1 C GLUT program work? Cheers, S. module Main where import System.Exit import Graphics.Rendering.OpenGL.GL as GL import Graphics.Rendering.OpenGL.GLU as GLU import Graphics.UI.GLUT as GLUT glDisplay :: DisplayCallback glDisplay = do 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) flush glInit :: IO () glInit = do clearColor $= (Color4 0.0 0.0 0.0 (1.0:: GLfloat)) cullFace $= Nothing depthFunc $= Just Less 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) reshape :: ReshapeCallback reshape size@(Size w h) = do viewport $= (Position 0 0, size) matrixMode $= Projection loadIdentity 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 keyboard :: KeyboardMouseCallback keyboard (Char '\27') Down _ _ = exitWith ExitSuccess keyboard _ _ _ _ = return () main :: IO () main = do (progName, _args) <- getArgsAndInitialize initialWindowSize $= Size 500 500 initialDisplayMode $= [ SingleBuffered, RGBMode, WithDepthBuffer ] createWindow progName glInit displayCallback $= glDisplay keyboardMouseCallback $= Just keyboard mainLoop
participants (2)
-
Patrick Scheibe
-
Sven Panne