Merge pull request #34 from GRRLIB/refactor

Refactoring
This commit is contained in:
Crayon 2022-11-24 23:43:36 -05:00 committed by GitHub
commit 3050dba256
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 331 additions and 382 deletions

View file

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
- Fixed compatibility issues with devkitPPC release 39. - Fixed compatibility issues with devkitPPC release 39.
- Added `GRRLIB_LoadTTFFromFile()` to load a TTF from a file. - Added `GRRLIB_LoadTTFFromFile()` to load a TTF from a file.
- Added `GRRLIB_Ellipse()` to draw an ellipse. - Added `GRRLIB_Ellipse()` to draw an ellipse.
- Changed function arguments types in a few functions.
- Fixed documentation for `GRRLIB_Camera3dSettings()`, `GRRLIB_Screen2Texture()` and `GRRLIB_CompoEnd()`. - Fixed documentation for `GRRLIB_Camera3dSettings()`, `GRRLIB_Screen2Texture()` and `GRRLIB_CompoEnd()`.
## [4.4.1][] - 2021-03-05 ## [4.4.1][] - 2021-03-05

View file

@ -1,5 +1,5 @@
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
Copyright (c) 2009-2021 The GRRLIB Team Copyright (c) 2009-2022 The GRRLIB Team
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -26,9 +26,9 @@ THE SOFTWARE.
// User should not directly modify these // User should not directly modify these
Mtx _GRR_view; // Should be static as soon as all light functions needing this var will be in this file ;) Mtx _GRR_view; // Should be static as soon as all light functions needing this var will be in this file ;)
static guVector _GRR_cam = {0.0F, 0.0F, 0.0F}, static guVector _GRR_cam = {0.0f, 0.0f, 0.0f},
_GRR_up = {0.0F, 1.0F, 0.0F}, _GRR_up = {0.0f, 1.0f, 0.0f},
_GRR_look = {0.0F, 0.0F, -100.0F}; _GRR_look = {0.0f, 0.0f, -100.0f};
static guVector _GRRaxisx = (guVector){1, 0, 0}; // DO NOT MODIFY!!! static guVector _GRRaxisx = (guVector){1, 0, 0}; // DO NOT MODIFY!!!
static guVector _GRRaxisy = (guVector){0, 1, 0}; // Even at runtime static guVector _GRRaxisy = (guVector){0, 1, 0}; // Even at runtime
static guVector _GRRaxisz = (guVector){0, 0, 1}; // NOT ever! static guVector _GRRaxisz = (guVector){0, 0, 1}; // NOT ever!
@ -134,7 +134,7 @@ void GRRLIB_2dMode() {
GX_LoadProjectionMtx(m, GX_ORTHOGRAPHIC); GX_LoadProjectionMtx(m, GX_ORTHOGRAPHIC);
guMtxIdentity(view); guMtxIdentity(view);
guMtxTransApply(view, view, 0, 0, -100.0F); guMtxTransApply(view, view, 0, 0, -100.0f);
GX_LoadPosMtxImm(view, GX_PNMTX0); GX_LoadPosMtxImm(view, GX_PNMTX0);
GX_ClearVtxDesc(); GX_ClearVtxDesc();
@ -190,7 +190,8 @@ void GRRLIB_ObjectViewScale(f32 scalx, f32 scaly, f32 scalz) {
* @param angz z rotation angle of the object. * @param angz z rotation angle of the object.
*/ */
void GRRLIB_ObjectViewRotate(f32 angx, f32 angy, f32 angz) { void GRRLIB_ObjectViewRotate(f32 angx, f32 angy, f32 angz) {
Mtx m, rx,ry,rz; Mtx m;
Mtx rx, ry, rz;
guMtxIdentity(m); guMtxIdentity(m);
guMtxRotAxisDeg(rx, &_GRRaxisx, angx); guMtxRotAxisDeg(rx, &_GRRaxisx, angx);
@ -245,7 +246,7 @@ void GRRLIB_ObjectViewEnd(void) {
*/ */
void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz, f32 scalx, f32 scaly, f32 scalz) { void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz, f32 scalx, f32 scaly, f32 scalz) {
Mtx ObjTransformationMtx; Mtx ObjTransformationMtx;
Mtx m, rx,ry,rz; Mtx m;
Mtx mv, mvi; Mtx mv, mvi;
guMtxIdentity(ObjTransformationMtx); guMtxIdentity(ObjTransformationMtx);
@ -258,6 +259,7 @@ void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 ang
} }
if((angx != 0.0f) || (angy != 0.0f) || (angz != 0.0f)) { if((angx != 0.0f) || (angy != 0.0f) || (angz != 0.0f)) {
Mtx rx, ry, rz;
guMtxIdentity(m); guMtxIdentity(m);
guMtxRotAxisDeg(rx, &_GRRaxisx, angx); guMtxRotAxisDeg(rx, &_GRRaxisx, angx);
guMtxRotAxisDeg(ry, &_GRRaxisy, angy); guMtxRotAxisDeg(ry, &_GRRaxisy, angy);
@ -297,7 +299,7 @@ void GRRLIB_ObjectView(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 ang
*/ */
void GRRLIB_ObjectViewInv(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz, f32 scalx, f32 scaly, f32 scalz) { void GRRLIB_ObjectViewInv(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32 angz, f32 scalx, f32 scaly, f32 scalz) {
Mtx ObjTransformationMtx; Mtx ObjTransformationMtx;
Mtx m, rx,ry,rz; Mtx m;
Mtx mv, mvi; Mtx mv, mvi;
guMtxIdentity(ObjTransformationMtx); guMtxIdentity(ObjTransformationMtx);
@ -317,6 +319,7 @@ void GRRLIB_ObjectViewInv(f32 posx, f32 posy, f32 posz, f32 angx, f32 angy, f32
} }
if((angx != 0.0f) || (angy != 0.0f) || (angz != 0.0f)) { if((angx != 0.0f) || (angy != 0.0f) || (angz != 0.0f)) {
Mtx rx, ry, rz;
guMtxIdentity(m); guMtxIdentity(m);
guMtxRotAxisDeg(rx, &_GRRaxisx, angx); guMtxRotAxisDeg(rx, &_GRRaxisx, angx);
guMtxRotAxisDeg(ry, &_GRRaxisy, angy); guMtxRotAxisDeg(ry, &_GRRaxisy, angy);
@ -372,35 +375,28 @@ void GRRLIB_SetTexture(GRRLIB_texImg *tex, bool rep) {
* @param col Color of the torus. * @param col Color of the torus.
*/ */
void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled, u32 col) { void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled, u32 col) {
int i, j; const f32 ringDelta = 2.0 * M_PI / rings;
f32 theta, phi, theta1; const f32 sideDelta = 2.0 * M_PI / nsides;
f32 cosTheta, sinTheta;
f32 cosTheta1, sinTheta1;
f32 ringDelta, sideDelta;
f32 cosPhi, sinPhi, dist;
ringDelta = 2.0 * M_PI / rings; f32 theta = 0.0;
sideDelta = 2.0 * M_PI / nsides; f32 cosTheta = 1.0;
f32 sinTheta = 0.0;
theta = 0.0; for (int i = rings - 1; i >= 0; i--) {
cosTheta = 1.0; const f32 theta1 = theta + ringDelta;
sinTheta = 0.0; const f32 cosTheta1 = cosf(theta1);
for (i = rings - 1; i >= 0; i--) { const f32 sinTheta1 = sinf(theta1);
theta1 = theta + ringDelta;
cosTheta1 = cos(theta1);
sinTheta1 = sin(theta1);
if(filled == true) { if(filled == true) {
GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2 * (nsides + 1)); GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2 * (nsides + 1));
} }
else { else {
GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 2 * (nsides + 1)); GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 2 * (nsides + 1));
} }
phi = 0.0; f32 phi = 0.0;
for (j = nsides; j >= 0; j--) { for (int j = nsides; j >= 0; j--) {
phi += sideDelta; phi += sideDelta;
cosPhi = cos(phi); const f32 cosPhi = cosf(phi);
sinPhi = sin(phi); const f32 sinPhi = sinf(phi);
dist = R + r * cosPhi; const f32 dist = R + r * cosPhi;
GX_Position3f32(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); GX_Position3f32(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
GX_Normal3f32(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); GX_Normal3f32(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
@ -425,29 +421,25 @@ void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled, u32 col)
* @param col Color of the sphere. * @param col Color of the sphere.
*/ */
void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled, u32 col) { void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled, u32 col) {
int i, j; for(int i = 0; i <= lats; i++) {
f32 lat0, z0, zr0, const f32 lat0 = M_PI * (-0.5f + (f32) (i - 1) / lats);
lat1, z1, zr1, const f32 z0 = sinf(lat0);
lng, x, y; const f32 zr0 = cosf(lat0);
for(i = 0; i <= lats; i++) { const f32 lat1 = M_PI * (-0.5f + (f32) i / lats);
lat0 = M_PI * (-0.5F + (f32) (i - 1) / lats); const f32 z1 = sinf(lat1);
z0 = sin(lat0); const f32 zr1 = cosf(lat1);
zr0 = cos(lat0);
lat1 = M_PI * (-0.5F + (f32) i / lats);
z1 = sin(lat1);
zr1 = cos(lat1);
if(filled == true) { if(filled == true) {
GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2 * (longs + 1)); GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2 * (longs + 1));
} }
else { else {
GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 2 * (longs + 1)); GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 2 * (longs + 1));
} }
for(j = 0; j <= longs; j++) { for(int j = 0; j <= longs; j++) {
lng = 2 * M_PI * (f32) (j - 1) / longs; const f32 lng = 2 * M_PI * (f32) (j - 1) / longs;
x = cos(lng); const f32 x = cosf(lng);
y = sin(lng); const f32 y = sinf(lng);
GX_Position3f32(x * zr0 * r, y * zr0 * r, z0 * r); GX_Position3f32(x * zr0 * r, y * zr0 * r, z0 * r);
GX_Normal3f32(x * zr0 * r, y * zr0 * r, z0 * r); GX_Normal3f32(x * zr0 * r, y * zr0 * r, z0 * r);
@ -467,16 +459,16 @@ void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled, u32 col) {
* @param col Color of the cube. * @param col Color of the cube.
*/ */
void GRRLIB_DrawCube(f32 size, bool filled, u32 col) { void GRRLIB_DrawCube(f32 size, bool filled, u32 col) {
static f32 n[6][3] = static const f32 normal[6][3] =
{ {
{-1.0, 0.0, 0.0}, {-1.0f, 0.0f, 0.0f},
{0.0, 1.0, 0.0}, {0.0f, 1.0f, 0.0f},
{1.0, 0.0, 0.0}, {1.0f, 0.0f, 0.0f},
{0.0, -1.0, 0.0}, {0.0f, -1.0f, 0.0f},
{0.0, 0.0, 1.0}, {0.0f, 0.0f, 1.0f},
{0.0, 0.0, -1.0} {0.0f, 0.0f, -1.0f}
}; };
static int faces[6][4] = static const u8 faces[6][4] =
{ {
{0, 1, 2, 3}, {0, 1, 2, 3},
{3, 2, 6, 7}, {3, 2, 6, 7},
@ -487,14 +479,14 @@ void GRRLIB_DrawCube(f32 size, bool filled, u32 col) {
}; };
f32 v[8][3]; f32 v[8][3];
v[0][0] = v[1][0] = v[2][0] = v[3][0] = -size / 2; v[0][0] = v[1][0] = v[2][0] = v[3][0] = -size / 2.0f;
v[4][0] = v[5][0] = v[6][0] = v[7][0] = size / 2; v[4][0] = v[5][0] = v[6][0] = v[7][0] = size / 2.0f;
v[0][1] = v[1][1] = v[4][1] = v[5][1] = -size / 2; v[0][1] = v[1][1] = v[4][1] = v[5][1] = -size / 2.0f;
v[2][1] = v[3][1] = v[6][1] = v[7][1] = size / 2; v[2][1] = v[3][1] = v[6][1] = v[7][1] = size / 2.0f;
v[0][2] = v[3][2] = v[4][2] = v[7][2] = -size / 2; v[0][2] = v[3][2] = v[4][2] = v[7][2] = -size / 2.0f;
v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2; v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2.0f;
for (int i = 5; i >= 0; i--) { for (s8 i = 5; i >= 0; i--) {
if(filled == true) { if(filled == true) {
GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
} }
@ -502,20 +494,20 @@ void GRRLIB_DrawCube(f32 size, bool filled, u32 col) {
GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 5); GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 5);
} }
GX_Position3f32(v[faces[i][0]][0], v[faces[i][0]][1], v[faces[i][0]][2] ); GX_Position3f32(v[faces[i][0]][0], v[faces[i][0]][1], v[faces[i][0]][2] );
GX_Normal3f32(n[i][0], n[i][1], n[i][2]); GX_Normal3f32(normal[i][0], normal[i][1], normal[i][2]);
GX_Color1u32(col); GX_Color1u32(col);
GX_Position3f32(v[faces[i][1]][0], v[faces[i][1]][1], v[faces[i][1]][2]); GX_Position3f32(v[faces[i][1]][0], v[faces[i][1]][1], v[faces[i][1]][2]);
GX_Normal3f32(n[i][0], n[i][1], n[i][2]); GX_Normal3f32(normal[i][0], normal[i][1], normal[i][2]);
GX_Color1u32(col); GX_Color1u32(col);
GX_Position3f32(v[faces[i][2]][0], v[faces[i][2]][1], v[faces[i][2]][2]); GX_Position3f32(v[faces[i][2]][0], v[faces[i][2]][1], v[faces[i][2]][2]);
GX_Normal3f32(n[i][0], n[i][1], n[i][2]); GX_Normal3f32(normal[i][0], normal[i][1], normal[i][2]);
GX_Color1u32(col); GX_Color1u32(col);
GX_Position3f32(v[faces[i][3]][0], v[faces[i][3]][1], v[faces[i][3]][2]); GX_Position3f32(v[faces[i][3]][0], v[faces[i][3]][1], v[faces[i][3]][2]);
GX_Normal3f32(n[i][0], n[i][1], n[i][2]); GX_Normal3f32(normal[i][0], normal[i][1], normal[i][2]);
GX_Color1u32(col); GX_Color1u32(col);
if(filled == false) { if(filled == false) {
GX_Position3f32(v[faces[i][0]][0], v[faces[i][0]][1], v[faces[i][0]][2]); GX_Position3f32(v[faces[i][0]][0], v[faces[i][0]][1], v[faces[i][0]][2]);
GX_Normal3f32(n[i][0], n[i][1], n[i][2]); GX_Normal3f32(normal[i][0], normal[i][1], normal[i][2]);
GX_Color1u32(col); GX_Color1u32(col);
} }
GX_End(); GX_End();
@ -530,19 +522,16 @@ void GRRLIB_DrawCube(f32 size, bool filled, u32 col) {
* @param filled Wired or not. * @param filled Wired or not.
* @param col Color of the cylinder. * @param col Color of the cylinder.
*/ */
void GRRLIB_DrawCylinder(f32 r, f32 h, int d, bool filled, u32 col) { void GRRLIB_DrawCylinder(f32 r, f32 h, u16 d, bool filled, u32 col) {
int i;
f32 dx, dy;
if(filled == true) { if(filled == true) {
GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2 * (d + 1)); GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2 * (d + 1));
} }
else { else {
GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 2 * (d + 1)); GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 2 * (d + 1));
} }
for(i = 0; i <= d; i++) { for(u16 i = 0; i <= d; i++) {
dx = cosf( M_PI * 2.0f * i / d ); const f32 dx = cosf( M_PI * 2.0f * i / d );
dy = sinf( M_PI * 2.0f * i / d ); const f32 dy = sinf( M_PI * 2.0f * i / d );
GX_Position3f32( r * dx, -0.5f * h, r * dy ); GX_Position3f32( r * dx, -0.5f * h, r * dy );
GX_Normal3f32( dx, 0.0f, dy ); GX_Normal3f32( dx, 0.0f, dy );
GX_Color1u32(col); GX_Color1u32(col);
@ -561,7 +550,7 @@ void GRRLIB_DrawCylinder(f32 r, f32 h, int d, bool filled, u32 col) {
GX_Position3f32(0.0f, -0.5f * h, 0.0f); GX_Position3f32(0.0f, -0.5f * h, 0.0f);
GX_Normal3f32(0.0f, -1.0f, 0.0f); GX_Normal3f32(0.0f, -1.0f, 0.0f);
GX_Color1u32(col); GX_Color1u32(col);
for(i = 0; i <= d; i++) { for(u16 i = 0; i <= d; i++) {
GX_Position3f32( r * cosf( M_PI * 2.0f * i / d ), -0.5f * h, r * sinf( M_PI * 2.0f * i / d ) ); GX_Position3f32( r * cosf( M_PI * 2.0f * i / d ), -0.5f * h, r * sinf( M_PI * 2.0f * i / d ) );
GX_Normal3f32(0.0f, -1.0f, 0.0f); GX_Normal3f32(0.0f, -1.0f, 0.0f);
GX_Color1u32(col); GX_Color1u32(col);
@ -577,7 +566,7 @@ void GRRLIB_DrawCylinder(f32 r, f32 h, int d, bool filled, u32 col) {
GX_Position3f32(0.0f, 0.5f * h, 0.0f); GX_Position3f32(0.0f, 0.5f * h, 0.0f);
GX_Normal3f32(0.0f, 1.0f, 0.0f); GX_Normal3f32(0.0f, 1.0f, 0.0f);
GX_Color1u32(col); GX_Color1u32(col);
for(i = 0; i <= d; i++) { for(u16 i = 0; i <= d; i++) {
GX_Position3f32( r * cosf( M_PI * 2.0f * i / d ), 0.5f * h, r * sinf( M_PI * 2.0f * i / d ) ); GX_Position3f32( r * cosf( M_PI * 2.0f * i / d ), 0.5f * h, r * sinf( M_PI * 2.0f * i / d ) );
GX_Normal3f32(0.0f, 1.0f, 0.0f); GX_Normal3f32(0.0f, 1.0f, 0.0f);
GX_Color1u32(col); GX_Color1u32(col);
@ -593,19 +582,16 @@ void GRRLIB_DrawCylinder(f32 r, f32 h, int d, bool filled, u32 col) {
* @param filled Wired or not. * @param filled Wired or not.
* @param col Color of the cone. * @param col Color of the cone.
*/ */
void GRRLIB_DrawCone(f32 r, f32 h, int d, bool filled, u32 col) { void GRRLIB_DrawCone(f32 r, f32 h, u16 d, bool filled, u32 col) {
int i;
f32 dx, dy;
if(filled == true) { if(filled == true) {
GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2 * (d + 1)); GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 2 * (d + 1));
} }
else { else {
GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 2 * (d + 1)); GX_Begin(GX_LINESTRIP, GX_VTXFMT0, 2 * (d + 1));
} }
for(i = 0; i <= d; i++) { for(u16 i = 0; i <= d; i++) {
dx = cosf( M_PI * 2.0f * i / d ); const f32 dx = cosf( M_PI * 2.0f * i / d );
dy = sinf( M_PI * 2.0f * i / d ); const f32 dy = sinf( M_PI * 2.0f * i / d );
GX_Position3f32( 0, -0.5f * h,0); GX_Position3f32( 0, -0.5f * h,0);
GX_Normal3f32( dx, 0.0f, dy ); GX_Normal3f32( dx, 0.0f, dy );
GX_Color1u32(col); GX_Color1u32(col);
@ -624,7 +610,7 @@ void GRRLIB_DrawCone(f32 r, f32 h, int d, bool filled, u32 col) {
GX_Position3f32(0.0f, 0.5f * h, 0.0f); GX_Position3f32(0.0f, 0.5f * h, 0.0f);
GX_Normal3f32(0.0f, 1.0f, 0.0f); GX_Normal3f32(0.0f, 1.0f, 0.0f);
GX_Color1u32(col); GX_Color1u32(col);
for(i = 0; i <= d; i++) { for(u16 i = 0; i <= d; i++) {
GX_Position3f32( r * cosf( M_PI * 2.0f * i / d ), 0.5f * h, r * sinf( M_PI * 2.0f * i / d ) ); GX_Position3f32( r * cosf( M_PI * 2.0f * i / d ), 0.5f * h, r * sinf( M_PI * 2.0f * i / d ) );
GX_Normal3f32(0.0f, 1.0f, 0.0f); GX_Normal3f32(0.0f, 1.0f, 0.0f);
GX_Color1u32(col); GX_Color1u32(col);
@ -642,12 +628,10 @@ void GRRLIB_DrawCone(f32 r, f32 h, int d, bool filled, u32 col) {
* @param col Color in RGBA format. * @param col Color in RGBA format.
*/ */
void GRRLIB_DrawTessPanel(f32 w, f32 wstep, f32 h, f32 hstep, bool filled, u32 col) { void GRRLIB_DrawTessPanel(f32 w, f32 wstep, f32 h, f32 hstep, bool filled, u32 col) {
f32 x, y; const f32 tmpy = h / 2.0f;
const f32 tmpx = w / 2.0f;
f32 tmpy = h/2.0f; const u16 tmp = ((w / wstep) * 2) + 2;
f32 tmpx = w/2.0f; for ( f32 y = -tmpy; y <= tmpy; y += hstep )
int tmp = ((w/wstep)*2)+2;
for ( y = -tmpy; y <= tmpy; y += hstep )
{ {
if(filled == true) { if(filled == true) {
GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, tmp); GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, tmp);
@ -655,7 +639,7 @@ void GRRLIB_DrawTessPanel(f32 w, f32 wstep, f32 h, f32 hstep, bool filled, u32 c
else { else {
GX_Begin(GX_LINESTRIP, GX_VTXFMT0, tmp); GX_Begin(GX_LINESTRIP, GX_VTXFMT0, tmp);
} }
for ( x = -tmpx; x <= tmpx; x += wstep ) for ( f32 x = -tmpx; x <= tmpx; x += wstep )
{ {
GX_Position3f32( x, y, 0.0f ); GX_Position3f32( x, y, 0.0f );
GX_Normal3f32( 0.0f, 0.0f, 1.0f); GX_Normal3f32( 0.0f, 0.0f, 1.0f);
@ -744,7 +728,7 @@ void GRRLIB_SetLightSpec(u8 num, guVector dir, f32 shininess, u32 lightcolor, u3
/////////////////////// Define Material and Ambient color and draw object ///////////////////////////////////// /////////////////////// Define Material and Ambient color and draw object /////////////////////////////////////
GX_SetChanAmbColor(GX_COLOR1, (GXColor){0x00,0x00,0x00,0xFF}); // specular ambient forced to black GX_SetChanAmbColor(GX_COLOR1, (GXColor){0x00,0x00,0x00,0xFF}); // specular ambient forced to black
GX_SetChanMatColor(GX_COLOR1, (GXColor) { R(speccolor), G(speccolor), B(speccolor), 0xFF }); // couleur du reflet specular GX_SetChanMatColor(GX_COLOR1, (GXColor) { R(speccolor), G(speccolor), B(speccolor), 0xFF }); // specular reflection color
} }
/** /**

View file

@ -1,5 +1,5 @@
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
Copyright (c) 2009-2020 The GRRLIB Team Copyright (c) 2009-2022 The GRRLIB Team
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -34,9 +34,9 @@ THE SOFTWARE.
*/ */
GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) { GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) {
GRRLIB_bytemapFont *fontArray = (struct GRRLIB_bytemapFont *)malloc(sizeof(GRRLIB_bytemapFont)); GRRLIB_bytemapFont *fontArray = (struct GRRLIB_bytemapFont *)malloc(sizeof(GRRLIB_bytemapFont));
u32 i, j = 1;
if (fontArray != NULL && my_bmf[0]==0xE1 && my_bmf[1]==0xE6 && my_bmf[2]==0xD5 && my_bmf[3]==0x1A) { if (fontArray != NULL && my_bmf[0]==0xE1 && my_bmf[1]==0xE6 && my_bmf[2]==0xD5 && my_bmf[3]==0x1A) {
u32 j = 1;
fontArray->version = my_bmf[4]; fontArray->version = my_bmf[4];
//u8 lineheight = my_bmf[5]; //u8 lineheight = my_bmf[5];
//short int sizeover = my_bmf[6]; //short int sizeover = my_bmf[6];
@ -48,7 +48,7 @@ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) {
u8 nbPalette = my_bmf[16]; u8 nbPalette = my_bmf[16];
short int numcolpal = 3 * nbPalette; short int numcolpal = 3 * nbPalette;
fontArray->palette = (u32 *)calloc(nbPalette + 1, sizeof(u32)); fontArray->palette = (u32 *)calloc(nbPalette + 1, sizeof(u32));
for (i=0; i < numcolpal; i+=3) { for (u32 i=0; i < numcolpal; i+=3) {
fontArray->palette[j++] = ((((my_bmf[i+17]<<2)+3)<<24) | (((my_bmf[i+18]<<2)+3)<<16) | (((my_bmf[i+19]<<2)+3)<<8) | 0xFF); fontArray->palette[j++] = ((((my_bmf[i+17]<<2)+3)<<24) | (((my_bmf[i+18]<<2)+3)<<16) | (((my_bmf[i+19]<<2)+3)<<8) | 0xFF);
} }
j = my_bmf[17 + numcolpal]; j = my_bmf[17 + numcolpal];
@ -58,7 +58,7 @@ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) {
fontArray->nbChar = (my_bmf[j] | my_bmf[j+1]<<8); fontArray->nbChar = (my_bmf[j] | my_bmf[j+1]<<8);
memset(fontArray->charDef, 0, 256 * sizeof(GRRLIB_bytemapChar)); memset(fontArray->charDef, 0, 256 * sizeof(GRRLIB_bytemapChar));
j++; j++;
for (i=0; i < fontArray->nbChar; i++) { for (u32 i=0; i < fontArray->nbChar; i++) {
const u8 c = my_bmf[++j]; const u8 c = my_bmf[++j];
fontArray->charDef[c].width = my_bmf[++j]; fontArray->charDef[c].width = my_bmf[++j];
fontArray->charDef[c].height = my_bmf[++j]; fontArray->charDef[c].height = my_bmf[++j];
@ -83,7 +83,10 @@ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) {
* @param bmf A GRRLIB_bytemapFont structure. * @param bmf A GRRLIB_bytemapFont structure.
*/ */
void GRRLIB_FreeBMF (GRRLIB_bytemapFont *bmf) { void GRRLIB_FreeBMF (GRRLIB_bytemapFont *bmf) {
if (bmf != NULL) { if (bmf == NULL) {
return;
}
for (u16 i = 0; i < 256; i++) { for (u16 i = 0; i < 256; i++) {
if (bmf->charDef[i].data != NULL) { if (bmf->charDef[i].data != NULL) {
free(bmf->charDef[i].data); free(bmf->charDef[i].data);
@ -93,7 +96,6 @@ void GRRLIB_FreeBMF (GRRLIB_bytemapFont *bmf) {
free(bmf->name); free(bmf->name);
free(bmf); free(bmf);
} }
}
/** /**
* Initialize a tile set. * Initialize a tile set.
@ -115,7 +117,7 @@ void GRRLIB_InitTileSet (GRRLIB_texImg *tex,
} }
tex->tilestart = tilestart; tex->tilestart = tilestart;
tex->tiledtex = true; tex->tiledtex = true;
tex->ofnormaltexx = 1.0F / tex->nbtilew; tex->ofnormaltexx = 1.0f / tex->nbtilew;
tex->ofnormaltexy = 1.0F / tex->nbtileh; tex->ofnormaltexy = 1.0f / tex->nbtileh;
GRRLIB_SetHandle( tex, 0, 0 ); GRRLIB_SetHandle( tex, 0, 0 );
} }

View file

@ -1,5 +1,5 @@
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
Copyright (c) 2009-2017 The GRRLIB Team Copyright (c) 2009-2022 The GRRLIB Team
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -31,10 +31,10 @@ THE SOFTWARE.
* @param texdest The texture destination. * @param texdest The texture destination.
*/ */
void GRRLIB_BMFX_FlipH (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) { void GRRLIB_BMFX_FlipH (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) {
unsigned int x, y, txtWidth = texsrc->w - 1; const u32 txtWidth = texsrc->w - 1;
for (y = 0; y < texsrc->h; y++) { for (u32 y = 0; y < texsrc->h; y++) {
for (x = 0; x < texsrc->w; x++) { for (u32 x = 0; x < texsrc->w; x++) {
GRRLIB_SetPixelTotexImg(txtWidth - x, y, texdest, GRRLIB_SetPixelTotexImg(txtWidth - x, y, texdest,
GRRLIB_GetPixelFromtexImg(x, y, texsrc)); GRRLIB_GetPixelFromtexImg(x, y, texsrc));
} }
@ -48,10 +48,10 @@ void GRRLIB_BMFX_FlipH (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) {
* @param texdest The texture destination. * @param texdest The texture destination.
*/ */
void GRRLIB_BMFX_FlipV (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) { void GRRLIB_BMFX_FlipV (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) {
unsigned int x, y, texHeight = texsrc->h - 1; const u32 texHeight = texsrc->h - 1;
for (y = 0; y < texsrc->h; y++) { for (u32 y = 0; y < texsrc->h; y++) {
for (x = 0; x < texsrc->w; x++) { for (u32 x = 0; x < texsrc->w; x++) {
GRRLIB_SetPixelTotexImg(x, texHeight - y, texdest, GRRLIB_SetPixelTotexImg(x, texHeight - y, texdest,
GRRLIB_GetPixelFromtexImg(x, y, texsrc)); GRRLIB_GetPixelFromtexImg(x, y, texsrc));
} }
@ -66,13 +66,11 @@ void GRRLIB_BMFX_FlipV (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) {
*/ */
void GRRLIB_BMFX_Grayscale (const GRRLIB_texImg *texsrc, void GRRLIB_BMFX_Grayscale (const GRRLIB_texImg *texsrc,
GRRLIB_texImg *texdest) { GRRLIB_texImg *texdest) {
unsigned int x, y; for (u32 y = 0; y < texsrc->h; y++) {
for (u32 x = 0; x < texsrc->w; x++) {
const u32 color = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
for (y = 0; y < texsrc->h; y++) { const u8 gray = ((R(color) * 77 +
for (x = 0; x < texsrc->w; x++) {
u32 color = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
u8 gray = ((R(color)* 77 +
G(color) * 150 + G(color) * 150 +
B(color) * 28 ) / 255); B(color) * 28 ) / 255);
@ -91,18 +89,16 @@ void GRRLIB_BMFX_Grayscale (const GRRLIB_texImg *texsrc,
* @author elisherer * @author elisherer
*/ */
void GRRLIB_BMFX_Sepia (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) { void GRRLIB_BMFX_Sepia (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) {
unsigned int x, y; for (u32 y = 0; y < texsrc->h; y++) {
u16 sr, sg, sb; for (u32 x = 0; x < texsrc->w; x++) {
u32 color; const u32 color = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
u16 sr = R(color)*0.393 + G(color)*0.769 + B(color)*0.189;
for (y = 0; y < texsrc->h; y++) { u16 sg = R(color)*0.349 + G(color)*0.686 + B(color)*0.168;
for (x = 0; x < texsrc->w; x++) { u16 sb = R(color)*0.272 + G(color)*0.534 + B(color)*0.131;
color = GRRLIB_GetPixelFromtexImg(x, y, texsrc); if (sr > 255)
sr = R(color)*0.393 + G(color)*0.769 + B(color)*0.189; sr = 255;
sg = R(color)*0.349 + G(color)*0.686 + B(color)*0.168; if (sg > 255)
sb = R(color)*0.272 + G(color)*0.534 + B(color)*0.131; sg = 255;
if (sr>255) sr=255;
if (sg>255) sg=255;
GRRLIB_SetPixelTotexImg(x, y, texdest, GRRLIB_SetPixelTotexImg(x, y, texdest,
RGBA(sr, sg, sb, A(color))); RGBA(sr, sg, sb, A(color)));
} }
@ -116,12 +112,9 @@ void GRRLIB_BMFX_Sepia (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) {
* @param texdest The texture destination. * @param texdest The texture destination.
*/ */
void GRRLIB_BMFX_Invert (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) { void GRRLIB_BMFX_Invert (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) {
unsigned int x, y; for (u32 y = 0; y < texsrc->h; y++) {
u32 color; for (u32 x = 0; x < texsrc->w; x++) {
const u32 color = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
for (y = 0; y < texsrc->h; y++) {
for (x = 0; x < texsrc->w; x++) {
color = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
GRRLIB_SetPixelTotexImg(x, y, texdest, GRRLIB_SetPixelTotexImg(x, y, texdest,
((0xFFFFFF - (color >> 8 & 0xFFFFFF)) << 8) | (color & 0xFF)); ((0xFFFFFF - (color >> 8 & 0xFFFFFF)) << 8) | (color & 0xFF));
} }
@ -137,26 +130,21 @@ void GRRLIB_BMFX_Invert (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) {
*/ */
void GRRLIB_BMFX_Blur (const GRRLIB_texImg *texsrc, void GRRLIB_BMFX_Blur (const GRRLIB_texImg *texsrc,
GRRLIB_texImg *texdest, const u32 factor) { GRRLIB_texImg *texdest, const u32 factor) {
int numba = (1+(factor<<1))*(1+(factor<<1)); const int numba = (1 + (factor << 1)) * (1 + (factor << 1));
u32 x, y;
s32 k, l;
int tmp;
int newr, newg, newb, newa;
u32 colours[numba]; u32 colours[numba];
u32 thiscol;
for (x = 0; x < texsrc->w; x++) { for (u32 x = 0; x < texsrc->w; x++) {
for (y = 0; y < texsrc->h; y++) { for (u32 y = 0; y < texsrc->h; y++) {
newr = 0; int newr = 0;
newg = 0; int newg = 0;
newb = 0; int newb = 0;
newa = 0; int newa = 0;
tmp = 0; int tmp = 0;
thiscol = GRRLIB_GetPixelFromtexImg(x, y, texsrc); const u32 thiscol = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
for (k = x - factor; k <= x + factor; k++) { for (s32 k = x - factor; k <= x + factor; k++) {
for (l = y - factor; l <= y + factor; l++) { for (s32 l = y - factor; l <= y + factor; l++) {
if (k < 0 || k >= texsrc->w || l < 0 || l >= texsrc->h) { if (k < 0 || k >= texsrc->w || l < 0 || l >= texsrc->h) {
colours[tmp] = thiscol; colours[tmp] = thiscol;
} }
@ -193,21 +181,18 @@ void GRRLIB_BMFX_Blur (const GRRLIB_texImg *texsrc,
*/ */
void GRRLIB_BMFX_Scatter (const GRRLIB_texImg *texsrc, void GRRLIB_BMFX_Scatter (const GRRLIB_texImg *texsrc,
GRRLIB_texImg *texdest, const u32 factor) { GRRLIB_texImg *texdest, const u32 factor) {
unsigned int x, y; const int factorx2 = factor * 2;
u32 val1, val2;
u32 val3, val4;
int factorx2 = factor*2;
for (y = 0; y < texsrc->h; y++) { for (u32 y = 0; y < texsrc->h; y++) {
for (x = 0; x < texsrc->w; x++) { for (u32 x = 0; x < texsrc->w; x++) {
val1 = x + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor; const u32 val1 = x + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor;
val2 = y + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor; const u32 val2 = y + (int) (factorx2 * (rand() / (RAND_MAX + 1.0))) - factor;
if ((val1 >= texsrc->w) || (val2 >= texsrc->h)) { if ((val1 >= texsrc->w) || (val2 >= texsrc->h)) {
} }
else { else {
val3 = GRRLIB_GetPixelFromtexImg(x, y, texsrc); const u32 val3 = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
val4 = GRRLIB_GetPixelFromtexImg(val1, val2, texsrc); const u32 val4 = GRRLIB_GetPixelFromtexImg(val1, val2, texsrc);
GRRLIB_SetPixelTotexImg(x, y, texdest, val4); GRRLIB_SetPixelTotexImg(x, y, texdest, val4);
GRRLIB_SetPixelTotexImg(val1, val2, texdest, val3); GRRLIB_SetPixelTotexImg(val1, val2, texdest, val3);
} }
@ -224,15 +209,11 @@ void GRRLIB_BMFX_Scatter (const GRRLIB_texImg *texsrc,
*/ */
void GRRLIB_BMFX_Pixelate (const GRRLIB_texImg *texsrc, void GRRLIB_BMFX_Pixelate (const GRRLIB_texImg *texsrc,
GRRLIB_texImg *texdest, const u32 factor) { GRRLIB_texImg *texdest, const u32 factor) {
unsigned int x, y; for (u32 x = 0; x < texsrc->w - 1 - factor; x += factor) {
unsigned int xx, yy; for (u32 y = 0; y < texsrc->h - 1 - factor; y +=factor) {
u32 rgb; const u32 rgb = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
for (u32 xx = x; xx < x + factor; xx++) {
for (x = 0; x < texsrc->w - 1 - factor; x += factor) { for (u32 yy = y; yy < y + factor; yy++) {
for (y = 0; y < texsrc->h - 1 - factor; y +=factor) {
rgb = GRRLIB_GetPixelFromtexImg(x, y, texsrc);
for (xx = x; xx < x + factor; xx++) {
for (yy = y; yy < y + factor; yy++) {
GRRLIB_SetPixelTotexImg(xx, yy, texdest, rgb); GRRLIB_SetPixelTotexImg(xx, yy, texdest, rgb);
} }
} }

View file

@ -176,7 +176,7 @@ int GRRLIB_Init (void) {
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
guMtxIdentity(GXmodelView2D); guMtxIdentity(GXmodelView2D);
guMtxTransApply(GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -100.0F); guMtxTransApply(GXmodelView2D, GXmodelView2D, 0.0f, 0.0f, -100.0f);
GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0); GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0);
guOrtho(perspective, 0.0f, rmode->efbHeight, 0.0f, rmode->fbWidth, 0.0f, 1000.0f); guOrtho(perspective, 0.0f, rmode->efbHeight, 0.0f, rmode->fbWidth, 0.0f, 1000.0f);
@ -223,9 +223,7 @@ void GRRLIB_Exit (void) {
if (done == true || is_setup == false) { if (done == true || is_setup == false) {
return; return;
} }
else {
done = true; done = true;
}
// Allow write access to the full screen // Allow write access to the full screen
GX_SetClipMode( GX_CLIP_DISABLE ); GX_SetClipMode( GX_CLIP_DISABLE );
@ -233,8 +231,10 @@ void GRRLIB_Exit (void) {
// We empty both frame buffers on our way out // We empty both frame buffers on our way out
// otherwise dead frames are sometimes seen when starting the next app // otherwise dead frames are sometimes seen when starting the next app
GRRLIB_FillScreen( 0x000000FF ); GRRLIB_Render(); GRRLIB_FillScreen( 0x000000FF );
GRRLIB_FillScreen( 0x000000FF ); GRRLIB_Render(); GRRLIB_Render();
GRRLIB_FillScreen( 0x000000FF );
GRRLIB_Render();
// Shut down the GX engine // Shut down the GX engine
GX_DrawDone(); GX_DrawDone();

View file

@ -29,7 +29,7 @@ THE SOFTWARE.
* @param tex A pointer to a texture representing the screen. * @param tex A pointer to a texture representing the screen.
* @param clear When this flag is set to @c true, the screen is cleared after copy. * @param clear When this flag is set to @c true, the screen is cleared after copy.
*/ */
void GRRLIB_Screen2Texture (int posx, int posy, GRRLIB_texImg *tex, bool clear) { void GRRLIB_Screen2Texture (u16 posx, u16 posy, GRRLIB_texImg *tex, bool clear) {
if(tex == NULL || tex->data == NULL) { if(tex == NULL || tex->data == NULL) {
return; return;
} }
@ -60,7 +60,7 @@ void GRRLIB_CompoStart (void) {
* @param posy Top left corner of the grabbed part. * @param posy Top left corner of the grabbed part.
* @param tex A pointer to a texture representing the screen. * @param tex A pointer to a texture representing the screen.
*/ */
void GRRLIB_CompoEnd(int posx, int posy, GRRLIB_texImg *tex) { void GRRLIB_CompoEnd(u16 posx, u16 posy, GRRLIB_texImg *tex) {
GRRLIB_Screen2Texture(posx, posy, tex, GX_TRUE); GRRLIB_Screen2Texture(posx, posy, tex, GX_TRUE);
if (rmode->aa) { if (rmode->aa) {

View file

@ -364,7 +364,7 @@ GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg) {
* @param my_size Size of the JPEG buffer to load. * @param my_size Size of the JPEG buffer to load.
* @return A GRRLIB_texImg structure filled with image information. * @return A GRRLIB_texImg structure filled with image information.
*/ */
GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const int my_size) { GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const u32 my_size) {
GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg)); GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg));
if (my_texture == NULL) { if (my_texture == NULL) {

View file

@ -1,5 +1,5 @@
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
Copyright (c) 2009-2017 The GRRLIB Team Copyright (c) 2009-2022 The GRRLIB Team
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -44,8 +44,8 @@ THE SOFTWARE.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// GRRLIB_clipping.h - Clipping control // GRRLIB_clipping.h - Clipping control
INLINE void GRRLIB_ClipReset (void); INLINE void GRRLIB_ClipReset (void);
INLINE void GRRLIB_ClipDrawing (const int x, const int y, INLINE void GRRLIB_ClipDrawing (const u32 x, const u32 y,
const int width, const int height); const u32 width, const u32 height);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// GRRLIB_collision.h - Collision detection // GRRLIB_collision.h - Collision detection
@ -66,16 +66,16 @@ INLINE bool GRRLIB_RectOnRect (const int rect1x, const int rect1y,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// GRRLIB_fbComplex.h - // GRRLIB_fbComplex.h -
INLINE void GRRLIB_NPlot (const guVector v[], const u32 color[], INLINE void GRRLIB_NPlot (const guVector v[], const u32 color[],
const long n); const u16 n);
INLINE void GRRLIB_NGone (const guVector v[], const u32 color[], INLINE void GRRLIB_NGone (const guVector v[], const u32 color[],
const long n); const u16 n);
INLINE void GRRLIB_NGoneFilled (const guVector v[], const u32 color[], INLINE void GRRLIB_NGoneFilled (const guVector v[], const u32 color[],
const long n); const u16 n);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// GRRLIB_fbGX.h - // GRRLIB_fbGX.h -
INLINE void GRRLIB_GXEngine (const guVector v[], const u32 color[], INLINE void GRRLIB_GXEngine (const guVector v[], const u32 color[],
const long n, const u8 fmt); const u16 n, const u8 fmt);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// GRRLIB_fbSimple.h - // GRRLIB_fbSimple.h -

View file

@ -129,9 +129,9 @@ void GRRLIB_Render (void);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// GRRLIB_snapshot.c - Create a texture containing a snapshot of a part of the framebuffer // GRRLIB_snapshot.c - Create a texture containing a snapshot of a part of the framebuffer
void GRRLIB_Screen2Texture (int posx, int posy, GRRLIB_texImg *tex, bool clear); void GRRLIB_Screen2Texture (u16 posx, u16 posy, GRRLIB_texImg *tex, bool clear);
void GRRLIB_CompoStart (void); void GRRLIB_CompoStart (void);
void GRRLIB_CompoEnd(int posx, int posy, GRRLIB_texImg *tex); void GRRLIB_CompoEnd(u16 posx, u16 posy, GRRLIB_texImg *tex);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// GRRLIB_texEdit.c - Modifying the content of a texture // GRRLIB_texEdit.c - Modifying the content of a texture
@ -139,7 +139,7 @@ GRRLIB_texImg* GRRLIB_CreateEmptyTexture (const u32 width, const u32 height);
GRRLIB_texImg* GRRLIB_LoadTexture (const u8 *my_img); GRRLIB_texImg* GRRLIB_LoadTexture (const u8 *my_img);
GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png); GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png);
GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg); GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg);
GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const int my_size); GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const u32 my_size);
GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp); GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -164,8 +164,8 @@ void GRRLIB_SetTexture(GRRLIB_texImg *tex, bool rep);
void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled, u32 col); void GRRLIB_DrawTorus(f32 r, f32 R, int nsides, int rings, bool filled, u32 col);
void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled, u32 col); void GRRLIB_DrawSphere(f32 r, int lats, int longs, bool filled, u32 col);
void GRRLIB_DrawCube(f32 size, bool filled, u32 col); void GRRLIB_DrawCube(f32 size, bool filled, u32 col);
void GRRLIB_DrawCylinder(f32 r, f32 h, int d, bool filled, u32 col); void GRRLIB_DrawCylinder(f32 r, f32 h, u16 d, bool filled, u32 col);
void GRRLIB_DrawCone(f32 r, f32 h, int d, bool filled, u32 col); void GRRLIB_DrawCone(f32 r, f32 h, u16 d, bool filled, u32 col);
void GRRLIB_DrawTessPanel(f32 w, f32 wstep, f32 h, f32 hstep, bool filled, u32 col); void GRRLIB_DrawTessPanel(f32 w, f32 wstep, f32 h, f32 hstep, bool filled, u32 col);
void GRRLIB_SetLightAmbient(u32 ambientcolor); void GRRLIB_SetLightAmbient(u32 ambientcolor);
void GRRLIB_SetLightDiff(u8 num, guVector pos, f32 distattn, f32 brightness, u32 lightcolor); void GRRLIB_SetLightDiff(u8 num, guVector pos, f32 distattn, f32 brightness, u32 lightcolor);

View file

@ -1,5 +1,5 @@
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
Copyright (c) 2009-2017 The GRRLIB Team Copyright (c) 2009-2022 The GRRLIB Team
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -42,8 +42,8 @@ void GRRLIB_ClipReset (void) {
* @param height The height of the rectangle. * @param height The height of the rectangle.
*/ */
INLINE INLINE
void GRRLIB_ClipDrawing (const int x, const int y, void GRRLIB_ClipDrawing (const u32 x, const u32 y,
const int width, const int height) { const u32 width, const u32 height) {
GX_SetClipMode( GX_CLIP_ENABLE ); GX_SetClipMode( GX_CLIP_ENABLE );
GX_SetScissor( x, y, width, height ); GX_SetScissor( x, y, width, height );
} }

View file

@ -1,5 +1,5 @@
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
Copyright (c) 2009-2017 The GRRLIB Team Copyright (c) 2009-2022 The GRRLIB Team
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -29,10 +29,10 @@ THE SOFTWARE.
* Draw an array of points. * Draw an array of points.
* @param v Array containing the points. * @param v Array containing the points.
* @param color The color of the points in RGBA format. * @param color The color of the points in RGBA format.
* @param n Number of points in the vector array. * @param n Number of points in the vector array. The maximum is 65536.
*/ */
INLINE INLINE
void GRRLIB_NPlot (const guVector v[], const u32 color[], const long n) { void GRRLIB_NPlot (const guVector v[], const u32 color[], const u16 n) {
GRRLIB_GXEngine(v, color, n, GX_POINTS); GRRLIB_GXEngine(v, color, n, GX_POINTS);
} }
@ -40,10 +40,10 @@ void GRRLIB_NPlot (const guVector v[], const u32 color[], const long n) {
* Draw a polygon. * Draw a polygon.
* @param v The vector containing the coordinates of the polygon. * @param v The vector containing the coordinates of the polygon.
* @param color The color of the filled polygon in RGBA format. * @param color The color of the filled polygon in RGBA format.
* @param n Number of points in the vector. * @param n Number of points in the vector. The maximum is 65536.
*/ */
INLINE INLINE
void GRRLIB_NGone (const guVector v[], const u32 color[], const long n) { void GRRLIB_NGone (const guVector v[], const u32 color[], const u16 n) {
GRRLIB_GXEngine(v, color, n, GX_LINESTRIP); GRRLIB_GXEngine(v, color, n, GX_LINESTRIP);
} }
@ -51,9 +51,9 @@ void GRRLIB_NGone (const guVector v[], const u32 color[], const long n) {
* Draw a filled polygon. * Draw a filled polygon.
* @param v The vector containing the coordinates of the polygon. * @param v The vector containing the coordinates of the polygon.
* @param color The color of the filled polygon in RGBA format. * @param color The color of the filled polygon in RGBA format.
* @param n Number of points in the vector. * @param n Number of points in the vector. The maximum is 65536.
*/ */
INLINE INLINE
void GRRLIB_NGoneFilled (const guVector v[], const u32 color[], const long n) { void GRRLIB_NGoneFilled (const guVector v[], const u32 color[], const u16 n) {
GRRLIB_GXEngine(v, color, n, GX_TRIANGLEFAN); GRRLIB_GXEngine(v, color, n, GX_TRIANGLEFAN);
} }

View file

@ -1,5 +1,5 @@
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
Copyright (c) 2009-2021 The GRRLIB Team Copyright (c) 2009-2022 The GRRLIB Team
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -29,14 +29,14 @@ THE SOFTWARE.
* Draws a vector. * Draws a vector.
* @param v The vector to draw. * @param v The vector to draw.
* @param color The color of the vector in RGBA format. * @param color The color of the vector in RGBA format.
* @param n Number of points in the vector. * @param n Number of points in the vector. The maximum is 65536.
* @param fmt Type of primitive. * @param fmt Type of primitive.
*/ */
INLINE INLINE
void GRRLIB_GXEngine (const guVector v[], const u32 color[], const long n, void GRRLIB_GXEngine (const guVector v[], const u32 color[], const u16 n,
const u8 fmt) { const u8 fmt) {
GX_Begin(fmt, GX_VTXFMT0, n); GX_Begin(fmt, GX_VTXFMT0, n);
for (int i = 0; i < n; i++) { for (u16 i = 0; i < n; i++) {
GX_Position3f32(v[i].x, v[i].y, v[i].z); GX_Position3f32(v[i].x, v[i].y, v[i].z);
GX_Color1u32(color[i]); GX_Color1u32(color[i]);
} }

View file

@ -46,13 +46,14 @@ void GRRLIB_FlushTex (GRRLIB_texImg *tex) {
*/ */
INLINE INLINE
void GRRLIB_FreeTexture (GRRLIB_texImg *tex) { void GRRLIB_FreeTexture (GRRLIB_texImg *tex) {
if(tex != NULL) { if(tex == NULL) {
return;
}
if (tex->data != NULL) { if (tex->data != NULL) {
free(tex->data); free(tex->data);
} }
free(tex); free(tex);
} }
}
/** /**
* Clear a texture to transparent black. * Clear a texture to transparent black.

View file

@ -13,7 +13,7 @@
int main() { int main() {
float a = 0; float a = 0;
u32 col[3] = {0xFFFFFFFF, 0xAAAAAAFF, 0x666666FF}; const u32 col[3] = {0xFFFFFFFF, 0xAAAAAAFF, 0x666666FF};
int cubeZ = 0; int cubeZ = 0;
GRRLIB_Init(); GRRLIB_Init();

View file

@ -196,7 +196,7 @@ int main() {
} }
else if(demo == 4) { else if(demo == 4) {
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_NRM, GX_TEXMTX0); // We say we use the Normal coord to map the texture (since there is no textcoord with this torus) GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_NRM, GX_TEXMTX0); // We say we use the Normal coord to map the texture (since there is no textcoord with this torus)
guLightFrustum(mv, 1.0F, -1.0F, 1.0F, -1.0F, 1.0F, 0.5F, 0.5F, 0.5F, 0.5F); // we are projecting the texture like a light (ie : videoprojector)) guLightFrustum(mv, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 0.5f); // we are projecting the texture like a light (ie : videoprojector))
guMtxScale(mr, -2.8f, -2.8f, 0.0f); //here is a little scaling to fit the torus guMtxScale(mr, -2.8f, -2.8f, 0.0f); //here is a little scaling to fit the torus
guMtxConcat(mr, mv, mv); guMtxConcat(mr, mv, mv);
@ -218,7 +218,7 @@ int main() {
} }
else if(demo == 5) { else if(demo == 5) {
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_NRM, GX_TEXMTX0); // We say we use the Normal coord to map the texture (since there is no textcoord with this torus) GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_NRM, GX_TEXMTX0); // We say we use the Normal coord to map the texture (since there is no textcoord with this torus)
guLightFrustum(mv, 1.0F, -1.0F, 1.0F, -1.0F, 1.0F, 0.5F, 0.5F, 0.5F, 0.5F); // we are projecting the texture like a light (ie : videoprojector)) guLightFrustum(mv, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 0.5f); // we are projecting the texture like a light (ie : videoprojector))
guMtxRotDeg(rx, 'X', a); // Here i rotate the texture guMtxRotDeg(rx, 'X', a); // Here i rotate the texture
guMtxRotDeg(ry, 'Y', a*2); // in the inverse way guMtxRotDeg(ry, 'Y', a*2); // in the inverse way
guMtxRotDeg(rz, 'Z', a*3); // of the guMtxRotDeg(rz, 'Z', a*3); // of the

View file

@ -10,71 +10,61 @@
int main() { int main() {
int offset1, offset2, offset3, offset4;
int periode1, periode2, periode3, periode4;
int length1, length2, length3, length4;
int amp1, amp2, amp3, amp4;
int origine1, origine2, origine3, origine4;
int adc1, adc2, adc3, adc4;
float siny1, siny2, siny3, siny4;
int x;
float pas1, pas2, pas3, pas4;
// Initialise the Graphics & Video subsystem // Initialise the Graphics & Video subsystem
GRRLIB_Init(); GRRLIB_Init();
// Initialise the Wiimotes // Initialise the Wii Remotes
WPAD_Init(); WPAD_Init();
adc1=0; const int adc1=0;
offset1=0; const int offset1=0;
origine1=0; const int origin1=0;
length1=1280; const int length1=1280;
amp1=100; const int amp1=100;
periode1=1; const int period1=1;
pas1=(periode1*360.0F)/length1; const float pas1=(period1*360.0f)/length1;
siny1 = offset1*pas1; float siny1 = offset1*pas1;
adc2=1; const int adc2=1;
offset2=0; const int offset2=0;
origine2=0; const int origin2=0;
length2=1280; const int length2=1280;
amp2=40; const int amp2=40;
periode2=2; const int period2=2;
pas2=(periode2*360.0F)/length2; const float pas2=(period2*360.0f)/length2;
siny2 = offset2*pas2; float siny2 = offset2*pas2;
adc3=-3; const int adc3=-3;
offset3=0; const int offset3=0;
origine3=0; const int origin3=0;
length3=1280; const int length3=1280;
amp3=30; const int amp3=30;
periode3=1; const int period3=1;
pas3=(periode3*360.0F)/length3; const float pas3=(period3*360.0f)/length3;
siny3 = offset3*pas3; float siny3 = offset3*pas3;
adc4=-7; const int adc4=-7;
offset4=0; const int offset4=0;
origine4=0; const int origin4=0;
length4=1280; const int length4=1280;
amp4=70; const int amp4=70;
periode4=1; const int period4=1;
pas4=(periode4*360.0F)/length4; const float pas4=(period4*360.0f)/length4;
siny4 = offset4*pas4; float siny4 = offset4*pas4;
while (1) { while (1) {
GRRLIB_FillScreen(0x000000FF); GRRLIB_FillScreen(0x000000FF);
WPAD_ScanPads(); // Scan the Wiimotes WPAD_ScanPads(); // Scan the Wii Remotes
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) break; if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) break;
float old1=siny1; const float old1=siny1;
float old2=siny2; const float old2=siny2;
float old3=siny3; const float old3=siny3;
float old4=siny4; const float old4=siny4;
for (x=0; x<=640; x++) { for (u16 x=0; x<=640; x++) {
siny1+=pas1; siny1+=pas1;
siny2+=pas2; siny2+=pas2;
siny3+=pas3; siny3+=pas3;
@ -83,11 +73,11 @@ int main() {
GX_Begin(GX_LINES, GX_VTXFMT0, 2); GX_Begin(GX_LINES, GX_VTXFMT0, 2);
GX_Position3f32(x, 0, 0); GX_Position3f32(x, 0, 0);
GX_Color1u32(0x000000FF); GX_Color1u32(0x000000FF);
GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origine1)+(sin(DegToRad(siny2))*amp2+origine2)+(sin(DegToRad(siny3))*amp3+origine3)+(sin(DegToRad(siny4))*amp4+origine4)+240, 0); GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origin1)+(sin(DegToRad(siny2))*amp2+origin2)+(sin(DegToRad(siny3))*amp3+origin3)+(sin(DegToRad(siny4))*amp4+origin4)+240, 0);
GX_Color1u32(0xFF00007F); GX_Color1u32(0xFF00007F);
GX_End(); GX_End();
GX_Begin(GX_LINES, GX_VTXFMT0, 2); GX_Begin(GX_LINES, GX_VTXFMT0, 2);
GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origine1)+(sin(DegToRad(siny2))*amp2+origine2)+(sin(DegToRad(siny3))*amp3+origine3)+(sin(DegToRad(siny4))*amp4+origine4)+240, 0); GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origin1)+(sin(DegToRad(siny2))*amp2+origin2)+(sin(DegToRad(siny3))*amp3+origin3)+(sin(DegToRad(siny4))*amp4+origin4)+240, 0);
GX_Color1u32(0xFF00007F); GX_Color1u32(0xFF00007F);
GX_Position3f32(x, 480, 0); GX_Position3f32(x, 480, 0);
GX_Color1u32(0x000000FF); GX_Color1u32(0x000000FF);

View file

@ -13,7 +13,7 @@
int main() { int main() {
float a = 0; float a = 0;
u32 col[3] = {0xFFFFFFFF, 0xAAAAAAFF, 0x666666FF}; const u32 col[3] = {0xFFFFFFFF, 0xAAAAAAFF, 0x666666FF};
int cubeZ = 0; int cubeZ = 0;
GRRLIB_Init(); GRRLIB_Init();

View file

@ -10,16 +10,6 @@
int main() { int main() {
int offset1, offset2, offset3, offset4;
int periode1, periode2, periode3, periode4;
int length1, length2, length3, length4;
int amp1, amp2, amp3, amp4;
int origine1, origine2, origine3, origine4;
int adc1, adc2, adc3, adc4;
float siny1, siny2, siny3, siny4;
int x;
float pas1, pas2, pas3, pas4;
// Initialise the Graphics & Video subsystem // Initialise the Graphics & Video subsystem
GRRLIB_Init(); GRRLIB_Init();
@ -27,54 +17,54 @@ int main() {
PAD_Init(); PAD_Init();
adc1=0; const int adc1=0;
offset1=0; const int offset1=0;
origine1=0; const int origin1=0;
length1=1280; const int length1=1280;
amp1=100; const int amp1=100;
periode1=1; const int period1=1;
pas1=(periode1*360.0F)/length1; const float pas1=(period1*360.0f)/length1;
siny1 = offset1*pas1; float siny1 = offset1*pas1;
adc2=1; const int adc2=1;
offset2=0; const int offset2=0;
origine2=0; const int origin2=0;
length2=1280; const int length2=1280;
amp2=40; const int amp2=40;
periode2=2; const int period2=2;
pas2=(periode2*360.0F)/length2; const float pas2=(period2*360.0f)/length2;
siny2 = offset2*pas2; float siny2 = offset2*pas2;
adc3=-3; const int adc3=-3;
offset3=0; const int offset3=0;
origine3=0; const int origin3=0;
length3=1280; const int length3=1280;
amp3=30; const int amp3=30;
periode3=1; const int period3=1;
pas3=(periode3*360.0F)/length3; const float pas3=(period3*360.0f)/length3;
siny3 = offset3*pas3; float siny3 = offset3*pas3;
adc4=-7; const int adc4=-7;
offset4=0; const int offset4=0;
origine4=0; const int origin4=0;
length4=1280; const int length4=1280;
amp4=70; const int amp4=70;
periode4=1; const int period4=1;
pas4=(periode4*360.0F)/length4; const float pas4=(period4*360.0f)/length4;
siny4 = offset4*pas4; float siny4 = offset4*pas4;
while (1) { while (1) {
GRRLIB_FillScreen(0x000000FF); GRRLIB_FillScreen(0x000000FF);
PAD_ScanPads(); // Scan the GameCube controllers PAD_ScanPads(); // Scan the GameCube controllers
if (PAD_ButtonsDown(0) & PAD_BUTTON_START) break; if (PAD_ButtonsDown(0) & PAD_BUTTON_START) break;
float old1=siny1; const float old1=siny1;
float old2=siny2; const float old2=siny2;
float old3=siny3; const float old3=siny3;
float old4=siny4; const float old4=siny4;
for (x=0; x<=640; x++) { for (u16 x=0; x<=640; x++) {
siny1+=pas1; siny1+=pas1;
siny2+=pas2; siny2+=pas2;
siny3+=pas3; siny3+=pas3;
@ -83,11 +73,11 @@ int main() {
GX_Begin(GX_LINES, GX_VTXFMT0, 2); GX_Begin(GX_LINES, GX_VTXFMT0, 2);
GX_Position3f32(x, 0, 0); GX_Position3f32(x, 0, 0);
GX_Color1u32(0x000000FF); GX_Color1u32(0x000000FF);
GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origine1)+(sin(DegToRad(siny2))*amp2+origine2)+(sin(DegToRad(siny3))*amp3+origine3)+(sin(DegToRad(siny4))*amp4+origine4)+240, 0); GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origin1)+(sin(DegToRad(siny2))*amp2+origin2)+(sin(DegToRad(siny3))*amp3+origin3)+(sin(DegToRad(siny4))*amp4+origin4)+240, 0);
GX_Color1u32(0xFF00007F); GX_Color1u32(0xFF00007F);
GX_End(); GX_End();
GX_Begin(GX_LINES, GX_VTXFMT0, 2); GX_Begin(GX_LINES, GX_VTXFMT0, 2);
GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origine1)+(sin(DegToRad(siny2))*amp2+origine2)+(sin(DegToRad(siny3))*amp3+origine3)+(sin(DegToRad(siny4))*amp4+origine4)+240, 0); GX_Position3f32(x, (sin(DegToRad(siny1))*amp1+origin1)+(sin(DegToRad(siny2))*amp2+origin2)+(sin(DegToRad(siny3))*amp3+origin3)+(sin(DegToRad(siny4))*amp4+origin4)+240, 0);
GX_Color1u32(0xFF00007F); GX_Color1u32(0xFF00007F);
GX_Position3f32(x, 480, 0); GX_Position3f32(x, 480, 0);
GX_Color1u32(0x000000FF); GX_Color1u32(0x000000FF);