Re: clear [ColorBuffer]

Sven Panne <[email protected]>
Newsgroups gmane.comp.lang.haskell.hopengl
Message-ID <[email protected]>
On Friday 16 February 2007 19:35, h. wrote:
>  [...] and the problem:
> The ColorBuffer is not cleared, the window shows what was there before it
> was created. [...]

Just a small addition: As was already pointed out, rendering in OpenGL is not 
synchronous, which is a very good design decision given the capabilities and 
architectures of today's graphic cards. If you use single-buffering (as in 
your example), a 'flush' or 'finish' is needed, see:

http://www.haskell.org/ghc/docs/latest/html/libraries/OpenGL/Graphics-Rendering-OpenGL-GL-FlushFinish.html

If double-buffering is used, GLUT's 'swapBuffers' is your friend:

http://www.haskell.org/ghc/docs/latest/html/libraries/GLUT/Graphics-UI-GLUT-Window.html#v%3AswapBuffers

Example:

--------------------------------------------------------------------------
import Graphics.UI.GLUT

main :: IO ()
main = do
   _ <- getArgsAndInitialize
   initialDisplayMode $= [ DoubleBuffered ]
   createWindow "Hello World"
   displayCallback $= do clear [ ColorBuffer ]; swapBuffers
   mainLoop
--------------------------------------------------------------------------

Other UI toolkits with an OpenGL canvas will have something similar 
to 'swapBuffers', e.g. 'glDrawableSwapBuffers' in Gtk2Hs, IIRC.

Cheers,
   S.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.