GRRLIB/examples/gamecube/3D_sample2/source/main.c

137 lines
4.4 KiB
C
Raw Permalink Normal View History

2022-05-28 05:27:55 +00:00
/*===========================================
NoNameNo
Simple Textured 3D cube
============================================*/
#include <grrlib.h>
#include <stdlib.h>
#include <math.h>
#include <malloc.h>
#include <ogc/pad.h>
#include "font_png.h"
#include "girl_png.h"
int main() {
float a=0;
int cubeZ=0;
GRRLIB_Init();
PAD_Init();
GRRLIB_texImg *tex_girl= GRRLIB_LoadTexture(girl_png);
GRRLIB_texImg *tex_font = GRRLIB_LoadTexture(font_png);
GRRLIB_InitTileSet(tex_font, 16, 16, 32);
GRRLIB_Settings.antialias = true;
GRRLIB_SetBackgroundColour(0x00, 0x00, 0x00, 0xFF);
GRRLIB_Camera3dSettings(0.0f,0.0f,13.0f, 0,1,0, 0,0,0);
while(1) {
GRRLIB_2dMode();
PAD_ScanPads();
if(PAD_ButtonsDown(0) & PAD_BUTTON_START) exit(0);
if(PAD_ButtonsHeld(0) & PAD_BUTTON_A) cubeZ++;
if(PAD_ButtonsHeld(0) & PAD_BUTTON_B) cubeZ--;
GRRLIB_3dMode(0.1,1000,45,1,0);
2024-04-02 05:40:42 +00:00
GRRLIB_SetTexture(tex_girl, FALSE);
2022-05-28 05:27:55 +00:00
GRRLIB_ObjectView(0,0,cubeZ, a,a*2,a*3,1,1,1);
GX_Begin(GX_QUADS, GX_VTXFMT0, 24);
GX_Position3f32(-1.0f,1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,0.0f);
GX_Position3f32(1.0f,1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(1.0f,0.0f);
GX_Position3f32(1.0f,-1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(1.0f,1.0f);
GX_Position3f32(-1.0f,-1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,1.0f);
GX_Position3f32(1.0f,1.0f,-1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,0.0f);
GX_Position3f32(-1.0f,1.0f,-1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(1.0f,0.0f);
GX_Position3f32(-1.0f,-1.0f,-1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(1.0f,1.0f);
GX_Position3f32(1.0f,-1.0f,-1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,1.0f);
GX_Position3f32(1.0f,1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,0.0f);
GX_Position3f32(1.0f,1.0f,-1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(1.0f,0.0f);
GX_Position3f32(1.0f,-1.0f,-1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(1.0f,1.0f);
GX_Position3f32(1.0f,-1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,1.0f);
GX_Position3f32(-1.0f,1.0f,-1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,0.0f);
GX_Position3f32(-1.0f,1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(1.0f,0.0f);
GX_Position3f32(-1.0f,-1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(1.0f,1.0f);
GX_Position3f32(-1.0f,-1.0f,-1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,1.0f);
GX_Position3f32(-1.0f,1.0f,-1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,0.0f);
GX_Position3f32(1.0f,1.0f,-1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(1.0f,0.0f);
GX_Position3f32(1.0f,1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(1.0f,1.0f);
GX_Position3f32(-1.0f,1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,1.0f);
GX_Position3f32(1.0f,-1.0f,-1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,0.0f);
GX_Position3f32(-1.0f,-1.0f,-1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(1.0f,0.0f);
GX_Position3f32(-1.0f,-1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(1.0f,1.0f);
GX_Position3f32(1.0f,-1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,1.0f);
GX_End();
a+=0.5f;
// Switch To 2D Mode to display text
GRRLIB_2dMode();
GRRLIB_Printf((640-(16*29))/2, 20, tex_font, 0xFFFFFFFF, 1, "PRESS A OR B TO ZOOM THE CUBE");
GRRLIB_Render();
}
GRRLIB_FreeTexture(tex_girl);
GRRLIB_FreeTexture(tex_font);
GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
exit(0);
}