Next: , Previous: , Up: GL   [Index]


3.3 Rendering

To draw with OpenGL, you obtain a drawing context (see GL Contexts) and send the GL some geometry. (You can think of the GL as a layer over your graphics card.) You can give the GL points, lines, and triangles in three-dimensional space. You configure your GL to render a certain part of space, and it takes your geometry, rasterizes it, and writes it to the screen (when you tell it to).

That’s the basic idea. You can customize most parts of this rendering pipeline, by specifying attributes of your geometry with the OpenGL API, and by programmatically operating on the geometry and the pixels with programs called shaders.

GL is an immediate-mode graphics API, which is to say that it doesn’t keep around a scene graph of objects. Instead, at every frame you as the OpenGL user have to tell the GL what is in the world, and how to paint it. It’s a fairly low-level interface, but a powerful one. See http://www.opengl.org/wiki/Rendering_Pipeline_Overview, for more details.

In the old days of OpenGL 1.0, it was common to call a function to paint each individual vertex. You’ll still see this style in some old tutorials. This quickly gets expensive if you have a lot of vertexes, though. This style, known as Legacy OpenGL, was deprecated and even removed from some versions of OpenGL. See http://www.opengl.org/wiki/Legacy_OpenGL, for more on the older APIs.

Instead, the newer thing to do is to send the geometry to the GL in a big array buffer, and have the GL draw geometry from the buffer. The newer functions like glGenBuffers allocate buffers, returning an integer that names a buffer managed by the GL. You as a user can update the contents of the buffer, but when drawing you reference the buffer by name. This has the advantage of reducing the chatter and data transfer between you and the GL, though it can be less convenient to use.

So which API should you use? Use what you feel like using, if you have a choice. Legacy OpenGL isn’t going away any time soon on the desktop. Sometimes you don’t have a choice, though; for example, when targeting a device that only supports OpenGL ES 2.x, legacy OpenGL is unavailable.

But if you want some advice, we suggest that you use the newer APIs. Not only will your code be future-proof and more efficient on the GL level, reducing the number of API calls improves performance, and it can reduce the amount of heap allocation in your program. All floating-point numbers are currently allocated on the heap in Guile, and doing less floating-point math in tight loops can only be a good thing.


Next: , Previous: , Up: GL   [Index]