OpenGL Renderer Documentation


1. Overview

This document basically just provides a simple overview of the rendering path and complimentary functions of the ZDoomGL renderer.


2. Renderer

   2.1. Which Renderer Is Active?

   The variable "currentrenderer" will tell you which renderer is active.  This is defined in the "gl_struct.h" header file.  A value of 0 is the software renderer and a value of 1 is the OpenGL renderer.

   2.2. Texture Management

   The texture manager in ZDoomGL has functionality to handle texture translations, animated textures, and automatically loads optional hires images (if the gl_texture_hires cvar is set).  It also handles configuring the textures to take advantage of any hardware options available to the textures, such as hardware mipmaps and anisotropic filtering.  There should only be one instance of the manager at one time, and it is defined as an extern variable called "textureList" in the "gl_struct.h" header file, so if you include that, you will gain access to the texture manager.
   
   The texture manager uses several items to key each texture: the pointer to the texture itself, the colormap that was set when it was loaded, if it was loaded as an alpha texture and if it was loaded as a sky texture.

      2.2.1. Binding Textures

      To bind a texture, there are a few different methods: BindTexture(int textureID, bool translate) and BindTexture(FTexture *tex).  The first one is handy for geometry rendering when you already have the index for the ZDoom texture manager (the translate parameter controls whether or not to animate the texture or if the index is an absolute index) and the second is good for the 2D displays.

      2.2.2. Setting Colormaps

      You can set a colormap with the SetTranslation methods: SetTranslation(unsigned short trans) and SetTranslation(const byte *trans).  The first is more of a convenience method for rendering actors and essentially calls the second.  BE SURE TO SET IT BACK TO NULL WHEN YOU HAVE BOUND THE TEXTURE TO BE TRANSLATED (textureList.SetTranslation((byte *)NULL);)!
      
      2.2.3. Alpha Textures
      
      The method LoadAlpha(bool alpha) controls whether or not to load the texture as an alpha texture (ie: particles, decals, etc).  Instead of using each pixel in the texture as a color index, it's assumed that the value represents an alpha value (0..255).  Be sure to set this back to false when you have bound the alpha texture.
      
      2.2.4. Sky Textures
      
      The method LoadSky(bool sky) controls whether or not to load the texture as a sky texture.  Sky textures are different than normal textures in that their transparent index is 0x00 instead of 0xff.  As with alpha textures, be sure to set this back to false when you have bound the sky texture.


3. Complimentary Functions

   3.1. 2D Displays

   GL_DrawTextureVA(FTexture *img, int x, int y, DWORD tag_start, ...)

   This function exactly mirrors the functionality in DCanvas::DrawTexture, so 99% of all 2D display calls go through this function (DCanvas::DrawText calls this function as well).

   3.2. Scaled/Non-scaled Textures

   Sprites, fonts and other 2D display images can have the automatic image scaling turned off with the textureList.AllowScale(bool scale) method.  You can then get the corner texture coordinates with the textureList.GetCorner(float *x, float *y) method.  Make sure to set this back to false when you are finished binding the texture!