![]() TGE Version 1.5.2 | |
| |
GraphicsOverviewThe Torque Engine does not implement its own graphics rasterization layer. OpenGL was chosen as the graphics API for the Torque to primarily for its cross-platform nature and ease-of-use. The Torque includes a utility library called DGL that extends OpenGL to support higher level primitives and resources, as well as performing texture management.The platform layer is responsible for initializing the OpenGL state. For PlatformWin32 this can include loading a DLL that converts OpenGL calls to Direct3D (OpenGL2D3D.DLL). The Texture ManagerDGL includes a texture manager (engine/dgl/gTexManager.*) that tracks the loading and unloading of all textures in the game. When the game requests a texture, it uses the TextureHandle class - which acts as a sort of special resource handle for textures in the game. Only one instance of a texture is ever loaded at once, and after load is handed off to OpenGL. When the game switches graphics modes or video devices, the Texture Manager can transparently reload and re-download all the game's textures.Primitive supportGFont - fonts in the Torque are alpha textures created by the platform layer from OS dependent outline fonts.GBitmap - the Torque supports several bitmap file types - PNG, JPEG, GIF, BMP and the custom BM8 format (an 8-bit color quantized texture format used to cut texture memory overhead). MaterialList - a material list is a resource that manages a list of bitmaps. It is used for shapes and interiors that have more than one texture. Primitive renderingThe DGL support functions support a wide variety of common 2D rendering primitives. Bitmaps (loaded as textures) can be rendered via the dglDrawBitmap(), dglDrawBitmapStretch(), dglDrawBitmapSR() (sub-region), and dglDrawBitmapStretchSR() functions. Text can be rendered using dglDrawText() and dglDrawTextN(). Dgl also supports drawing of lines, rectangles and filled rectangles.Unlike default OpenGL, the screen coordinate space set up for 2D rendering in the Torque is a traditional 2D scheme where (0,0) is in the upper left corner of the screen and +Y goes down the screen. This requires (in the case of 3D) calling dglSetViewport rather than glViewport. For 2D rendering, DGL viewport management is simplified by dglSetClipRect(). 3D RenderingThere are several key differences in how the Torque does rendering from the default OpenGL. First, the coordinate system is set up to look down the +Y axis instead of -Z. This means dgl replaces the call to glFrustum() with a call to dglSetFrustum(). Also, all Torque matrices are organized in standard C array form - with the second element in the array corresponding to the first row, second column. This is the opposite of OpenGL, so DGL supplies alternates to glLoadMatrix() and glMultMatrix(), appropriately named dglLoadMatrix() and dglMultMatrix() respectively.3D points can be converted to 2D screen points using the dglPointToScreen() function, and a measure of projected screen size of an object can be determined using the dglProjectRadius() function. |