sglv0.16
This document is intended to be viewed in Internet
Explorer
By downloading the sgl package you agree to the following terms: This software is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
arising from the use of this software. You use this software at your own
risk.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it, copy parts or whole sections of code, and redistribute it freely, subject to the following restrictions: 1. Please acknowledge the original author when using this software,
copying code or 2. Altered source versions or custom packages that include parts of the
original sgl package 3. You may not charge for the original sgl package although you may
charge for
Sgl is a software 3D graphics rendering engine for DIV Games Studio. Sgl has low-level drawing routines such as triangular primitive polygons. There are also some High-level commands that allow you to import Md2 Models and render them. This engine is primarily designed for Solid coloured polygons (there alot faster) but it also has support for Textured polygons. This engine is designed for and fixed at 8-bit colour (used in DIV Games Studio). Hopefully in the future when DIV supports 16-bit & 24-bit colour modes, i'll adapt this. As this engine is software based, it is slower and uglier when compared to hardware 3D engines such as Opengl (which sgl's commands are loosely based upon) and Direct3D. Because the core rendering process of sgl is fixed point (32-bit) math,
rendering on large polygons
● (fast) Solid & (slow) Textured (8-bit) Mapped Triangular
primitive
polygons with transparencies
●Small speedup and memory op
by switching to 16bit zbuffering, a few asm ops and a faster memory
clearing. ●Added textured polygon
transparencies (with variable colour)
●Rewrote
sglGetMatrixHeight() because is still had some major bugs that I couldn't
patch over
●Made polygons more seamless
after I saw occasional minor gaps when using matrixes.
●Cut out the need to call
sglResetModelInfo or sglResetTextureInfo(). Now does it on execution
●First stable version of
sgl.
Textured & untextured polygons working. Md2 models with backface culling
All sgl dll commands begin with "sgl" eg. sglLoadModel().
This initialises the dll for the current screen resolution. This must be called before drawing. If you change the resolution after calling this command or change the Rendering context (rendering buffer) to one of a different size, you must recall it before drawing or else DIV may crash. NOTE: when you call sglInit(), if the requested zbuffer is smaller than what already exists, the old one is kept to stop unneeded memory allocation, speeding things up abit.
This defines the renderable area of the background screen. This must be setup for drawing to take place. y0&x0 define the top-left corner of the screen and y1&x1 define the bottom-right corner of the screen. Using this command it is possible to have "split screen" support. For a double split screen (usually for a two player game) define the first viewport to the top of the screen, Then render your graphics. Then simply move the viewport down to the bottom half of the screen and render your second lot of graphics. NOTE: x0 & y1 include the maximum area, so the greatest x1 value you could specify if the resolution was 800x600 would be 799. Anything greater wouldn't work.
This sets the viewport to maximum. This does the same as sglSetViewport(0,0,screen_x_size-1,screen_y_size-1)
This refers to the screen viewport dimensions. This is simply a parameter
of
This refers to the entire screen dimensions, regardless of the viewport.
This is simply a parameter of
This clears the zbuffer, a huge array that is needed for polygons to be
drawn correctly. This must be called every frame before you start drawing.
This function must be called AFTER sglinit()
This renders a 3D three-sided polygon to the screen. The polygon is automatically drawn in accord with the camera position and rotation(s). The filling mode defines whether it is filled with a colour, OR whether a texture map is used and what are the texture co-ordinates. The following commands can be used for the "FILLING TYPE": sglSolidColour(col) and sglTextureMap(Texture ID, tx0, ty0, tx1,
ty1, tx2, ty2)
This is used as a parameter to sglPolygon3v() as a FILLING TPYE. This specifies that the polygon should be filled with a colour. e.g.. sglPolygon3v(....,sglSolidColour(10)); This draws a polygon filled with the colour '10'.
This is used as a parameter to sglPolygon3v() as a FILLING TYPE. This specifies that the polygon should be texture mapped. The tx&ty parameters specify which texture co-ordinate each of polygon's vertexes should use. eg. sglPolygon3v(....,sglTextureMap(1,0,0,99,0,99,99)); This draws a polygon Texture Mapped with the texture '1'. Textured Polygons are alot slower than Solid Coloured ones and should be substituted with Solid ones where possible. Also Textured Polygons, if they are too large will start to mess up and can possibly crash. Keep textured polygons small (<=20000) for the best results NOTE: The co-ordinates must all be positive. Also they must be SMALLER than the texture width/height. Setting an x co-ordinate to 100 if the texture is 100 wide will make Div CRASH. The maximum x co-ordinate is the texture width -1. The same applies to the height.
This is the same as sglTextureMap, but the parameters, instead of being co-ordinates are out of 1024. 1024 would be the whole texture width/height and 0 would be the start. 512 would be the middle ect. Apart from this, this is exactly the same as sglTextureMap.
This enables Z-Buffering on all polygons/models when drawing. Z-Buffering
is by default is enabled, so you Z-Buffering is the most popular way of accurately ordering polygons and
is used in Opengl & Direct3D.
This Disables Z-Buffering on all polygons/models when drawing. Disabling
Z-Buffering means polygons are
This effectively turns fogging on by setting the fog colour, max intensity
and distance.
This effectively turns fogging off. Fogging is automatically off by default unless turned on.
This simply adjusts the dll if the game palette has changed at all. If
you have loaded an fpg with a different
When this is called and then when texture mapped polygons are rendered,
any transparent pixels
This simply prevents transparent colour pixels in a texture mapped
polygon are drawn. This is done by default
This allows you to set the colour of transparent pixels (0 by default).
This only takes effect when transparencies are
This command creates a blank new texture and copies the selected portion of the background to this texture. This is the easiest method to load textures into sgl memory. Simply put your texture to the background starting at 0,0 and then call this function giving the required width and height. example: put(0,1,160,100); texture_id = sglGrabTexture(0,0,320,200); This example puts a 320x200 texture to screen and then grabs it into memory. NOTE: sglNewTexture() is NOT needed to get a texture as this function creates a new texture anyway. This function also returns -1 if an error occurs, and otherwise the texture id.
This command creates a new texture that is the height and width supplied. The id is returned. sglSolidColour() & sglTextureMap() can be used as a parameter to CLEAR FILLING TYPE to clear the texture once it is created or if 0 is specified, then it is not cleared. This function returns -1 and not 0 if and error occurs.
This command makes a texture of an existing buffer by passing the offset to the data and specifying the width and height of it. No actual texture is copied or generated, but just a pointer to the buffer specified is saved meaning as you alter the buffer the texture is changed.
This is not function is needed as the dll automatically frees textures at the end UNLESS you want to free this texture slot and its data to use again (assuming you have used up all the texture slots).
This is similar to sglFreeTexture() but it does not free the texture data, but only free's up the texture slot. This function would be used in conjunction with a texture created with MakeTexture() as the actual texture data does not belong to sgl (or if it does it's part of another texture)
This copies a portion of the current RB (by default DIV's background) to the texture specified. All co-ordinates need to be posative. A suitable texture already needs to exist for this function, unlike sglGrabTexture.
This returns the texture offset in memory of the texture <id> supplied. Mainly used as the first parameter of sglSetNewRB() to make rendering to textures possible
This returns the texture 's width
This returns the texture 's height
NOTE: Version 0.1.5.8 sprites are slow....speedup coming soon...
This sets the rendering perspective. By default this is 512 (0.5f in sgl's floating point conversion) It should be noted that changing the perspective drastically can cause large textured polygons to display incorrectly.
This just clears the RB (Div's screen by default) with a chosen colour. This is the same as DIV's Clear_Screen() but you can specify a colour. The buffer that is cleared depends on what the RB is set to. If you pass sglEntireArea() as an area parameter, the whole screen is
cleared.
This writes the current the sgl dll version to the STRING provided.The
string has to be a suitable length. The code supplied is for eg. STRING sglver; //creates a string called sglver .... sglVersion(sglver); // sets sglver with the current dll version write(0,10,10,0,sglver); // prints out sglver
This returns the distance of the pixel at any x,y screen co-ordinate
after it has been rendered and
This sets the zoom for the camera. The value is in 1024ths. so 1x zoom is
1024, 2x is 2048 ect.
This returns the current zoom level.
This sets the zoom for the camera to 1x. This is the same as calling: sglSetZoom(1024);
This sets the Rendering Buffer (the buffer which polygons are rendered to) to a custom buffer or a Texture. If all rendering will be done to this buffer you should set it before you call sglInit() to save you calling it twice. If you plan to switch between this and the normal buffer then if the buffers are different sizes you need to call sglInit() and sglViewport() again each time you switch to draw. example - say you wanted to render to a texture that is a different size to the DIV background screen: sglSetNewRB(sglTextureOffset(texture_id),sglTextureWidth(texture_id),sglTextureHeight(texture_id)); sglInit(); sglFullScreen(); sglClearZbuffer(); <Texture drawing commands> sglDefaultRB(); sglInit(); sglFullScreen(); sglClearZbuffer(); <normal drawing commands>
This sets the Rendering Buffer to the DIV screen background This RC is by default used, so you do not need to call it unless you are switching back from a custom Rendering Buffer.
This returns the video buffer's (DIV's final screen) memory offset. This can be used to set a new RB or simple use this as a texture using the sglMakeTexture() command.
This simply sets the camera's x,y&z 3D co-ordinates.
This sets the rotation for the desired camera Axis. Axis id's are 1,2&4 or alternatively, sglXAxis(),sglYAxis(),sglZAxis(). The Axis id's can be flagged so you can set multiple axis' at the same time. eg to set the x axis rotation to 0 you would call sglSetCameraAxisRotation(sglXAxis(),0); or to set ALL the axis' to 0 you would call sglSetCameraAxisRotation(sglAllAxis(),0); or sglSetCameraAxisRotation(sglXAxis() | sglYAxis() | sglZAxis() ,0);
This is similar to sglSetCameraAxisRotation() but instead of setting it the function returns the current camera axis rotation.
This is the same as sglSetCameraAxisRotation() but instead of setting the axis rotation it increments to axis rotation by the value given.
This sets the desired camera axis to the given value. Axis id's are 1,2&4 or alternatively, sglXAxis(),sglYAxis(),sglZAxis(). The Axis id's can be flagged so you can set multiple axis' at the same time. for exaple if you wanted to set the cameras hight to 0 you would call: sglSetCameraAxisPosition(sglYAxis,0);
This is the similar to sglSetCameraAxisPosition() but instead of setting it, the function returns the current axis position.
This moves the desired camera axis by the given value. Axis id's are 1,2&4 or alternatively, sglXAxis(),sglYAxis(),sglZAxis(). The Axis id's can be flagged so you can set multiple axis' at the same time. for exaple if you wanted to make the camera higher by 10 you would call: sglMoveCameraAxis(sglYAxis,10);
This advances the camera using the directions of the axis(s) given. Axis
id's are 1,2&4 or alternatively, sglXAxis(),sglYAxis(),sglZAxis(). The Axis
id's can be flagged so you can set multiple axis' at the same time. So sglAdvanceCamera(sglYAxis(),value would be similar to DIV's Advance(value). Multiple Axis' can be flagged so you can advance in all the directions the camera is facing.
This pushes the camera co-ordinates and rotations onto a stack (Stores
them). The stack depth is 200h (#256) in size by default meaning you can store
256 sets of camera
This simply brings back the last pushed set of camera
co-ordinates/rotations stored with
This sets the camera position and rotations to 0.
This is to be used in conjunction with Camera commands. This simply returns 1.
This is to be used in conjunction with Camera commands. This simply returns 2.
This is to be used in conjunction with Camera commands. This simply returns 4.
This is to be used in conjunction with Camera commands. This simply returns 7.
This loads an Md2 model into sgl Memory ready to be rendered. The function returns -1 if an error has occured or else it returns the Model ID for that particular model.
Because MD2 Models do not contain Texture Data, this function 'Binds' a texture to a model. This means when the model is rendered it will be rendered with the chosen texture (referenced by texture_id). The texture MUST be no smaller than the models default texture size.
This renders an md2 model that has been correctly loaded and textured. The frame is is the current model animation stage and is in 1024ths. so 0 would be the first frame 1024 would be the next frame and 512 would be inbetween. This means the animation can be made to go slow but still smooth. The x,y&z co-ordinates are where in 3D it is drawn. The rotateX,rotate,Y,rotateZ commands control the model z,y&z rotation and the scaleX,scaleY&scaleZ commands control the x,y&z scale.
This turns on Back Face Culling for a specified model in memory. Back Face
Culling is a On a Closed Model this on average eliminates 50% of polygons.
This method is automatically enabled when a model is loaded, you only
need to call this function
This disables Back Face Culling on a model. The only reasons why you need to
call this is if
Disabling Back Face Culling is not recommended as it is slower because
un-needed polygons
If a model is just rendered and Back Face Culling is enabled on that
model, this returns the number
This returns information of a model that is loaded into memory. The model id
must reference a valid
"SKINWIDTH"
"SKINHEIGHT"
"NUMVERTICES"
"NUMTEXCOORDS"
"NUMTRIANGLES"
"NUMFRAMES" Note: The parameters are not case-sensative. e.g.. sglGetModelInfo(0,"NumTriangles"); // This returns the polygon count of the model 0.
This copies the name of a model frame specified to a string by passing the
string offset.
This searches a model to find a frame that matches the frame_name
text. Wildcards (*) can be used. eg. frameid = sglModelFrame(0, "stand*", 0); This searches for the first frame that's name begins with "stand" and can have any other letter(s) beyond this. frameid = sglModelFrame(0, "stand*1", 0);
This searches for the first frame that's name begins with stand, has any 6th letter
and ends in '1'
This returns the texture x co-ordinate of a polygon in a model. The
polygon_id references the
This returns the texture y co-ordinate of a polygon in a model. The
polygon_id references the
This Creates a matrix slot in sgl memory that can then be rendered. This
commands does not struct MATRIX_Control
Matrix_Tiles_Width; End
In the above structure the matrix tiles width & height indicates the
vertical and horizontal amount of tiles
The tile_x_size & tile_z_size indicates the size of a single tile in the
matrix.
The Texture_array is a simple array that holds the infomation for all the
tiles texture ids. The array should
This means even after you have created a matrix you can alter a tiles
height, texture, a matrix's
sglMakeMatrix() returns the matrix id which is used to reference the
particular matrix.
This discards a matrix and frees up the texture slot to be used again. THIS
DOES NOT FREE UP MEMORY
This renders a matrix by passing the matrix id. No other parameter are
needed as the matrix is controlled
This gets the height (y) of a matrix at a specified x & z point. Remember a
matrix's x& z offset
Tagging is a system that allows the user to render polygons in any order,
tagging select ones, and after be able to It is recommended when you do not need tagging you turn it off (very slight speedup) Tagging is perfect for shooting games as you can tag each enemy with a
unique number then
This turns tagging off. This is by default.
This clears the Tag buffer (with the #0). If you are using tagging you need to call this every frame before drawing just like you would call sglClearZbuffer(). If you pass sglEntireArea() as an area parameter, the whole Tag
buffer is cleared.
if you are going to check for a specific model or polygon then before you
render it, set the active tag to
Returns the current active Tag.
This checks a specific pixel on screen and returns the tag number of that pixel.
When this is turned on, if a model or matrix is drawn, the active tag is
increased each time a polygon
When this is called auto incrementing is turned off (by default it is off
anyway). This means if you render a
This blitzes an sgl texture to the Rendering Buffer(by default the DIV background).
|