libnds
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions
gl2d.h File Reference

A very small and simple DS rendering lib using the 3d core to render 2D stuff. More...

#include <nds/arm9/videoGL.h>

Data Structures

struct  glImage
 Struct for our GL-Based Images. More...
 

Enumerations

enum  GL_FLIP_MODE {
  GL_FLIP_NONE = (1 << 0) ,
  GL_FLIP_V = (1 << 1) ,
  GL_FLIP_H = (1 << 2)
}
 Enums selecting flipping mode. More...
 

Functions

void glBegin2D (void)
 Sets up OpenGL for 2d rendering.
 
void glBox (int x1, int y1, int x2, int y2, int color)
 Draws a box.
 
void glBoxFilled (int x1, int y1, int x2, int y2, int color)
 Draws a filled box.
 
void glBoxFilledGradient (int x1, int y1, int x2, int y2, int color1, int color2, int color3, int color4)
 Draws a filled box in gradient colors.
 
void glEnd2D (void)
 Issue this after drawing 2d so that we don't mess the matrix stack.
 
static int glGetActiveTexture (void)
 Returns the active texture. Use with care.
 
void glLine (int x1, int y1, int x2, int y2, int color)
 Draws a line.
 
int glLoadSpriteSet (glImage *sprite, const unsigned int numframes, const uint16_t *texcoords, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int param, int palette_width, const void *palette, const void *texture)
 Initializes our spriteset with Texture Packer generated UV coordinates.
 
int glLoadTileSet (glImage *sprite, int tile_wid, int tile_hei, int bmp_wid, int bmp_hei, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int param, int palette_width, const void *palette, const void *texture)
 Initializes our tileset (like glInitSpriteset()) but without the use of Texture Packer auto-generated files.
 
void glPutPixel (int x, int y, int color)
 Draws a pixel.
 
void glScreen2D (void)
 Initializes GL in 2D mode.
 
static void glSetActiveTexture (int TextureID)
 Set the active texture. Use with care.
 
void glSprite (int x, int y, int flipmode, const glImage *spr)
 Draws a sprite.
 
void glSpriteOnQuad (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int uoff, int voff, int flipmode, const glImage *spr)
 Draws a horizontaly stretched sprite (clean stretching).
 
void glSpriteRotate (int x, int y, s32 angle, int flipmode, const glImage *spr)
 Draws a center rotated sprite.
 
void glSpriteRotateScale (int x, int y, s32 angle, s32 scale, int flipmode, const glImage *spr)
 Draws a center rotated scaled sprite.
 
void glSpriteRotateScaleXY (int x, int y, s32 angle, s32 scaleX, s32 scaleY, int flipmode, const glImage *spr)
 Draws a center rotated axis-exclusive scaled sprite.
 
void glSpriteScale (int x, int y, s32 scale, int flipmode, const glImage *spr)
 Draws a scaled sprite.
 
void glSpriteScaleXY (int x, int y, s32 scaleX, s32 scaleY, int flipmode, const glImage *spr)
 Draws an axis exclusive scaled sprite.
 
void glSpriteStretchHorizontal (int x, int y, int length_x, const glImage *spr)
 Draws a horizontaly stretched sprite (clean stretching).
 
void glTriangle (int x1, int y1, int x2, int y2, int x3, int y3, int color)
 Draws a triangle.
 
void glTriangleFilled (int x1, int y1, int x2, int y2, int x3, int y3, int color)
 Draws a filled triangle.
 
void glTriangleFilledGradient (int x1, int y1, int x2, int y2, int x3, int y3, int color1, int color2, int color3)
 Draws a triangle in gradient colors.
 

Detailed Description

A very small and simple DS rendering lib using the 3d core to render 2D stuff.

API

Enumeration Type Documentation

◆ GL_FLIP_MODE

Enums selecting flipping mode.

These enums are bits for flipping the sprites.

You can **"|"** (or) GL_FLIP_V and GL_FLIP_H to flip both ways.

Enumerator
GL_FLIP_NONE 

No flipping.

GL_FLIP_V 

Sprite is rendered vertically flipped.

GL_FLIP_H 

Sprite is rendered horizontally flipped.

Function Documentation

◆ glBegin2D()

void glBegin2D ( void  )

Sets up OpenGL for 2d rendering.

Call this before drawing any of GL2D's drawing or sprite functions.

◆ glBox()

void glBox ( int  x1,
int  y1,
int  x2,
int  y2,
int  color 
)

Draws a box.

Parameters
x1,y1Top-Left coordinate of the box.
x2,y2Bottom-Right coordinate of the box.
colorRGB15/ARGB16 color.

◆ glBoxFilled()

void glBoxFilled ( int  x1,
int  y1,
int  x2,
int  y2,
int  color 
)

Draws a filled box.

Parameters
x1,y1Top-Left coordinate of the box.
x2,y2Bottom-Right coordinate of the box.
colorRGB15/ARGB16 color.

◆ glBoxFilledGradient()

void glBoxFilledGradient ( int  x1,
int  y1,
int  x2,
int  y2,
int  color1,
int  color2,
int  color3,
int  color4 
)

Draws a filled box in gradient colors.

Parameters
x1,y1Top-Left coordinate of the box.
x2,y2Bottom-Right coordinate of the box.
color1RGB15/ARGB16 color of the Top-Left corner.
color2RGB15/ARGB16 color of the Bottom-Left corner.
color3RGB15/ARGB16 color of the Bottom-Right corner.
color4RGB15/ARGB16 color of the Top-Right corner.

◆ glEnd2D()

void glEnd2D ( void  )

Issue this after drawing 2d so that we don't mess the matrix stack.

The compliment of glBegin2D().

◆ glGetActiveTexture()

static int glGetActiveTexture ( void  )
inlinestatic

Returns the active texture. Use with care.

Needed to achieve some effects since libnds 1.5.0.

Returns
Returns the texture ID.

◆ glLine()

void glLine ( int  x1,
int  y1,
int  x2,
int  y2,
int  color 
)

Draws a line.

Parameters
x1,y1Top-Left coordinate of the line.
x2,y2Bottom-Right coordinate of the line.
colorRGB15/ARGB16 color.

◆ glLoadSpriteSet()

int glLoadSpriteSet ( glImage sprite,
const unsigned int  numframes,
const uint16_t *  texcoords,
GL_TEXTURE_TYPE_ENUM  type,
int  sizeX,
int  sizeY,
int  param,
int  palette_width,
const void *  palette,
const void *  texture 
)

Initializes our spriteset with Texture Packer generated UV coordinates.

Very safe and easy to use.

Parameters
spritePointer to an array of glImage.
numframesNumber of frames in a spriteset (auto-generated by Texture Packer).
texcoordsTexture Packer auto-generated array of UV coords.
typeThe format of the texture (see glTexImage2D()).
sizeXThe horizontal size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2D()).
sizeYThe vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2D()).
paramParameters for the texture (see glTexImage2D()).
palette_widthLength of the palette. Valid values are 4, 16, 32, 256 (if 0, the palette is removed from the currently bound texture).
palettePointer to the palette data to load (if NULL, then palette is emoved from currently bound texture).
texturePointer to the texture data to load.
Returns
Returns the texture ID on success, -1 on error.

◆ glLoadTileSet()

int glLoadTileSet ( glImage sprite,
int  tile_wid,
int  tile_hei,
int  bmp_wid,
int  bmp_hei,
GL_TEXTURE_TYPE_ENUM  type,
int  sizeX,
int  sizeY,
int  param,
int  palette_width,
const void *  palette,
const void *  texture 
)

Initializes our tileset (like glInitSpriteset()) but without the use of Texture Packer auto-generated files.

Can only be used when tiles in a tilset are of the same dimensions.

Parameters
spritePointer to an array of glImage.
tile_widWidth of each tile in the texture.
tile_heiHeight of each tile in the texture.
bmp_widWidth of of the texture or tileset.
bmp_heiheight of of the texture or tileset.
typeThe format of the texture (see glTexImage2D()).
sizeXThe horizontal size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2D()).
sizeYThe vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2D()).
paramParameters for the texture (see glTexImage2D()).
palette_widthLength of the palette. Valid values are 4, 16, 32, 256 (if 0, the palette is removed from the currently bound texture).
palettePointer to the palette data to load (if NULL, then palette is removed from currently bound texture).
texturePointer to the texture data to load.
Returns
Returns the texture ID on success, -1 on error.

◆ glPutPixel()

void glPutPixel ( int  x,
int  y,
int  color 
)

Draws a pixel.

Parameters
xX position of the pixel.
yY position of the pixel.
colorRGB15/ARGB16 color.

◆ glScreen2D()

void glScreen2D ( void  )

Initializes GL in 2D mode.

Also initializes GL in 3d mode so that we could combine 2D and 3D later. Almost a direct copy from the DS example files.

◆ glSetActiveTexture()

static void glSetActiveTexture ( int  TextureID)
inlinestatic

Set the active texture. Use with care.

Needed to achieve some effects since libnds 1.5.0.

Parameters
TextureIDTexture to set as active.

◆ glSprite()

void glSprite ( int  x,
int  y,
int  flipmode,
const glImage spr 
)

Draws a sprite.

Parameters
xX position of the sprite.
yY position of the sprite.
flipmodeMode for flipping (see GL_FLIP_MODE enum).
sprPointer to a glImage.

◆ glSpriteOnQuad()

void glSpriteOnQuad ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3,
int  x4,
int  y4,
int  uoff,
int  voff,
int  flipmode,
const glImage spr 
)

Draws a horizontaly stretched sprite (clean stretching).

Useful for "shrearing effects".

Parameters
x1,y1First corner of the sprite.
x2,y2Second corner of the sprite.
x3,y3Third corner of the sprite.
x4,y4Fourth corner of the sprite.
uoff,voffTexture offsets.
flipmodeMode for flipping (see GL_FLIP_MODE enum).
sprPointer to a glImage.

◆ glSpriteRotate()

void glSpriteRotate ( int  x,
int  y,
s32  angle,
int  flipmode,
const glImage spr 
)

Draws a center rotated sprite.

Parameters
xX position of the sprite center.
yY position of the sprite center.
angleBinary Radian Angle(-32768 to 32767) to rotate the sprite.
flipmodeMode for flipping (see GL_FLIP_MODE enum).
sprPointer to a glImage.

◆ glSpriteRotateScale()

void glSpriteRotateScale ( int  x,
int  y,
s32  angle,
s32  scale,
int  flipmode,
const glImage spr 
)

Draws a center rotated scaled sprite.

Parameters
xX position of the sprite center.
yY position of the sprite center.
angleBinary Radian Angle(-32768 to 32767) to rotate the sprite.
scale20.12 fixed-point scale value (1 << 12 is normal).
flipmodeMode for flipping (see GL_FLIP_MODE enum).
sprPointer to a glImage.

◆ glSpriteRotateScaleXY()

void glSpriteRotateScaleXY ( int  x,
int  y,
s32  angle,
s32  scaleX,
s32  scaleY,
int  flipmode,
const glImage spr 
)

Draws a center rotated axis-exclusive scaled sprite.

Parameters
xX position of the sprite center.
yY position of the sprite center.
angleBinary Radian Angle(-32768 to 32767) to rotate the sprite.
scaleX20.12 fixed-point X-Axis scale value (1 << 12 is normal).
scaleY20.12 fixed-point Y-Axis scale value (1 << 12 is normal).
flipmodeMode for flipping (see GL_FLIP_MODE enum).
sprPointer to a glImage.

◆ glSpriteScale()

void glSpriteScale ( int  x,
int  y,
s32  scale,
int  flipmode,
const glImage spr 
)

Draws a scaled sprite.

Parameters
xX position of the sprite.
yY position of the sprite.
scale20.12 fixed-point scale value (1 << 12 is normal).
flipmodeMode for flipping (see GL_FLIP_MODE enum).
sprPointer to a glImage.

◆ glSpriteScaleXY()

void glSpriteScaleXY ( int  x,
int  y,
s32  scaleX,
s32  scaleY,
int  flipmode,
const glImage spr 
)

Draws an axis exclusive scaled sprite.

Parameters
xX position of the sprite.
yY position of the sprite.
scaleX20.12 fixed-point X-Axis scale value (1 << 12 is normal).
scaleY20.12 fixed-point Y-Axis scale value (1 << 12 is normal).
flipmodeMode for flipping (see GL_FLIP_MODE enum).
sprPointer to a glImage.

◆ glSpriteStretchHorizontal()

void glSpriteStretchHorizontal ( int  x,
int  y,
int  length_x,
const glImage spr 
)

Draws a horizontaly stretched sprite (clean stretching).

Useful for "laser effects".

Parameters
xX position of the sprite center.
yY position of the sprite center.
length_xThe length(in pixels) to stretch the sprite.
sprPointer to a glImage.

◆ glTriangle()

void glTriangle ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3,
int  color 
)

Draws a triangle.

Parameters
x1,y1Vertex 1 of the triangle.
x2,y2Vertex 2 of the triangle.
x3,y3Vertex 3 of the triangle.
colorRGB15/ARGB16 color of the triangle.

◆ glTriangleFilled()

void glTriangleFilled ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3,
int  color 
)

Draws a filled triangle.

Parameters
x1,y1Vertex 1 of the triangle.
x2,y2Vertex 2 of the triangle.
x3,y3Vertex 3 of the triangle.
colorRGB15/ARGB16 color of the triangle.

◆ glTriangleFilledGradient()

void glTriangleFilledGradient ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3,
int  color1,
int  color2,
int  color3 
)

Draws a triangle in gradient colors.

Parameters
x1,y1Vertex 1 of the triangle.
x2,y2Vertex 2 of the triangle.
x3,y3Vertex 3 of the triangle.
color1RGB15/ARGB16 color of the vertex 1.
color2RGB15/ARGB16 color of the vertex 2.
color3RGB15/ARGB16 color of the vertex 3.