OpenGL: Difference between revisions
Line 109: | Line 109: | ||
createWindow "My Window" | createWindow "My Window" | ||
</haskell> | </haskell> | ||
You will also need to call [http://hackage.haskell.org/packages/archive/GLUT/latest/doc/html/Graphics-UI-GLUT-Window.html#v%3AswapBuffers] | You will also need to call <haskell> swapBuffers </haskell> at the end of your draw function [http://hackage.haskell.org/packages/archive/GLUT/latest/doc/html/Graphics-UI-GLUT-Window.html#v%3AswapBuffers (Read more about swapBuffers.)]. | ||
=== The depth buffer doesn't work (things that are closer to the camera are occluded by things that are farther from the camera) === | === The depth buffer doesn't work (things that are closer to the camera are occluded by things that are farther from the camera) === |
Revision as of 08:51, 16 September 2012
This article is a stub. You can help by expanding it.
References
In particular, note that the examples/ directory in the GLUT repo contains lots of examples, including translations of the red book examples.
(Note: at least some of these resources appear to be missing from /packages, but there are copies at /ghc-6.8/packages.)
Both the API documentation and the examples are best studied with the original specs and the original red book examples at hand. An index of examples can be found at the OpenGL wiki page Code Resources.
Projects using the OpenGL bindings
- Endless Cavern, a 2D procedurally-generated exploration game.
- Frag, a 3D first-person shooter game.
- Monadius, a 2D scrolling arcade game.
- Roguestar, a roguelike adventure game using 3D graphics.
- Shu-thing, a 2D scrolling arcade game.
- Topkata, a jumping ball puzzle game.
- PolyFunViz, a toolkit for scientific visualization (e.g. surfaces, flows, contours, volumes)
- Raincat, a 2d puzzle game
- Gloss, hides the pain of drawing simple vector graphics behind a nice data type and a few display functions
HOpenGL Resources
- OpenGLTutorial1 and OpenGLTutorial2
- Beautiful Code, Compelling Evidence: Functional Programming for Information Visualization and Visual Analytics - Writing visualizations using OpenGL or Cairo (PDF)
- Andre Furtado's nice tutorial written in 2001 (bitrotted)
OpenGL Resources
- OpenGL FAQ and Troubleshooting Guide Assumes some knowledge of OpenGL. Good for those who have written something but want to avoid common pitfalls.
Getting Started
- Windows users can read how to install OpenGL in the blog article freeglut + Windows + HOpenGL + HGLUT
- use the Haskell port (Hackage package) of the NeHe Tutorials
- assuming you know Haskell, any OpenGL tutorial of your choice should get you going (browsing the OpenGL site is also a good idea)
- use the Red Book, and its example code translations, to understand the small differences between OpenGL and HOpenGL
- use the OpenGL and GLUT specs to find your way around the HOpenGL Haddock documentation
- use the HopenGL list for questions and success stories
Additional software
- OpenGLRaw: A 1:1 mapping of OpenGL's C API, intended as a basis for a nicer interface. (Example code)
- StateVar: This package contains state variables, which are references in the IO monad, like IORefs or parts of the OpenGL state
- ObjectName: Explicitly handled object names. This tiny package contains the class ObjectName, which corresponds to the general notion of explicitly handled identifiers for API objects, e.g. a texture object name in OpenGL or a buffer object name in OpenAL
- GLURaw: A raw binding for the OpenGL graphics system. GLURaw is a raw Haskell binding for the GLU 1.3 OpenGL utility library. It is basically a 1:1 mapping of GLU's C API, intended as a basis for a nicer interface
- FTGL: Portable TrueType font rendering for OpenGL using the Freetype2 library
- GLFW: A binding for GLFW, An OpenGL Framework
- GLUT: A binding for the OpenGL Utility Toolkit
- graphics-drawingcombinators: A functional interface to 2D drawing in OpenGL
- Tensor: This package contains tensor data types and their instances for some basic type classes.
- GPipe: A functional graphics API for programmable GPUs
- The freetype2 package; bindings to FreeType, a software font engine
Somewhat related is SDL, which is based on OpenGL:
- SDL: Binding to libSDL
- SDL-gfx: Binding to libSDL_gfx
- SDL-image: Binding to libSDL_image
- SDL-mixer: Binding to libSDL_mixer
- SDL-mpeg: Binding to the SMPEG library
- SDL-ttf: Binding to libSDL_ttf
To add sound to OpenGL applications:
- OpenAL: A binding to the OpenAL cross-platform 3D audio API
- ALUT: A binding for the OpenAL Utility Toolkit
A fork of HOpenGL:
Experiments with raw bindings to GLFW/OpenGL produced with HSFFIG
Troubleshooting
I can't display text with renderString
It's probably because the text is displayed too big. Setting a much smaller scale factor before calling renderString should solve the problem.
scale 0.001 0.001 (0.001∷GLfloat)
renderString Roman "Test string"
Animations flicker
If you're not using DoubleBuffered display mode, turn that on. Also, you must set the display mode before creating the window you're going to be drawing in. To check if you've enabled double buffering use something like:
db <- get doubleBuffered
and set DoubleBuffered mode (before creating your windows!) like this:
initialDisplayMode $= [DoubleBuffered]
createWindow "My Window"
swapBuffers
The depth buffer doesn't work (things that are closer to the camera are occluded by things that are farther from the camera)
Make sure that depthFunc is set:
depthFunc $= Just Less
Furthermore, if you're using GLFW, the following var has to be greater than zero:
get (windowParam DepthBits)
If DepthBits is 0, you probably forgot to initialize the window, like so:
openWindow size [DisplayDepthBits 16] Window
Once you enable the depth buffer, you will need to clear it before each cycle of your drawing method:
clear [ColorBuffer, DepthBuffer]
See also: The OpenGL FAQ: 12.010 How do I make depth buffering work?