The SGADE Documentation

the SGADE The Socrates Gameboy Advance Development Engine

The SGADE is a development library for the Nintendo Gameboy Advance. It's free for all uses and is distributed without guarantees. For more information visit the SGADE page.


Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

SoMode4PolygonRasterizer

Functionality for all mode 4 polygon and triangle rendering. More...

Files

file  SoMode4PolygonRasterizer.c
file  SoMode4PolygonRasterizer.h

Functions

void SoMode4PolygonRasterizerInitialize (void)
 Initializes the rasterizer.

void SoMode4PolygonRasterizerSetBuffer (void *a_Buffer)
 Sets the backbuffer the rasterizer will render to.

void SoMode4PolygonRasterizerSetTexture (SoImage *a_Texture)
 Sets the texture the rasterizer should use for textured polygons.

void SoMode4PolygonRasterizerDrawTexturedPolygon (u32 a_NumVertices, SoVector2 *a_ScreenCoordinates, SoVector2 *a_TextureCoordinates)
 Draws a textured polygon.

void SoMode4PolygonRasterizerDrawSolidPolygon (u32 a_NumVertices, SoVector2 *a_ScreenCoordinates, u32 a_PaletteIndex)
 Draws a solid single color polygon.

void SoMode4PolygonRasterizerDrawSolidTriangleC (SoVector2 a_Triangle[3], u32 a_PaletteIndex)
 C version of the assembly solid triangle rasterizer;.

void SoMode4PolygonRasterizerDrawSolidTriangle (SoVector2 a_Triangle[3], u32 a_PaletteIndex)
 Draws a solid filled 2D triangle.


Variables

u16g_SoMode4PolygonRasterizerBuffer
 Pointer the polygon routines will render to.


Detailed Description

Functionality for all mode 4 polygon and triangle rendering.

Singleton

Module containing all routines to draw textured and solid and special case polygons and triangles. If you want kick ass double buffered full resolution 3D graphics on your Gameboy Advance, use this module.


Function Documentation

void SoMode4PolygonRasterizerDrawSolidPolygon u32    a_NumVertices,
SoVector2   a_ScreenCoordinates,
u32    a_PaletteIndex
 

Draws a solid single color polygon.

Parameters:
a_NumVertices  Number of vertices in the polygon.
a_ScreenCoordinates  Array of a_NumVertices SoVector2 objects, which are the vertices points of the triangle. All three need to be onscreen, in a fixed of the polygon. These need to be in fixed point format and on screen. This routine does not do any clipping.
a_PaletteIndex  Index in the screen palette to the color you want to draw the polygon with.
Warning:
This function is is rather slow. It was the second thing I've ever written for the GBA and some things just need to be done better befor you can use this in an a commercial or otherwise important product. For example, you shouldn't be drawing polygons, but triangles. This routine uses edge tables, which means slow nasty memory reads everywhere.
If you really want a fast polyfiller, subdivide your polygons in triangles and use SoMode4RasterizerDrawSolidTriangle instead.

void SoMode4PolygonRasterizerDrawSolidTriangle SoVector2    a_Triangle[3],
u32    a_PaletteIndex
 

Draws a solid filled 2D triangle.

Parameters:
a_Triangle  Array of 3 SoVector2 objects, which are the three corner points of the triangle. All three need to be onscreen, in a fixed point format. This routine does not do any clipping.
a_PaletteIndex  Color you want to draw the triangle with.
This routine draws a filled (flat or solid or whatever you want to call it) triangle in the current SoMode4PolygonRasterizer backbuffer. This backbuffer is set by using the SoMode4PolygonRasterizerSetBuffer function.

void SoMode4PolygonRasterizerDrawSolidTriangleC SoVector2    a_Triangle[3],
u32    a_PaletteIndex
 

C version of the assembly solid triangle rasterizer;.

I actually implemented this one first, and then converted it to assembly;

void SoMode4PolygonRasterizerDrawTexturedPolygon u32    a_NumVertices,
SoVector2   a_ScreenCoordinates,
SoVector2   a_TextureCoordinates
 

Draws a textured polygon.

Parameters:
a_NumVertices  Number of vertices in the polygon.
a_ScreenCoordinates  Array of a_NumVertices SoVector2 objects, which are the vertices points of the triangle. All three need to be onscreen, in a fixed of the polygon. These need to be in fixed point format and on screen. This routine does not do any clipping.
a_TextureCoordinates  Array of a_NumVertices SoVector2 objects that represent the texture coordinates of the polygon.
Warning:
This function is is rather slow. It was the first thing I've ever written for the GBA and some things just need to be done better befor you can use this in an a commercial or otherwise important product. For example, you shouldn't be drawing polygons, but triangles. This routine uses edge tables, which means slow nasty memory reads everywhere. Besides, it's not affine, thus slow.
If you really want a fast texturemapper, keep bugging me and I'll write you one. Or even better, write it yourself (in assembly ofcourse) and submit it for the SGADE.

void SoMode4PolygonRasterizerInitialize void   
 

Initializes the rasterizer.

Make this the first function you call before any other SoMode4Rasterizer functions. Returns immediately if this method has been called before.

Make sure you have already called SoMode4RendererEnable too.

void SoMode4PolygonRasterizerSetBuffer void *    a_Buffer
 

Sets the backbuffer the rasterizer will render to.

Parameters:
a_Buffer  Pointer to the start of a 240 x 160 x 8 bit buffer.
Note that this buffer (for perfomance reasons) always is a 240 by 160 pixel buffer, where each pixel is 8 bit. I could change this in the future (to support other sizes) even without a performance loss, but for now I have other priorities.

void SoMode4PolygonRasterizerSetTexture SoImage   a_Texture
 

Sets the texture the rasterizer should use for textured polygons.

Parameters:
a_Texture  Texture you want to use.


Variable Documentation

u16* g_SoMode4PolygonRasterizerBuffer  
 

Pointer the polygon routines will render to.

For internal use only.


Copyright 2002 by the SGADE authors. See SoLicense.h or Visit the SGADE page for more information.