When you set the display mode for OpenGL, you enable all the coolness of 3D rendering, but you disable the bread-and-butter raster SDL functionality like fill() and blit(). Since the GUI libraries use those surface methods extensively, they cannot readily be used in OpenGL displays.

Lamina provides the LaminaPanelSurface and LaminaScreenSurface classes, which bridge between the two.

LaminaPanelSurfaceThe ‘surf’ attribute is a surface, and can be drawn on, blitted to, and passed to GUI rendering functions for alteration. The ‘display’ method displays the surface as a transparent textured quad in the OpenGL model-space. The ‘refresh’ method indicates that the surface has changed, and that the texture needs regeneration. The ‘clear’ method restores the blank and transparent original condition. The initializer needs the size and location of the quad in 2d model units, and the programmer sets up the modelview matrix before calling display().

LaminaScreenSurfaceHas the methods and attributes described above, but needs no initial parameters; it automatically sizes the gui quad to display full-screen. When either the projection or modelview matrix changes, call the refreshPosition method to resize and relocate the quad to maintain full-screen.

There are six demonstration scripts in the distribution: The PGU and Ocemp versions of my GUI comparison script have been converted to use PanelOverlays, and the clock-spinner has been replace with a rotating wireframe sphere, to show the 3D quality. The other four scripts are conversions of Nehe tutorial lesson04 for Ocemp and PGU; the GUI provides buttons to toggle the image rotations on and off. Two scripts have a ‘zoom’ button to illustrate the LaminaScreenSurface’s resizing method.

This LaminaPanelSurface implementation requires you to stipulate where the quad will be drawn, and, if your surface is not screen-sized, to make adjustments for mouse coordinates. This is most useful if your viewer (camera) does not pan or pivot. The LaminaScreenSurface automatically sizes the quad to be full-screen and the mouse events can be used as-is.

The file can be found at
https://sourceforge.net/project/showfiles.php?group_id=110483

I can be reached at dkeeney@travelbyroad.net or by leaving a comment on the blog.

Advertisements