![]() |
The Computer Graphics Companion Online Edition Damian Scattergood 1999-2001 |
|
DESIGNING A GRAPHICS ENGINE |
|
The Universal Graphics Engine One of the fundamental concepts you must always keep in mind when designing a graphics engine is that it should be completely portable. This way as newer, faster and more elaborate hardware arrives, your graphics engine can be easily modified to run on the new system. This gives you the advantages of not having to rework code, thus getting your software to market sooner. Obviously you must design your graphics engine to be mostly hardware independant. This way by only modifying the bare mininum of code, your engine can easily be ported to run on various platforms. In designing a graphics engine the basic design should fall into two categories, hardware and non-hardware dependant routines. The following diagram shows the ideal layout for a complete graphics engine. |
The Universal Graphics Engine Overview
|
HARDWARE |
BLITSTONES and PRIMITIVES |
|
2D SOFTWARE LEVEL |
COMPLEX PRIMITIVES |
|
|
2D WORLD MAPPING SYSTEM |
||
|
2D WORLD SYSTEM |
||
|
2D OBJECTS |
||
|
3D |
WORLD TRANSFORMATION SYSTEM |
|
|
3D WORLD SYSTEM |
||
|
3D OBJECTS |
||
|
3D MODELLING SYSTEM |
|
Other Blitsones can include HorizontalLine() and Line() drawing routines, which take advantage of the hardware platform. These key elements can be used to create any given object. by one of the higher levels. Primitives are the next level up containing such routines as Circle(), Triangle(), Rectangle() etc,. These routines can either be coded calling only the hardware dependant BlitStones, or they can alternately be coded to suit the current hardwae for optimum speed. At the upper end of the Primitives section you can include what I call Complex Primitives. These routines are 2D based drawing routines suach as DrawPolygon() and FillPolygon(). Here you may also have the routines for SolidDisc(), SolidSector() etc. It is not a requirement to have Primitives hardware dependant, but doing so can greatly increase the drawing speed.
At the start of the 2D level you can include Complex Primitives if you do not want them to be hardware dependant.
In order to change 2D screen co-ordinates to hardware specific co-ordinates the 2D system must supply co-ordianate mapping software. These routines will perform such functions as line clipping to only pass visible co-ordinates to the lower level drawing system. Viewport mapping functions are also supllied at this level.
The 2D world system supplies the standard functions for moving objects about in the 2D world. Its main functions would include Rotate(), Transform(),Scale() etc.
The 2D Object level is where the user creates their 2D world. Here you will find routines for drawing Polygons, Text etc. It is at this level most 2D programs are designed. A 2D drafting package could be designed using only this level and below.
The basic functionality of the 3D graphics package must be the 3D to 2D mapping functions. These functions will take 3D elements and convert them to 2D co-ordinates for drawing by the 2D system. Functions can include scaling, perspective and 3D clipping routines.
The 3D world system contains the basic routines to Rotate, Scale, Transform etc given 3D co-ordinates and objects in the 3D world.
The 3D objects level contains routines for creation and modelling of bacis 3D objects. Routines are usually supplied for drawing what are termed the basic 3D building blocks, these being Cubes, Spheres etc... Using this blocks you can create various real world objects.
The final level in your graphics engine is the 3D modelling system. This is where the user creates their virtual world. This system supplies the user with software to create a 3D model of any object, place it into the virtual world and allows the user full mobility within that world. |