problem with displayCallback and Double buffering

does anyone else have this problem? i want to use double buffering, but swapBuffers does not seem to work. to set the active window to... the active window (i think that has to work!) does not work, too. but i am able to compile and run glut examples with double buffering written in c. coeus@titan ~/Documents/haskell/hopengl/problem $ ghc -package GLUT -package OpenGL first.hs -lglut coeus@titan ~/Documents/haskell/hopengl/problem $ ./a.out displayModePossible? ...True begin swapBuffers

Marc A. Ziegert wrote:
does anyone else have this problem? i want to use double buffering, but swapBuffers does not seem to work.
Works for me with the current version from CVS on x86 Linux, see below.
to set the active window to... the active window (i think that has to work!) does not work, too. [...]
I guess with "active" you mean "current", but this works for me, too. Remember that you can't access currentWindow (or windowPosition, windowSize, etc.) before mainLoop is entered, this is how GLUT works. Cheers, S. ---------------------------------------------------------------------- import Graphics.UI.GLUT dc :: DisplayCallback dc = do clearColor $= Color4 0 0 1 0 clear [ColorBuffer, DepthBuffer] putStrLn "begin swapBuffers" swapBuffers putStrLn "end swapBuffers" main :: IO () main = do getArgsAndInitialize initialDisplayMode $= [DoubleBuffered, WithDepthBuffer] b <- get displayModePossible putStrLn $ "displayModePossible? ..." ++ show b createWindow "main" displayCallback $= dc mainLoop ---------------------------------------------------------------------- panne@jeanluc:~> ghc --make first.hs Chasing modules from: first.hs Compiling Main ( first.hs, first.o ) Linking ... panne@jeanluc:~> ./a.out displayModePossible? ...True begin swapBuffers end swapBuffers [ blue window appears, iconized it and de-iconized it again ] begin swapBuffers end swapBuffers

i've installed ghc-6.3.20031102 (still the "-lGL" <--> "-lGLU" bug in package.conf). that version works now, thanks. now i want to use ghci, especially with forkIO mainLoop , but that does not seem to work anymore. is that a forkIO bug? the renaming of DoubleBuffered and WithDepthBuffer is convenient. :) - marc Am Freitag, 31. Oktober 2003 18:48 schrieb Sven Panne:
Marc A. Ziegert wrote:
does anyone else have this problem? i want to use double buffering, but swapBuffers does not seem to work.
Works for me with the current version from CVS on x86 Linux, see below.
to set the active window to... the active window (i think that has to work!) does not work, too. [...]
I guess with "active" you mean "current", but this works for me, too. Remember that you can't access currentWindow (or windowPosition, windowSize, etc.) before mainLoop is entered, this is how GLUT works.
Cheers, S.
---------------------------------------------------------------------- import Graphics.UI.GLUT
dc :: DisplayCallback dc = do clearColor $= Color4 0 0 1 0 clear [ColorBuffer, DepthBuffer] putStrLn "begin swapBuffers" swapBuffers putStrLn "end swapBuffers"
main :: IO () main = do getArgsAndInitialize initialDisplayMode $= [DoubleBuffered, WithDepthBuffer] b <- get displayModePossible putStrLn $ "displayModePossible? ..." ++ show b createWindow "main" displayCallback $= dc mainLoop ---------------------------------------------------------------------- panne@jeanluc:~> ghc --make first.hs Chasing modules from: first.hs Compiling Main ( first.hs, first.o ) Linking ... panne@jeanluc:~> ./a.out displayModePossible? ...True begin swapBuffers end swapBuffers [ blue window appears, iconized it and de-iconized it again ] begin swapBuffers end swapBuffers
_______________________________________________ HOpenGL mailing list HOpenGL@haskell.org http://www.haskell.org/mailman/listinfo/hopengl

On 05.11.2003, at 00:34, Marc A. Ziegert wrote:
i've installed ghc-6.3.20031102 (still the "-lGL" <--> "-lGLU" bug in package.conf). that version works now, thanks.
now i want to use ghci, especially with forkIO mainLoop , but that does not seem to work anymore. is that a forkIO bug?
Hmm... did you build ghc with the --enable-threaded-rts flag? If so, you should be using forkOS instead of forkIO; forkIO creates a lightweight thread, but most OpenGL implementations require a (heavyweight) OS thread to run reliably. With GHC 6.3 --enable-threaded-rts, this means you can call GLUT/OpenGL from the main thread, from threads created using forkOS, and from foreign exported functions, but not from threads created using forkIO. If you're not using --enable-threaded-rts, then you could encounter a different problem: GHCi only gets a chance to run while the GLUT mainLoop is inside a callback, and while GHCi is waiting for input using readline, the GLUT mainLoop will be blocked. Things might work if you build GHC without readline support and install an idle callback into the GLUT event loop. In both cases, keep in mind that all the OpenGL drawing has to be done from the thread that GLUT is running in. You can use MVars to communicate with that thread from the GHCi prompt, but doing OpenGL drawing from the GHCi prompt while a GLUT mainLoop is running in the background will never work reliably. Grüße, Wolfgang

wow. thanks. i think, i have to compile again... and read about all the configurations first. - marc Am Mittwoch, 5. November 2003 01:04 schrieb Wolfgang Thaller:
On 05.11.2003, at 00:34, Marc A. Ziegert wrote:
i've installed ghc-6.3.20031102 (still the "-lGL" <--> "-lGLU" bug in package.conf). that version works now, thanks.
now i want to use ghci, especially with forkIO mainLoop , but that does not seem to work anymore. is that a forkIO bug?
Hmm... did you build ghc with the --enable-threaded-rts flag? If so, you should be using forkOS instead of forkIO; forkIO creates a lightweight thread, but most OpenGL implementations require a (heavyweight) OS thread to run reliably. With GHC 6.3 --enable-threaded-rts, this means you can call GLUT/OpenGL from the main thread, from threads created using forkOS, and from foreign exported functions, but not from threads created using forkIO.
If you're not using --enable-threaded-rts, then you could encounter a different problem: GHCi only gets a chance to run while the GLUT mainLoop is inside a callback, and while GHCi is waiting for input using readline, the GLUT mainLoop will be blocked. Things might work if you build GHC without readline support and install an idle callback into the GLUT event loop.
In both cases, keep in mind that all the OpenGL drawing has to be done from the thread that GLUT is running in. You can use MVars to communicate with that thread from the GHCi prompt, but doing OpenGL drawing from the GHCi prompt while a GLUT mainLoop is running in the background will never work reliably.
Grüße,
Wolfgang
_______________________________________________ HOpenGL mailing list HOpenGL@haskell.org http://www.haskell.org/mailman/listinfo/hopengl
participants (3)
-
Marc A. Ziegert
-
Sven Panne
-
Wolfgang Thaller