sgl.html sgl_minimal.html sgl_Tips.html sgl_TroubleShooting.html

sglv0.16

This document is intended to be viewed in Internet Explorer
sgl <software graphics library> Version 0.16
Written by Antzrhere (Antzrhere@hotmail.com)

Disclaimer

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.

Sgl and the author of sgl is in no way affiliated with Hammer Technologies or Fastrak Publishing company.

License

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
    including it in your own packages.

2. Altered source versions or custom packages that include parts of the original sgl package
    must be plainly marked as such, and must not be misrepresented as being the
    original software.

3. You may not charge for the original sgl package although you may charge for
     software that you have created that utilises or includes sgl in any way.
 

What Is Sgl?

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
is not as accurate as say Opengl or Direct3D (which i assume uses 64-bit+ floating point math.
This is in order or speed up calculations as the fpu's on Intel's in practice slower.

v0.159 Specifications

● (fast) Solid & (slow) Textured (8-bit) Mapped Triangular primitive polygons with transparencies
● Perspective corrected [1/w] Z-Buffering & texturing.
● High Level Md2 Model Loading/Animation/Rendering Commands
● Low level single triangular polygon rendering routines
● Back Face Culling (on models) <coming soon for single polygons>
● Coloured customisable Z Fogging (5-bit colour transition)
● Camera Pop/Push Commands
● Polygon/model tagging. Enables you to check for a polygon/model at any x,y screen
   co-ordinate. Perfect for 3D shooting games.
● Matrices with back face/front face culling and Matrix commands (like Darkbasic :-) )
● Scaling for all global resolutions and viewport resolutions.
● Simple 3D & 2D clipping routines
● Split/multiple Screen Ability
● Ability to change the rendering buffer to a new custom buffer or Texture
● All grabable Textures sizes Supported (>=1x1 <=1024x768)
 

Changes/History

 

v0.6

●Small speedup and memory op by switching to 16bit zbuffering, a few asm ops and a faster memory clearing.
  Upto 10% faster.

●Added textured polygon transparencies (with variable colour)
  New commands are sglEnableTransparencies(),sglDisableTransparencies() & sglSetTransparentColour(col)

v0.159

Rewrote sglGetMatrixHeight() because is still had some major bugs that I couldn't patch over
  New method is smaller, faster and *hopefully* bug free.
Added zooming and appropriate commands.
Sorted out version numbers :P. Really is should be v0.159 NOT v0.1.5.9 as pointed kindly out
   by Retep.
●sglGetZBufferDistAtXY() was actually added last version but not mentioned.
●sglClearTagBuffer now doesn't accept an id...the buffer is simply cleared with 0. Had to change
because i realised you couldn't clear a 16-bit buffer with an 8-bit value properly :P
●Sprites....arrgh....the new faster way drew black transparent areas so I had to switch back...
don't know why....AND they weren't fog compatible....fixed now...

v0.158

Made polygons more seamless after I saw occasional minor gaps when using matrixes.
Fixed small bug which cut drawing off by 1 pixel (x&y) at the upper limits.
sgl3Dsprite...many bugs :P...all fixed now :
i) Accidentally took the 4th parameter as the texture id instead of the first.
ii) Wasn't zbuffered!..yeah..I must have missed that function! :P
....And I also added a speedup for checking the colour
Added tagging. This means you can 'tag' a polygon/model/sprite with an id number, render
  everything and then check what polygon/model is visible at any x,y co-ordinate on screen.
  PERFECT for 3d shooting games. This is similar to object logging with ModeA, but faster.
Hopefully I've fixed a potential bug with sglGetMatrixHeight()
I just discovered that sglSetViewport() and sglMaxViewport were all messed up and stored
incorrect dimensions (+1 pixel)...for some reason though this seemingly worked okay for a while
with dodgy clipping which must of compensated for it, although sometimes it made div crash on
exit. Well thats all fixed now and the view port functions are all correct and clipping is corect..
I also fixed sprite clipping which was off by -1 pixel horizontally and would cull a sprite if it
had 1 vertical scan line to draw...that's fixed now..
●sglClearZbuffer() sglClearTagBuffer & sglClearRB() now accept an area parameter.
if sglEntireArea() [0] is passed the whole buffer is cleared irrelevant of the viewport..and
if sglRenderableArea() [1] is passed only the viewport area is cleared...this is faster when
not the whole screen is a renderable area...

 

v0.157

Cut out the need to call sglResetModelInfo or sglResetTextureInfo(). Now does it on execution
●Md2 models now will render with ANY sized texture independent of the model (co-ordinates are auto scaled)
  (Previously it was only possible with the size specified in the model file as the skinWidth)
●sgl3DSprite now accepts texture id as the first parameter instead of the last (made more sense) and fixed
   parameter error with the sgl3Dsprite documentation.
●Set default perspective to 512 (0.5f) cause everything looks so much cooler :P
●Added colour Fogging to all polygons :)
●Added clipping to model polygons
●Added sglAdjustToPalette() to adjust to a new palette.
●Fixed MASSIVE bug that caused Div to crash if you tried to render more than 1 model :/...:)
●Added MATRIXES! ..:)..and commands that go along with it...plus sglGetMatrixHeight() :)
   AND matrix back/front face culling
● SpellCheck!...Discard is not spelt 'disgard' ....changed to sglDiscardTexture() :P :P :P :P
● Changed sglTextureMap() & sglTextureMapf() to sglTriTextureMap() and sglTriTextureMapf()
   to add compaitability with different textured polygons in the future (quads ect)
   Changed sglBlitzTexture to sgl2D_BlitzTexture(). From now on all specific 2D drawing commands
    are going to be 'sgl2D_*'. Changed sglRenderMd2Model() and sglLoadMd2Model() to
   simply sglRenderModel() and sglLoadModel() to add future compatibility.
● Added sglFindMd2ModelFrame() which searches for a named frame with wildcards..and
   sglGetMd2ModelFrameName().

v0.149

●First stable version of sgl. Textured & untextured polygons working. Md2 models with backface culling
  working.

 

Command List (/74)

All sgl dll commands begin with "sgl" eg. sglLoadModel().
I have categorised all commands into there type usage.

 

Basic Fundamental Commands

 

sglinit()

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.

sglSetViewport(x0,y0,x1,y1)

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.

sglSetMaxViewport()

This sets the viewport to maximum. This does the same as sglSetViewport(0,0,screen_x_size-1,screen_y_size-1)

 

sglRenderableArea()

This refers to the screen viewport dimensions. This is simply a parameter of
sglClearRB(), sglClearZbuffer() or sglClearTagBuffer().

 

sglEntireArea()

This refers to the entire screen dimensions, regardless of the viewport. This is simply a parameter of
sglClearRB(), sglClearZbuffer() or sglClearTagBuffer().

 

sglClearZbuffer(area)

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()

If you pass sglEntireArea() as an area parameter, the whole zbuffer is cleared.
If you pass sglRenderablerea() as an area parameter, the only the zbuffer that is in the viewport is
cleared (faster)

sglPolygon3v(x0,y0,z0,x1,y1,z1,x2,y2,z2,<FILLING TYPE>)

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)

NOTE: if you wish to texture map polygons, keep the size no larger than 10,000 or you may
notice that texturing may start to jump about a bit and look ugly. This is because the core uses 32-bit fixed
point math and therefore is not as accurate as I'd like it to be .

 

sglSolidColour(colour)

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'.

 

sglTextureMap(Texture ID, tx0, ty0, tx1, ty1, tx2, ty2)

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.

 

sglTextureMapf(Texture ID, tx0_percent, ty0_percent, tx1_percent, ty1_percent, tx2_percent, ty2_percent)

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.

 

sglEnableZbuffering()

This enables Z-Buffering on all polygons/models when drawing. Z-Buffering is by default is enabled, so you
don't need to call this function unless it has been previously disabled and you want to re-enable it.

Z-Buffering is the most popular way of accurately ordering polygons and is used in Opengl & Direct3D.
 

sglDisableZbuffering()

This Disables Z-Buffering on all polygons/models when drawing. Disabling Z-Buffering means polygons are
ordered in the sequence they are drawn. The only use of disabling Z-Buffering is if you wish to do
2D drawing on top of a 3D scene, or you want to speed up polygon drawing on polygons that do
not need to be sorted (i.e.. A sky box which will always be drawn on top of).

The later method is recommended for large background polygons that will be drawn on top of every time.
 

sglSetFog(colour,Intensity,Distance)

This effectively turns fogging on by setting the fog colour, max intensity and distance.
The colour is the fog colour and must be between 0 and 255. The intensity is the effect fog has at maximum effect.
This is a percentage and must be between 0 and 100.
The distance is the distance before the fog is at its densest. 1 represents an sgl distance of 1024 and 2 = 2048 ect.
The maximum distance is 16383. This means fog distance is only effective in 1024 (z) jumps.

sglNoFog()

This effectively turns fogging off. Fogging is automatically off by default unless turned on.

 

sglAdjustToPalette()

This simply adjusts the dll if the game palette has changed at all. If you have loaded an fpg with a different
palette than the original fpg or you have loaded a new palette, then call this straight after so things
don't look messed up. sgl Textures are not effected to changed in any way by calling this function.

 

sglEnableTransparencies()

When this is called and then when texture mapped polygons are rendered, any transparent pixels
won't be drawn. The transparent colour is by default 0, but can be set with sglSetTransparentColour().
When transparencies are enabled texture mapped polygons are slightly slower, so disable it when you
don't need it.
 

 

sglDisableTransparencies()

This simply prevents transparent colour pixels in a texture mapped polygon are drawn. This is done by default
and is slightly faster.


 

sglSetTransparentColour(colour)

This allows you to set the colour of transparent pixels (0 by default). This only takes effect when transparencies are
enabled.
 

 

Texture creation/Loading Commands
If you are grabbing textures before you have called sglInit() you will need to set the Rendering Buffer to the screen (assuming that is your desired RB) by calling SglSetDefaultRB().

 

sglGrabTexture(x0,y0,x1,y1)

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.

 

sglNewTexture(height,width,<CLEAR FILLING TYPE>)

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.

 

sglMakeTexture(Data offset,height,width)

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.

 

sglFreeTexture(texture_id)

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).

 

sglDiscardTexture(texture_id)

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)

 

sglCopyRBtoTexture(texture_id,x0,y0,x1,y1)

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.

 

sglGetTextureOffset(texture_id)

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

 

sglGetTextureWidth(texture_id)

This returns the texture 's width

 

sglGetTextureWidth(texture_id)

This returns the texture 's height

 

 

 MISC Command

 

sgl3DSprite(texture_id, x, y, z, x_scale, y_scale)

NOTE: Version 0.1.5.8 sprites are slow....speedup coming soon...
This renders a mode 7 style sprite in 3D similar to how you would render a polygon.
The x,y&z control the co-ordinates in 3D space. The x_scale and y_scale control the
horizontal and vertical size, and the texture id is the texture that is used.
Black areas of a texture (colour 0) are not drawn.

 

sglSetPerspective(perspective)

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.

 

sglClearRB(colour,area)

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.
If you pass sglRenderablerea() as an area parameter, the only the screen that is in the viewport is
cleared (faster)

sglGetVersion(String)

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
DIV 2 use only.

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

 

sglGetZbufferDistAtXY(x,y)

This returns the distance of the pixel at any x,y screen co-ordinate after it has been rendered and
before you have cleared the zbuffer again.

 

sglSetZoom(zoom_value)

This sets the zoom for the camera. The value is in 1024ths. so 1x zoom is 1024, 2x is 2048 ect.
The value must be greater or equal to 1.
REMEMBER zooming by 10x has the same quality effect as making the polygon 10x bigger...
large textured polygons  textures may start to jump.

 

sglGetZoom()

This returns the current zoom level.

 

sglResetZoom()

This sets the zoom for the camera to 1x. This is the same as calling:

sglSetZoom(1024);

 

 Rendering Buffer (RB) Manipulation Commands

 

sglSetNewRB(buffer_offset,buffer_x_size,buffer_y_size)

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>

 

sglSetDefaultRB()

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.

 

sglGetVideoBufferAddress()

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.

 

Camera Commands

 

sglSetCameraXYZ(x,y,z)

This simply sets the camera's x,y&z 3D co-ordinates.

 

sglSetCameraAxisRotation(Axis_ID,value)

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);

 

sglGetCameraAxisRotation(Axis_ID)

This is similar to sglSetCameraAxisRotation() but instead of setting it the function returns the current camera axis rotation.

 

sglRotateCameraAxis(Axis_id,value)

This is the same as sglSetCameraAxisRotation() but instead of setting the axis rotation it increments to axis rotation by the value given.

 

sglSetCameraAxisPosition(Axis_id,value)

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);

sglGetCameraAxisPosition(Axis_id,)

This is the similar to sglSetCameraAxisPosition() but instead of setting it, the function returns the current axis position.

 

sglMoveCameraAxis(Axis_id,value)

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);

 

sglAdvanceCamera(sglAxis,value)

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.
sglZAxis can be passed as a flag, but no effect will take place.

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.

 

sglPushCamera()

This pushes the camera co-ordinates and rotations onto a stack (Stores them).
This means you can have a camera position/rotation, store it, change it and then
recall it all back by calling sglPopCamera().

The stack depth is 200h (#256) in size by default meaning you can store 256 sets of camera
co-ordinates/rotations at one time.

sglPopCamera()

This simply brings back the last pushed set of camera co-ordinates/rotations stored with
sglPopCamera(). Remember the order that you pop cameras has to be the opposite order you
pushed them (if you are popping/pushing more than 2 cameras).

 

sglResetCamera()

This sets the camera position and rotations to 0.

 

sglXAxis()

This is to be used in conjunction with Camera commands. This simply returns 1.

 

sglYAxis()

This is to be used in conjunction with Camera commands. This simply returns 2.

 

sglZAxis()

This is to be used in conjunction with Camera commands. This simply returns 4.

 

sglAllAxis()

This is to be used in conjunction with Camera commands. This simply returns 7.

 

 

Model Commands

 

sglLoadModel(<filename>)

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.

 

sglBindTextureToModel(model_id,tetxure_id)

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.

 

sglRenderModel(model_id,frame,x,y,z,rotateX,rotateY,rotateZ,scaleX,scaleY,scaleZ)

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.

sglEnableModelBFCulling(model_id)

This turns on Back Face Culling for a specified model in memory. Back Face Culling is a
method of only drawing polygons that are facing the user and for the majority visible.

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
to re-enable Back Face Culling if it has been disabled for a particular model.

 

sglDisableModelBFCulling(model_id)

This disables Back Face Culling on a model. The only reasons why you need to call this is if
Back Face culling is eliminating visible polygons or if the model is not closed.

Disabling Back Face Culling is not recommended as it is slower because un-needed polygons
are rendered.

 

sglLastPolygonsCulled()

If a model is just rendered and Back Face Culling is enabled on that model, this returns the number
of polygons that were culled, allowing you to calculate how many polygons were actually
rendered on and off screen.

 

sglGetModelInfo(model_id,<Info>)

This returns information of a model that is loaded into memory. The model id must reference a valid
model. The different parameters you can pass for 'info' are in text format and are as follows:

"SKINWIDTH"
The width of the models "skin' or texture map.

"SKINHEIGHT"
The height of the models "skin' or texture map.

"FRAMESIZE"
The size of each frame in bytes

"NUMVERTICES"
The number of Vertices in the polygon

"NUMTEXCOORDS"
The number of Texture Co-ordinates

"NUMTRIANGLES"
The number of Triangles or Polygons in the model

"NUMFRAMES"
The number of animation frames in the model

Note: The parameters are not case-sensative.

e.g..

sglGetModelInfo(0,"NumTriangles"); // This returns the polygon count of the model 0.

 

sglGetModelFrameName(model_id,frame_id,String Offset)

This copies the name of a model frame specified to a string by passing the string offset.
This is a Div 2 + compatible command only.

 

sglFindModelFrame(model_id,frame_name, ignore_size)

This searches a model to find a frame that  matches the frame_name text. Wildcards (*) can be used.
Wildcards is a character '*' and can be used to substitute individual letters or at the end of the frame_name to ignore any letters passed this point. Unlike windows a wildcard at the start simply substitutes 1 character and not an infinite amount. If Ignore Size is set to 1, the function will ignore the first valid match found
and continue to search for more. If it is said to 2 it will ignore the first two matches.. and so forth. The purpose of
this is so that you can find all the frames that fulfil the search criteria and not just the first one. If you ignore too many matching frames, the function simply returns the last matching frame id. The function returns the frame id that matches the criteria. If no frame is found at all the function returns -1. If an invalid model/frame is given the function returns -2. SEARCHING IS CASE SENSITIVE!

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'
(e.g.. "stand11" or "stand21")

 

 

sglGetModelTextureCoordX(model_id,Polygon_id,Vertex_id)

This returns the texture x co-ordinate of a polygon in a model. The polygon_id references the
polygon in the model and must not be greater or equal the number of polygons in that model.
The vertex must be either 0,1 or 2.

 

sglGetModelTextureCoordY(model_id,Polygon_id,Vertex_id)

This returns the texture y co-ordinate of a polygon in a model. The polygon_id references the
polygon in the model and must not be greater or equal the number of polygons in that model.
The vertex must be either 0,1 or 2.

 

Matrix Commands

 

sglMakeMatrix(Control_struct_offset, Height_array_offset, Texture_array_offset)

This Creates a matrix slot in sgl memory that can then be rendered. This commands does not
create a a matrix, but you do this in DIV's memory and then pass the offsets to the memory.
The DIV memory must be GLOBAL.
The Control_struct controls the matrix main info. This is what is should look like in Div:

struct MATRIX_Control

Matrix_Tiles_Width;
Matrix_Tiles_Height;
x, y, z;
Tile_x_Size;
Tile_y_scale;
Tile_z_Size;
Textured_Mode;
Culling_Type;

End

In the above structure the matrix tiles width & height indicates the vertical and horizontal amount of tiles
The x,y&z control the matrix postion.

The tile_x_size & tile_z_size indicates the size of a single tile in the matrix.
The Tile_y_scale is a vertical scalar for the whole matrix.
If Textured_Mode is set to 1 then textures are used, otherwise the texture_id's are solid Colours.
If Culling_type is set to 0, no culling (hidden face removal) is carried out. If it is set to 1, back face
culling is carried out. If it is set to 2, front face culling is carried out.
For most occasions back face culling (#1) is used as it faster than no culling, however some
times this may cause graphical glitches on double sided polygons in which case you should select
No culling (#0) which is slower.

The Height_array is a simple array that holds the infomation for all the tiles height. The array should
1 wider than the amount of horizontal tiles and 1 wider than the amount of vertical tiles eg.
the array would be 8*6 big for a 7*5 matrix. Structures can be used but the data must be linear so
arrays are more suitable. Tile data is read from left to right, top to bottom.

The Texture_array is a simple array that holds the infomation for all the tiles texture ids. The array should
same size as the matrix's width*height.

This means even after you have created a matrix you can alter a tiles height, texture, a matrix's
x scale, y scale size ect. by just changing the data in DIV.

sglMakeMatrix() returns the matrix id which is used to reference the particular matrix.
A negative number is returned if there are no more matrix slots left.

 

sglDiscardMatrix(Matrix_id)

This discards a matrix and frees up the texture slot to be used again. THIS DOES NOT FREE UP MEMORY
as matrix data is in Div.

sglRenderMatrix(Matrix_id)

This renders a matrix by passing the matrix id. No other parameter are needed as the matrix is controlled
by the matrix's structures and arrays in Div Memory.

 

sglGetMatrixHeight(Matrix_id,x ,z)

This gets the height (y) of a matrix at a specified x & z point. Remember a matrix's x& z offset
is included in the x & z parameters.. e.g. if a matrix's X offset  has been shifted +1000, any x parameter you
pass to sglGetMatrixHeight() that is smaller than +1000 will not actually be part of the matrix.
Any value that is returned also takes into account the matrix's y offset. If you try and check an area where
a matrix doesn't exist, the function will just return the matrix's y offset.

 

Tagging Commands

 

sglEnableTagging()

Tagging is a system that allows the user to render polygons in any order, tagging select ones, and after be able to
take a x and y screen co-ordinate and check which polygon/model is at that pixel.
 
This simply turns tagging on. Tagging must be on for all polygons, even if you only need to check
for one polygon. The only exception is when you are rendering something that is always in the
background like a sky. In this instance you do not need tagging on when you draw this, but you
need to re-enable it when you draw other polygons.

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
after you can check the cross-air pixel and see which enemy (if there is one) is in the line
of the cross-air. This creates pixel-perfect bullet collisions.

sglDisableTagging()

This turns tagging off. This is by default.

 

sglClearTagbuffer(area)

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 pass sglRenderablerea() as an area parameter, the only the Tag buffer that is in the viewport is
cleared (faster)

 

sglSetActiveTag(tag_number)

if you are going to check for a specific model or polygon then before you render it, set the active tag to
a specific number, render the model/polygon then set it back to 0. This means when you check at a
specific pixel, if that polygon/model is there it will return your number.

The number has to between 0 and 65535.
 

sglGetActiveTag()

Returns the current active Tag.

 

sglGetTagAtXY(x,y)

This checks a specific pixel on screen and returns the tag number of that pixel.

 

sglAutoIncrementTagON()

When this is turned on, if a model or matrix is drawn, the active tag is increased each time a polygon
is rendered, meaning you can check the tag buffer and distinguish different polygons in a model
instead of a model having just one id for all the polygons.
 

sglAutoIncrementTagOFF()

When this is called auto incrementing is turned off (by default it is off anyway). This means if you render a
model or a matrix ALL the polygons in that model or matrix will have the same id and you
won't be able to distinguish them from each other.

 

2D Drawing Commands
All 2D commands begin with 'sgl2D_'

 

sgl2D_BlitzTexture(Texture ID,x,y)

This blitzes an sgl texture to the Rendering Buffer(by default the DIV background).