OpenGL Samples for Linux

Simple GLX Sample
 

This sample is a basic demonstration of how to use GLX to create windowed OpenGL samples via XFree86, which is a a freely redistributable open-source implementation of the X Window System.

 

Simple GLUT/freeglut Sample
 

This sample is a basic demonstration of how to use GLUT or it's replacement, freeglut to create cross-platform, windowed OpenGL samples.

 

Benchmarking Test App
 

Renders a textured sphere using either Immediate Mode calls, Immediate Mode calls cached in a Display List, or a Vertex Array for benchmarking purposes.

 

Texture Animated 3D Sprites
 

It may sound strange to write 3D code that mimics the traditional sprite animation found in 2D games, but many modern video card drivers place little emphasis on 2D bit-blitting anymore. This means that 3D sprites, which perform 2D style animation through the manipulation of texture coordinates, are much faster because they can take advantage of any hardware acceleration that exists in the hardware’s TN&L pipeline.

 

Basic 3D Collision Detection
 

As you may or may not know, truly accurate collision detection between two 3D objects can only be done by performing an intersection test on every triangle in the first object against every triangle of the second object. Of course, it's too wasteful to just go around blindly performing this costly procedure on every object in the scene against every other object. To save us considerable CPU cycles, we'll calculate and assign a bounding sphere for each of our 3D objects so we can perform a quick check to see whether or not the two objects are even close to one another and require further testing. In short, if the two bounding spheres of our objects overlap, then there exists a possible collision and we need investigate further by checking triangles. If the two spheres don't overlap, a collision is not possible and we can move on.

Please note that the spheres shown below are being rendered for demonstration purposes only. The spheres that are actually used for collision detection are purely mathematical and exist only as a center point in 3D space and a radius.

 

Off-screen Rendering Using Pixel Buffers
 

This sample demonstrates how to create dynamic textures through off-screen rendering. The off-screen rendering step is accomplished using a p-buffer, which is created using GLX's glXCreatePbuffer method. The step of dynamic texture creation from a p-buffer involves sharing the window's GLXContext with the p-buffer's GLXContext so we can load the texture with pixel data with a simple call to glCopyTexSubImage2D.

As a demonstration, a spinning textured cube is rendered to a p-buffer, which is in turn, used to create a dynamic texture. The dynamic texture is then used to texture a second spinning cube, which will be rendered to the application's window.

Relevant Keywords:  GLXContext, GLXFBConfig, XVisualInfo, DefaultScreen, glXCreateContext, glXCreatePbuffer, glXGetVisualFromFBConfig, glXChooseFBConfig, glXMakeCurrent, glXDestroyContext, glXDestroyPbuffer, glDeleteTextures, glGenTextures, glBindTexture, glTexParameteri, glTexImage2D, glReadPixels, glCopyTexSubImage2D, GLX_DOUBLEBUFFER, GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, GLX_DEPTH_SIZE, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, GLX_WINDOW_BIT, GLX_PBUFFER_WIDTH, GLX_PBUFFER_HEIGHT, and GLX_LARGEST_PBUFFER.

 

SDL Samples (Simple Directmedia Layer)

Sprite Bit-Blitting
 

This sample demonstrates how to use SDL to animate a 2D sprite via bit-blitting.

 

Polling for Mouse Input
 

This sample demonstrates how to create the world's cheesiest paint program by polling the mouse for input using SDL.

 

2D Star Field
 

This sample demonstrates how to use SDL to create a 2D star field effect suitable for a 2D space shooter.

 

SDL & OpenGL
 

This sample demonstrates how to use SDL to render 3D scenes with OpenGL.