GRRLIB/examples/3D_Light1/source/main.c

87 lines
2.7 KiB
C
Raw Permalink Normal View History

/*===========================================
NoNameNo
Simple Diffuse light sample code
============================================*/
#include <grrlib.h>
#include <stdlib.h>
#include <math.h>
#include <wiiuse/wpad.h>
#include "Letter_Gothic_Std_14_Bold_png.h"
int main() {
2010-04-06 17:04:57 +00:00
float l1=0, l2=0;
float a=0;
int camZ=13.0f;
GRRLIB_Init();
WPAD_Init();
GRRLIB_texImg *tex_font = GRRLIB_LoadTexture(Letter_Gothic_Std_14_Bold_png);
GRRLIB_InitTileSet(tex_font, 11, 24, 32);
GRRLIB_Settings.antialias = true;
GRRLIB_SetBackgroundColour(0x00, 0x00, 0x00, 0xFF);
while(1) {
GRRLIB_2dMode();
WPAD_ScanPads();
if(WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) break;
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_PLUS) camZ++;
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_MINUS) camZ--;
GRRLIB_Camera3dSettings(0.0f,0.0f,camZ, 0,1,0, 0,0,0);
2010-04-06 17:04:57 +00:00
GRRLIB_SetLightAmbient(0x333333FF);
2022-05-25 04:10:17 +00:00
GRRLIB_3dMode(0.1, 1000, 45, 0, 1);
2010-04-06 19:03:51 +00:00
2010-04-06 17:04:57 +00:00
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A) {
2010-04-06 19:03:51 +00:00
// Set all light off to get the sphere no light sourced (only get the vertex color)
2010-04-06 17:04:57 +00:00
GRRLIB_SetLightOff();
GRRLIB_ObjectView(sin(l1)*4.0f,0.0f,cos(l1)*4.0f, 0,0,0,1,1,1);
GRRLIB_DrawSphere(0.2f, 20, 20, true, 0xFF0000FF);
}
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_B) {
2010-04-06 19:03:51 +00:00
// Set all light off to get the sphere no light sourced (only get the vertex color)
2010-04-06 17:04:57 +00:00
GRRLIB_SetLightOff();
GRRLIB_ObjectView(0.0f,sin(l2)*4.0f,cos(l2)*4.0f, 0,0,0,1,1,1);
GRRLIB_DrawSphere(0.2f, 20, 20, true, 0x00FF00FF);
}
2010-04-06 19:03:51 +00:00
// Set a dummy black light to get the ambient one when no light is selected
GRRLIB_SetLightDiff(0,(guVector){0.0f,0.0f,0.0f},20.0f,1.0f,0x000000FF);
2010-04-06 17:04:57 +00:00
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A) {
GRRLIB_SetLightDiff(0,(guVector){sin(l1)*4.0f,0.0f,cos(l1)*4.0f},20.0f,1.0f,0xFF0000FF);
2010-04-06 19:03:51 +00:00
l1+=0.03f;
2010-04-06 17:04:57 +00:00
}
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_B) {
GRRLIB_SetLightDiff(1,(guVector){0.0f,sin(l2)*4.0f,cos(l2)*4.0f},20.0f,1.0f,0x00FF00FF);
2010-04-06 19:03:51 +00:00
l2+=0.05f;
2010-04-06 17:04:57 +00:00
}
GRRLIB_ObjectView(0,0,0, a,a*2,a*3,1,1,1);
2010-04-06 17:04:57 +00:00
GRRLIB_DrawTorus(1, 2, 60, 60, true, 0xFFFFFFFF);
a+=0.5f;
2010-04-06 17:04:57 +00:00
// Switch to 2D Mode to display text
GRRLIB_2dMode();
GRRLIB_Printf((640-(16*29))/2, 20, tex_font, 0xFFFFFFFF, 1, "PRESS + OR - TO ZOOM");
GRRLIB_Printf((640-(16*29))/2, 40, tex_font, 0xFFFFFFFF, 1, "HOLD A - RED / B - GREEN");
GRRLIB_Render();
}
GRRLIB_FreeTexture(tex_font);
GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
exit(0);
}