sparrowRenderer

SparrowRenderer is for rendering 3D stuff to the target of sparrowPrimitives.  Like sparrowPrimitves it provides triangles, quads (with and without texture), lines, ellipses, rectangles and blitting or rotozoom of surfaces, furthermore light calculation.  Like other 3d libraries (e.g.  OpenGL) sparrow3d uses matrizes for the orientation and position in space.

Summary
sparrowRendererSparrowRenderer is for rendering 3D stuff to the target of sparrowPrimitives.
Light
SP_MODELVIEW_STACK_SIZEThe maximum depth of spPushModelView and spPopModelView Operations
spPointa point struct with space, modelview and projected coordinates
spTexPointa point struct with space, modelview, projected and texture coordinates and the w clip
spEdgeedge struct for meshes.
spTriangleSA triangle struct for meshes.
spQuadSA triangle struct for meshes.
spModelContains a mesh.
spLightStruct for light sources.
Operations for the MatrizesLike other 3d libraries like OpenGL, sparrow3d uses homolog 4x4 matrizes for the orientation in space, too.
spSetFrustumf2Function for setting up the frustom of the projection matrix.
spSetPerspectiveSets the projection matrix.
spSetPerspectiveStereoscopicSets and returns a projection matrix for steroscopic viewing, so most of the times you will call this function for each eye once.
spStereoCreateProjectionMatrixesUse this function, if you want two projection matrixes with the given eye distance for stereoscopic projection.
spGetProjectionMatrixReturns the projetion matrix pointer.
spGetMatrixReturns you the REAL modelview matrix pointer! 
spPushModelViewSaves the recent ModelView matrix on a stack.
spPopModelViewLoads the ModelView matrix from the stack.
spIdentitySets the modelview matrix to the identity matrix.
spMulMatrixMultiplies the modelview matrix with the given matrix.
spMulMatrixLeftMultiplies the modelview matrix with the given matrix, but from the left side.
spScalespScale scales the modelview matrix.
spRotateRotates rad radians around the vector (x,y,z).
spRotateXRotates rad radians around the x-axis.
spRotateYRotates rad radians around the y-axis.
spRotateZRotates rad radians around the z-axis.
spTranslateThis function does a relative translation to (x,y,z).
Light functionsOnly ”Real” 3D functions (except spLine3D) are enlighted.
spSetLightSets Light Calculation on or off.
spEnableLightSpecifies, whether a light is used or not for the light calculation.
spSetLightColorSets the color of a light
spSetLightPositionSets the Light Position.
spUpdateLightIf you want to update the lights position without a recall of spSetLightPosition use this function.
spSetAmbientLightColorSets the global ambient light value.
“Real” 3D functionsThese functions are for drawing 3d primitives in space with light calculation, rotation and so on.
spTriangle3DDraws a triangle in 3D space.
spQuad3DDraws a quad in 3D space.
spTriangleTex3DDraws a textured triangle in 3D space.
spQuadTex3DDraws a textured quad in 3D space.
spMesh3DDraws a mesh in 3D space.
spMesh3DwithPoslike spMesh3D, but with an additional position.
spLine3DDraws a line in the 3d space with the given color.
“Billboard” 3D FunctionsFor these functions the position and size are projected, but the rotation is always, that you see the front (also called “billboard”).
spRotozoomSurface3DDraws a rotozoomed surface in 3d space.
spRotozoomSurfacePart3DDraws a rotozoomed part of a surface in 3d space.
spRectangle3DDraws a billboard rectangle in 3d space.
spCollapsePrimitivesDetermines, whether ellipses, rectangles, ellipses borders and rectangle borders can collapse to an (unseeable) object smaller than one pixel.
spEllipse3DDraws a billboard ellipse in 3d space.
spRectangleBorder3DDraws a billboard rectangle border in 3d space.
spEllipseBorder3DDraws a billboard ellipse border in 3d space.
“Blitting” 3D FunctionsVery much like the ”Billboard” 3D Functions, but the size and rotation is fix (0 and SP_ONE)!
spBlit3DBlits a surface in 3d space very fast.
spBlitPart3DBlits a part of a surface in 3d space very fast.
Optimization and other functionsSome optional optimizations and helpers.
spSetPerspectiveTextureMappingEvery of the ”Real” 3D functions with textures can be rendered with affine texture mapping what may look a bit “wobly” or perspectivly correct, which looks the best, but may be slower!
spProjectPoint3DProjects a point in the 3D scene.
spUsePrecalculatedNormalsDesides, whether the precalculated normal values of meshes are used or not.

Light

SP_MAX_LIGHTSmaximal count of lights.  However more would look shitty nevertheless.

SP_MODELVIEW_STACK_SIZE

The maximum depth of spPushModelView and spPopModelView Operations

spPoint

a point struct with space, modelview and projected coordinates

Variables

x,y,z (Sint32)coordinates in space
tx,ty,tz (Sint32)with modelview multiplied coordinates
px,py,pz (Sint32)projected coordinates

spTexPoint

a point struct with space, modelview, projected and texture coordinates and the w clip

Variables

x,y,z (Sint32)coordinates in space
tx,ty,tz (Sint32)with modelview multiplied coordinates
px,py,pz (Sint32)projected coordinates
u,v (Sint32)texture coordinates
w (Sint32)w clip

spEdge

edge struct for meshes.

Variables

point (int*)array of the two points, which create an edge
status (int)flag after drawing (optional), whether the edge is in the background (-1), in the foreground (1) or at the border (0)

spTriangleS

A triangle struct for meshes.

Variables

point (int*)Array of 3 references to points
was_drawn (int)determines, where the triangle was drawn the last time: 0 = not drawn, else 1 screen, 2 left, 4 lefttop, 8 top, 16 righttop, 32 right, 64 rightbottom, 128 bottom, 256 leftbottom
edge (int*)Array of 3 references to edges
normal (Sint32)Array with 3 fixed point numbers as normal
pNormal (Sint32)Array with 3 fixed point numbers as projected normal

spQuadS

A triangle struct for meshes.

Variables

point (int*)Array of 4 references to points
was_drawn (int)determines, where the quad was drawn the last time: 0 = not drawn, else 1 screen, 2 left, 4 lefttop, 8 top, 16 righttop, 32 right, 64 rightbottom, 128 bottom, 256 leftbottom
edge (int*)Array of 4 references to edges
normal (Sint32)Array with 3 fixed point numbers as normal
pNormal (Sint32)Array with 3 fixed point numbers as projected normal

spModel

Contains a mesh.  You can fill it on your own (have fun, it is a lot of work) or use sparrowMesh to load (e.g.) wavefront object files.  SparrowRenderer provides functions for drawing these meshes very fast.

Variables

texture (SDL_Surface*)the texture.  Sparrow3D Meshes only can have 1 texture
pointCount (int)number of points without texture coordinates in the mesh
point (spPoint*)pointer/array to pointCount spPoint structs
texPointCount (int)number of points with texture coordinates in the mesh
texPoint (spTexPoint*)pointer/array to texPointCount spTexPoint structs
triangleCount (int)numbers of untextured triangles in the Mesh
triangle (spTriangleS*)pointer/array to triangleCount spTriangleS structs
texTriangleCount (int)numbers of textured triangles in the Mesh
texTriangle (spTriangleS*)pointer/array to texTriangleCount spTriangleS structs
quadCount (int)numbers of untextured quads in the Mesh quad (spQuadS)- pointer/array to quadCount spQuadS structs
texQuadCount (int)numbers of textured quads in the Mesh
texQuad (spQuadS)pointer/array to texQuadCount spQuadS structs
edgeCount (int)numbers of untextured edges in the Mesh
edge (spEdge*)pointer/array to edgeCount spEdge structs
texEdgeCount (int)numbers of textured edges in the Mesh
texEdge (spEdge*)pointer/array to texEdgeCount spEdge structs
color (Uint16)16 bit colour of the whole mesh

spLight

Struct for light sources.

Variables

r,g,b (Uint32)fixed point color of the light.  (SP_ONE,SP_ONE,SP_ONE) is a bright white
x,y,z (Sint32)position of the light
tx,ty,tz (Sint32)translated position of the light
active (Sint32)determines, whether the light is enabled in calculation or not.  1 is on, 0 is off

Operations for the Matrizes

Like other 3d libraries like OpenGL, sparrow3d uses homolog 4x4 matrizes for the orientation in space, too.  These functions are for manipulating the projection and modelview matrix.  The last is for the orientation in space, the first for projecting from the 3d space to the 2d space of the screen.  Most of the times you will not have to change the matrizes on your own and you can just functions for manipulating them

spSetFrustumf2

PREFIX void spSetFrustumf2(Sint32 *matrix,
Sint32 left,
Sint32 right,
Sint32 bottom,
Sint32 top,
Sint32 znear,
Sint32 zfar)

Function for setting up the frustom of the projection matrix.  Most of the time you will not use this directly, but the perspective setting up functions do.

Parameters

matrixa pointer to at least 16 Sint32 values for the matrix
leftthe left border of the frustum
rightthe right border of the frustum
bottomthe bottom border of the frustum
topthe top border of the frustum
znearz position auf the near plane
zfarz position of the far plane

spSetPerspective

PREFIX void spSetPerspective(float fovyInDegrees,
float aspectRatio,
float znear,
float zfar)

Sets the projection matrix.  Because you call this function mostly just one time at beginning and the need of REALLY high accuracy, this is one of the rare functions from sparrow3d, which has floats as parameter.

Parameters

fovyInDegreesthe field of View in degrees.  45° is a good value
aspectRatiothe aspect ratio of the projection. width / height is a good value most of the times
znear,zfarthe nearest and farest value for the z ordinate

See Also

spSetPerspectiveStereoscopic

spSetPerspectiveStereoscopic

PREFIX void spSetPerspectiveStereoscopic(Sint32 *projectionMatrix,
float fovyInDegrees,
float aspectRatio,
float znear,
float zfar ,
float z0,
float distance)

Sets and returns a projection matrix for steroscopic viewing, so most of the times you will call this function for each eye once.  Because you call this function mostly just one time at beginning and the need of REALLY high accuracy, this is one of the rare functions from sparrow3d, which has floats as parameter.

Parameters

projectionMatrixa pointer to at least 16 Sint32 values for the calculated projection matrix
fovyInDegreesthe field of View in degrees.  45° is a good value
aspectRatiothe aspect ratio of the projection. width / height is a good value most of the times
znear,zfarthe nearest and farest value for the z ordinate
z0position of the null paralaxis.  That is the plane, where the left and right eye got the same image and it seems, that the object is at screen position while stereoscopic rendering
distancethe distance from the centre, for one eye positive, for one negative

See Also

spSetPerspective

spStereoCreateProjectionMatrixes

PREFIX void spStereoCreateProjectionMatrixes(Sint32 *left_matrix,
Sint32 *right_matrix,
float fovyInDegrees,
float aspectRatio,
float znear,
float zfar ,
float z0,
float distance,
int crossed)

Use this function, if you want two projection matrixes with the given eye distance for stereoscopic projection.  The projection matrix of sparrow3d is not set!  You have to set it with memcpy(spGetProjectionMatrix(),matrix,sizeof(Sint32)*16) by yourself.  For stereoscopic rendering, you have to render the scene two times with the colours of your 3d glasses and merge it afterwars, e.g. with spStereoMergeSurfaces (screen,right_screen,crossedEyes).

Parameters

left_matrix, right_matrixthe matrizes (pointer to at least 16 Sint32 values) of the left and right eye
fovyInDegreesthe field of View in degrees.  45° is a good value
aspectRatiothe aspect ratio of the projection. width / height is a good value most of the times
znear,zfarthe nearest and farest value for the z ordinate
z0position of the null paralaxis.  That is the plane, where the left and right eye got the same image and it seems, that the object is at screen position while stereoscopic rendering
distancethe distance from the centre, for one eye positive, for one negative
crosseddetermines, whether the you will use crossed eye or color merging for merging the two resulting projections.  For colored glassed use crossed=0, for two seperate images crossed=0

spGetProjectionMatrix

PREFIX Sint32* spGetProjectionMatrix(void)

Returns the projetion matrix pointer.  Be carefull: You get the real pointer, no copy.  Usefull for setting the projection matrix on yourself, e.g. while rendering stereoscopic:

spSelectRenderTarget(right_screen);
memcpy(spGetProjectionMatrix(),right_projection,sizeof(Sint32)*16);

Returns

Sint32*pointer to the projection matrix

See Also

spGetMatrix

spGetMatrix

PREFIX Sint32* spGetMatrix(void)

Returns you the REAL modelview matrix pointer!  That means, every change is directly updated.

Returns

Sint32*pointer to the modelview matrix

See Also

spGetProjectionMatrix

spPushModelView

PREFIX void spPushModelView(void)

Saves the recent ModelView matrix on a stack.  Get the last element of the stack with spPopModelView.

See Also

spPopModelView

spPopModelView

PREFIX void spPopModelView(void)

Loads the ModelView matrix from the stack.

See Also

spPushModelView

spIdentity

PREFIX void spIdentity(void)

Sets the modelview matrix to the identity matrix.  This resets the view.  If you now would draw something, it would be drawn to (0,0,0), without rotation and without scaling.

spMulMatrix

PREFIX void spMulMatrix(Sint32 *matrix)

Multiplies the modelview matrix with the given matrix.

Parameters

matrixa pointer to 16 Sint32 values

spMulMatrixLeft

PREFIX void spMulMatrixLeft(Sint32 *matrix)

Multiplies the modelview matrix with the given matrix, but from the left side.

Parameters

matrixa pointer to 16 Sint32 values

spScale

PREFIX void spScale(Sint32 x,
Sint32 y,
Sint32 z)

spScale scales the modelview matrix.  Use it with care, seems to be a bit buggy...

Parameters

x,y,zzoom parameters.  Set everything to SP_ONE to get no result

spRotate

PREFIX void spRotate(Sint32 x,
Sint32 y,
Sint32 z,
Sint32 rad)

Rotates rad radians around the vector (x,y,z).  Also a bit buggy. spRotate(X|Y|Z) are better most of the times.

Parameters

x,y,zaxis to rotate
radangle to rotate

See Also

spRotateX, spRotateY, spRotateZ

spRotateX

PREFIX void spRotateX(Sint32 rad)

Rotates rad radians around the x-axis.

Parameters

radangle to rotate around the x-axis

See Also

spRotate, spRotateY, spRotateZ

spRotateY

PREFIX void spRotateY(Sint32 rad)

Rotates rad radians around the y-axis.

Parameters

radangle to rotate around the y-axis

See Also

spRotate, spRotateX, spRotateZ

spRotateZ

PREFIX void spRotateZ(Sint32 rad)

Rotates rad radians around the z-axis.

Parameters

radangle to rotate around the z-axis

See Also

spRotate, spRotateX, spRotateY

spTranslate

PREFIX void spTranslate(Sint32 x,
Sint32 y,
Sint32 z)

This function does a relative translation to (x,y,z).

Parameters

x,y,zway to translate

Light functions

Only ”Real” 3D functions (except spLine3D) are enlighted.  You have up to 8 light sources (in fact, even more than 4 look shitty).

spSetLight

PREFIX void spSetLight(int value)

Sets Light Calculation on or off.  Default off (0)

Parameters

value0 means off, 1 means on

spEnableLight

PREFIX void spEnableLight(int number,
Sint32 active)

Specifies, whether a light is used or not for the light calculation.  (default: just number 0 is enabled)

Paramaters

numberthe light to (de)activate
active1 for turning on, 0 for switching off

spSetLightColor

PREFIX void spSetLightColor(int number,
Uint32 r,
Uint32 g,
Uint32 b)

Sets the color of a light

Parameters

numberthe light to change the color
r,g,bUint32 fixed point RGB color of the light

spSetLightPosition

PREFIX void spSetLightPosition(int number,
Sint32 x,
Sint32 y,
Sint32 z)

Sets the Light Position.  The Position will be transformed with the modelview matrix as it is at call!

Parameters

numberthe light to change position
x,y,znew position of the light

See Also

spUpdateLight

spUpdateLight

PREFIX void spUpdateLight(int number)

If you want to update the lights position without a recall of spSetLightPosition use this function.  This just multiplies the lights position with the modelview matrix to get the new position in camera space.

Parameters

numberthe light to update position

See Also

spSetLightPosition

spSetAmbientLightColor

PREFIX void spSetAmbientLightColor(Uint32 r,
Uint32 g,
Uint32 b)

Sets the global ambient light value.  This value is added to all other lights independing from position of the face in space.

Parameters

r,g,bFixed point Uint32 color value.  Default: 0.25, 0.25, 0.25

“Real” 3D functions

These functions are for drawing 3d primitives in space with light calculation, rotation and so on.

spTriangle3D

PREFIX int spTriangle3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
Sint32 x2,
Sint32 y2,
Sint32 z2,
Sint32 x3,
Sint32 y3,
Sint32 z3,
Uint16 color)

Draws a triangle in 3D space.  Returns 0 if not drawn (culling) or different bits, where the edges are: 1 screen, 2 left, 4 lefttop, 8 top, 16 righttop, 32 right, 64 rightbottom, 128 bottom, 256 leftbottom.

Parameters

x1,y1,z1position of the first triangle point in space
x2,y2,z2position of the second triangle point in space
x3,y3,z3position of the third triangle point in space
color16 Bit color of the triangle

Returns

intsee above

See Also

spTriangleTex3D, spQuad3D

spQuad3D

PREFIX int spQuad3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
Sint32 x2,
Sint32 y2,
Sint32 z2,
Sint32 x3,
Sint32 y3,
Sint32 z3,
Sint32 x4,
Sint32 y4,
Sint32 z4,
Uint16 color)

Draws a quad in 3D space.  Returns 0 if not drawn (culling) or different bits, where the edges are: 1 screen, 2 left, 4 lefttop, 8 top, 16 righttop, 32 right, 64 rightbottom, 128 bottom, 256 leftbottom.

Parameters

x1,y1,z1position of the first quad point in space
x2,y2,z2position of the second quad point in space
x3,y3,z3position of the third quad point in space
x4,y4,z4position of the fourth quad point in space
color16 Bit color of the quad

Returns

intsee above

See Also

spTriangle3D, spQuadTex3D

spTriangleTex3D

PREFIX int spTriangleTex3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
Sint32 u1,
Sint32 v1,
Sint32 x2,
Sint32 y2,
Sint32 z2,
Sint32 u2,
Sint32 v2,
Sint32 x3,
Sint32 y3,
Sint32 z3,
Sint32 u3,
Sint32 v3,
Uint16 color)

Draws a textured triangle in 3D space.  Returns 0 if not drawn (culling) or different bits, where the edges are: 1 screen, 2 left, 4 lefttop, 8 top, 16 righttop, 32 right, 64 rightbottom, 128 bottom, 256 leftbottom.  The used texture is determined with spBindTexture.

Parameters

x1,y1,z1position of the first triangle point in space
u1,v1texture position of the first triangle point
x2,y2,z2position of the second triangle point in space
u2,v2texture position of the second triangle point
x3,y3,z3position of the third triangle point in space
u3,v3texture position of the third triangle point
color16 Bit color of the triangle

Returns

intsee above

See Also

spTriangle3D, spQuadTex3D

spQuadTex3D

PREFIX int spQuadTex3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
Sint32 u1,
Sint32 v1,
Sint32 x2,
Sint32 y2,
Sint32 z2,
Sint32 u2,
Sint32 v2,
Sint32 x3,
Sint32 y3,
Sint32 z3,
Sint32 u3,
Sint32 v3,
Sint32 x4,
Sint32 y4,
Sint32 z4,
Sint32 u4,
Sint32 v4,
Uint16 color)

Draws a textured quad in 3D space.  Returns 0 if not drawn (culling) or different bits, where the edges are: 1 screen, 2 left, 4 lefttop, 8 top, 16 righttop, 32 right, 64 rightbottom, 128 bottom, 256 leftbottom.  The used texture is determined with spBindTexture.

Parameters

x1,y1,z1position of the first quad point in space
u1,v1texture position of the first quad point
x2,y2,z2position of the second quad point in space
u2,v2texture position of the second quad point
x3,y3,z3position of the third quad point in space
u3,v3texture position of the third quad point
x4,y4,z4position of the fourth quad point in space
u4,v4texture position of the fourth quad point
color16 Bit color of the quad

Returns

intsee above

See Also

spQuad3D, spTriangleTex3D

spMesh3D

PREFIX int spMesh3D(spModelPointer mesh,
int updateEdgeList)

Draws a mesh in 3D space.  Every time the was_drawn variable of every face is sets, which determines, whether the face was drawn (uneven 0) and where (like e.g. the return value of spTriangle3D).

Parameters

meshpointer to a spModel struct to be drawn
updateEdgeListdetermines, whether the edgeList shall be updated.  If 0, no update is made.  When 1 every edge is marked.  When 2 a solid body is assumed and “holes” (e.g. because of textured and untextured subbodys) are ignored.

Returns

intthe count of drawn faces

See Also

spMesh3DwithPos

spMesh3DwithPos

PREFIX int spMesh3DwithPos(Sint32 x,
Sint32 y,
Sint32 z,
spModelPointer mesh,
int updateEdgeList)

like spMesh3D, but with an additional position.

Parameters

x,y,zposition to draw to mesh
meshpointer to a spModel struct to be drawn
updateEdgeListdetermines, whether the edgeList shall be updated.  If 0, no update is made.  When 1 every edge is marked.  When 2 a solid body is assumed and “holes” (e.g. because of textured and untextured subbodys) are ignored.

Returns

intthe count of drawn faces

See Also

spMesh3D

spLine3D

PREFIX void spLine3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
Sint32 x2,
Sint32 y2,
Sint32 z2,
Uint16 color)

Draws a line in the 3d space with the given color.  No light calculation is done!

Parameters

x1,y1,z1the point from which the line should be drawn
x2,y2,z2the point to which the line should be drawn
color16 bit color of the line

“Billboard” 3D Functions

For these functions the position and size are projected, but the rotation is always, that you see the front (also called “billboard”).  No lighting, as it woudln’t make much sense with the face always showing in the same direction!

spRotozoomSurface3D

PREFIX void spRotozoomSurface3D(Sint32 x,
Sint32 y,
Sint32 z,
SDL_Surface *surface,
Sint32 zoomX,
Sint32 zoomY,
Sint32 angle)

Draws a rotozoomed surface in 3d space.  If father away, it gets smaller.  If you don’t want these effect evaluate zoomX and zoomY with the z-coordinate or use spBlit3D.

Parameters

x,y,zposition in 3d space
surfaceSDL_Surface* to be drawn
zoomX,zoomYx and y zoom of the surface
anglethe rotation of the surface in fixed point radian

See Also

spRotozoomSurfacePart3D, spBlit3D

spRotozoomSurfacePart3D

PREFIX void spRotozoomSurfacePart3D(Sint32 x,
Sint32 y,
Sint32 z,
SDL_Surface *surface,
Sint32 sx,
Sint32 sy,
Sint32 w,
Sint32 h,
Sint32 zoomX,
Sint32 zoomY,
Sint32 angle)

Draws a rotozoomed part of a surface in 3d space.  If father away, it gets smaller.  If you don’t want these effect evaluate zoomX and zoomY with the z-coordinate or use spBlitPart3D.

Parameters

x,y,zposition in 3d space
surfaceSDL_Surface* to be drawn
sx,syposition of the left top corner of the part of the surface to be drawn
w,hsize of the part to be drawn
zoomX,zoomYx and y zoom of the surface
anglethe rotation of the surface in fixed point radian

spRectangle3D

PREFIX void spRectangle3D(Sint32 x,
Sint32 y,
Sint32 z,
Sint32 w,
Sint32 h,
Uint16 color)

Draws a billboard rectangle in 3d space.

Parameters

x,y,zposition in 3d space
w,hwidth and height of the rectangle
color16 bit color of the rectangle

See Also

spRectangleBorder3D

spCollapsePrimitives

PREFIX void spCollapsePrimitives(int value)

Determines, whether ellipses, rectangles, ellipses borders and rectangle borders can collapse to an (unseeable) object smaller than one pixel.

Paramaters

value0 means, that the primitive do not collapse, if 1 for a specific distance it will not be drawn anymore (too small).  Default is 1.

spEllipse3D

PREFIX void spEllipse3D(Sint32 x,
Sint32 y,
Sint32 z,
Sint32 rx,
Sint32 ry,
Uint16 color)

Draws a billboard ellipse in 3d space.

Parameters

x,y,zposition in 3d space
rx,ryx and y radius of the ellipse
color16 bit color of the ellipse

See Also

spEllipseBorder3D

spRectangleBorder3D

PREFIX void spRectangleBorder3D(Sint32 x,
Sint32 y,
Sint32 z,
Sint32 w,
Sint32 h,
Sint32 bx,
Sint32 by,
Uint16 color)

Draws a billboard rectangle border in 3d space.

Parameters

x,y,zposition in 3d space
w,hwidth and height of the rectangle
bx,bywidth and height of the border
color16 bit color of the rectangle

See Also

spRectangle3D

spEllipseBorder3D

PREFIX void spEllipseBorder3D(Sint32 x,
Sint32 y,
Sint32 z,
Sint32 rx,
Sint32 ry,
Sint32 bx,
Sint32 by,
Uint16 color)

Draws a billboard ellipse border in 3d space.

Parameters

x,y,zposition in 3d space
rx,ryx and y radius of the ellipse
bx,bywidth and height of the border
color16 bit color of the ellipse

See Also

spEllipse3D

“Blitting” 3D Functions

Very much like the ”Billboard” 3D Functions, but the size and rotation is fix (0 and SP_ONE)!

spBlit3D

PREFIX void spBlit3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
SDL_Surface *surface)

Blits a surface in 3d space very fast.

Parameters

x1,y1,z1position in space
surfaceSDL_Surface* to be drawn

See Also

spRotozoomSurface3D, spBlitPart3D

spBlitPart3D

PREFIX void spBlitPart3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
SDL_Surface *surface,
Sint32 sx,
Sint32 sy,
Sint32 w,
Sint32 h)

Blits a part of a surface in 3d space very fast.

Parameters

x1,y1,z1position in space
surfaceSDL_Surface* to be drawn
sx,syposition of the left top corner of the part of the surface to be drawn
w,hsize of the part to be drawn

See Also

spRotozoomSurfacePart3D, spBlit3D

Optimization and other functions

Some optional optimizations and helpers.

spSetPerspectiveTextureMapping

PREFIX void spSetPerspectiveTextureMapping(int value)

Every of the ”Real” 3D functions with textures can be rendered with affine texture mapping what may look a bit “wobly” or perspectivly correct, which looks the best, but may be slower!

Parameters

value1 enables perspectively correct mapping, 0 disables.  0 is default

spProjectPoint3D

PREFIX void spProjectPoint3D(Sint32 x,
Sint32 y,
Sint32 z,
Sint32 *px,
Sint32 *py,
Sint32 *pz,
Sint32 *w,
Sint32 withModelview)

Projects a point in the 3D scene.  Usefull if you will draw your own stuff in the 3D world.

Parameters

x,y,z3d space point to project
px,py,pzpointer (!) to Sint32 coordinates, where to write the projection result
wpointer (!) to a Sint32 variable to save the w coordinate for w-clipping if needed
withModelviewsays, whether the rotation in the ModelViewMatrix should be involved.  E.g. if you want to get a perspective correct width, you don’t want the rotation.  In this case set it to 0.  Most of the time you should be fine with 1

spUsePrecalculatedNormals

PREFIX void spUsePrecalculatedNormals(int value)

Desides, whether the precalculated normal values of meshes are used or not.  So this works only with spMesh3D* functions.  Be carefull!  You can use this optimization only, if you don’t scale!  Translation and rotations are fine.  At default this feature is disabled.

Parameters

value1 enabled, 0 disabled (default)
PREFIX void spPushModelView(void)
Saves the recent ModelView matrix on a stack.
PREFIX void spPopModelView(void)
Loads the ModelView matrix from the stack.
PREFIX void spSetFrustumf2(Sint32 *matrix,
Sint32 left,
Sint32 right,
Sint32 bottom,
Sint32 top,
Sint32 znear,
Sint32 zfar)
Function for setting up the frustom of the projection matrix.
PREFIX void spSetPerspective(float fovyInDegrees,
float aspectRatio,
float znear,
float zfar)
Sets the projection matrix.
PREFIX void spSetPerspectiveStereoscopic(Sint32 *projectionMatrix,
float fovyInDegrees,
float aspectRatio,
float znear,
float zfar ,
float z0,
float distance)
Sets and returns a projection matrix for steroscopic viewing, so most of the times you will call this function for each eye once.
PREFIX void spStereoCreateProjectionMatrixes(Sint32 *left_matrix,
Sint32 *right_matrix,
float fovyInDegrees,
float aspectRatio,
float znear,
float zfar ,
float z0,
float distance,
int crossed)
Use this function, if you want two projection matrixes with the given eye distance for stereoscopic projection.
PREFIX Sint32* spGetProjectionMatrix(void)
Returns the projetion matrix pointer.
PREFIX Sint32* spGetMatrix(void)
Returns you the REAL modelview matrix pointer! 
PREFIX void spIdentity(void)
Sets the modelview matrix to the identity matrix.
PREFIX void spMulMatrix(Sint32 *matrix)
Multiplies the modelview matrix with the given matrix.
PREFIX void spMulMatrixLeft(Sint32 *matrix)
Multiplies the modelview matrix with the given matrix, but from the left side.
PREFIX void spScale(Sint32 x,
Sint32 y,
Sint32 z)
spScale scales the modelview matrix.
PREFIX void spRotate(Sint32 x,
Sint32 y,
Sint32 z,
Sint32 rad)
Rotates rad radians around the vector (x,y,z).
PREFIX void spRotateX(Sint32 rad)
Rotates rad radians around the x-axis.
PREFIX void spRotateY(Sint32 rad)
Rotates rad radians around the y-axis.
PREFIX void spRotateZ(Sint32 rad)
Rotates rad radians around the z-axis.
PREFIX void spTranslate(Sint32 x,
Sint32 y,
Sint32 z)
This function does a relative translation to (x,y,z).
These functions are for drawing 3d primitives in space with light calculation, rotation and so on.
PREFIX void spSetLight(int value)
Sets Light Calculation on or off.
PREFIX void spEnableLight(int number,
Sint32 active)
Specifies, whether a light is used or not for the light calculation.
PREFIX void spSetLightColor(int number,
Uint32 r,
Uint32 g,
Uint32 b)
Sets the color of a light
PREFIX void spSetLightPosition(int number,
Sint32 x,
Sint32 y,
Sint32 z)
Sets the Light Position.
PREFIX void spUpdateLight(int number)
If you want to update the lights position without a recall of spSetLightPosition use this function.
PREFIX void spSetAmbientLightColor(Uint32 r,
Uint32 g,
Uint32 b)
Sets the global ambient light value.
PREFIX int spTriangle3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
Sint32 x2,
Sint32 y2,
Sint32 z2,
Sint32 x3,
Sint32 y3,
Sint32 z3,
Uint16 color)
Draws a triangle in 3D space.
PREFIX int spQuad3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
Sint32 x2,
Sint32 y2,
Sint32 z2,
Sint32 x3,
Sint32 y3,
Sint32 z3,
Sint32 x4,
Sint32 y4,
Sint32 z4,
Uint16 color)
Draws a quad in 3D space.
PREFIX int spTriangleTex3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
Sint32 u1,
Sint32 v1,
Sint32 x2,
Sint32 y2,
Sint32 z2,
Sint32 u2,
Sint32 v2,
Sint32 x3,
Sint32 y3,
Sint32 z3,
Sint32 u3,
Sint32 v3,
Uint16 color)
Draws a textured triangle in 3D space.
PREFIX int spQuadTex3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
Sint32 u1,
Sint32 v1,
Sint32 x2,
Sint32 y2,
Sint32 z2,
Sint32 u2,
Sint32 v2,
Sint32 x3,
Sint32 y3,
Sint32 z3,
Sint32 u3,
Sint32 v3,
Sint32 x4,
Sint32 y4,
Sint32 z4,
Sint32 u4,
Sint32 v4,
Uint16 color)
Draws a textured quad in 3D space.
PREFIX int spMesh3D(spModelPointer mesh,
int updateEdgeList)
Draws a mesh in 3D space.
PREFIX int spMesh3DwithPos(Sint32 x,
Sint32 y,
Sint32 z,
spModelPointer mesh,
int updateEdgeList)
like spMesh3D, but with an additional position.
PREFIX void spLine3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
Sint32 x2,
Sint32 y2,
Sint32 z2,
Uint16 color)
Draws a line in the 3d space with the given color.
PREFIX void spRotozoomSurface3D(Sint32 x,
Sint32 y,
Sint32 z,
SDL_Surface *surface,
Sint32 zoomX,
Sint32 zoomY,
Sint32 angle)
Draws a rotozoomed surface in 3d space.
PREFIX void spRotozoomSurfacePart3D(Sint32 x,
Sint32 y,
Sint32 z,
SDL_Surface *surface,
Sint32 sx,
Sint32 sy,
Sint32 w,
Sint32 h,
Sint32 zoomX,
Sint32 zoomY,
Sint32 angle)
Draws a rotozoomed part of a surface in 3d space.
PREFIX void spRectangle3D(Sint32 x,
Sint32 y,
Sint32 z,
Sint32 w,
Sint32 h,
Uint16 color)
Draws a billboard rectangle in 3d space.
PREFIX void spCollapsePrimitives(int value)
Determines, whether ellipses, rectangles, ellipses borders and rectangle borders can collapse to an (unseeable) object smaller than one pixel.
PREFIX void spEllipse3D(Sint32 x,
Sint32 y,
Sint32 z,
Sint32 rx,
Sint32 ry,
Uint16 color)
Draws a billboard ellipse in 3d space.
PREFIX void spRectangleBorder3D(Sint32 x,
Sint32 y,
Sint32 z,
Sint32 w,
Sint32 h,
Sint32 bx,
Sint32 by,
Uint16 color)
Draws a billboard rectangle border in 3d space.
PREFIX void spEllipseBorder3D(Sint32 x,
Sint32 y,
Sint32 z,
Sint32 rx,
Sint32 ry,
Sint32 bx,
Sint32 by,
Uint16 color)
Draws a billboard ellipse border in 3d space.
For these functions the position and size are projected, but the rotation is always, that you see the front (also called “billboard”).
PREFIX void spBlit3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
SDL_Surface *surface)
Blits a surface in 3d space very fast.
PREFIX void spBlitPart3D(Sint32 x1,
Sint32 y1,
Sint32 z1,
SDL_Surface *surface,
Sint32 sx,
Sint32 sy,
Sint32 w,
Sint32 h)
Blits a part of a surface in 3d space very fast.
PREFIX void spSetPerspectiveTextureMapping(int value)
Every of the ”Real” 3D functions with textures can be rendered with affine texture mapping what may look a bit “wobly” or perspectivly correct, which looks the best, but may be slower!
PREFIX void spProjectPoint3D(Sint32 x,
Sint32 y,
Sint32 z,
Sint32 *px,
Sint32 *py,
Sint32 *pz,
Sint32 *w,
Sint32 withModelview)
Projects a point in the 3D scene.
PREFIX void spUsePrecalculatedNormals(int value)
Desides, whether the precalculated normal values of meshes are used or not.
SparrowMesh is for loading meshes (definied at sparrowRenderer.h).
a point struct with space, modelview and projected coordinates
a point struct with space, modelview, projected and texture coordinates and the w clip
A triangle struct for meshes.
A triangle struct for meshes.
edge struct for meshes.
PREFIX void spStereoMergeSurfaces(SDL_Surface *left,
SDL_Surface *right,
int crossed)
This functions merges two same sized (!)
PREFIX void spBindTexture(SDL_Surface *texture)
This texture will be used for all following draw operations with textures
Close