Added samples

This commit is contained in:
GeeckoDev 2010-11-21 01:29:00 +01:00
parent ebab6449f5
commit ea23da1dda
19 changed files with 530 additions and 0 deletions

BIN
sample/clock/EBOOT.PBP Normal file

Binary file not shown.

21
sample/clock/Makefile Normal file
View File

@ -0,0 +1,21 @@
MEDIA = /media/PANDORA/psp/game/CAT_Homebrews\ perso/
TARGET = gLib2D-clock
OBJS = main.o ../../glib2d.o
LIBS = -ljpeg -lpng -lz -lpspgum -lpspgu -lpsprtc -lm
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = gLib2D sample - clock
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
install:
cp ./EBOOT.PBP $(MEDIA)$(TARGET)
dir:
mkdir $(MEDIA)$(TARGET)
lclean:
rm *.o

71
sample/clock/main.c Normal file
View File

@ -0,0 +1,71 @@
// A simple clock.
// Rotated rectangles can easily replace lines (but crappy rendering).
#include <pspkernel.h>
#include <psprtc.h>
#include "../../glib2d.h"
PSP_MODULE_INFO("App",0,1,1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
/* Callbacks */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0; }
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0; }
int SetupCallbacks() {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) sceKernelStartThread(thid, 0, 0);
return thid; }
int main()
{
SetupCallbacks();
pspTime time;
while (1)
{
sceRtcGetCurrentClockLocalTime(&time);
gClear(WHITE);
gBegin(NULL);
gSetCoordMode(G_DOWN_LEFT);
gSetCoordXY(G_SCR_W/2,G_SCR_H/2);
// Hours
gSetScaleWH(1,30);
gSetColor(BLACK);
gSetRotation(((time.hour%12)+
time.minutes/60.f+
time.seconds/3600.f)*360/12);
gAdd();
// Minutes
gSetScaleWH(1,70);
gSetColor(BLACK);
gSetRotation((time.minutes+
time.seconds/60.f)*360.f/60.f);
gAdd();
// Seconds
gSetScaleWH(1,70);
gSetColor(RED);
gSetRotation(time.seconds*360.f/60.f);
gAdd();
gEnd();
gFlip(G_TRUE); // Vsync enabled
}
sceKernelExitGame();
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,21 @@
MEDIA = /media/PANDORA/psp/game/CAT_Homebrews\ perso/
TARGET = gLib2D-coordinates
OBJS = main.o ../../glib2d.o
LIBS = -ljpeg -lpng -lz -lpspgum -lpspgu -lpsprtc -lm
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = gLib2D sample - coordinates
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
install:
cp ./EBOOT.PBP $(MEDIA)$(TARGET)
dir:
mkdir $(MEDIA)$(TARGET)
lclean:
rm *.o

73
sample/coordinates/main.c Normal file
View File

@ -0,0 +1,73 @@
// gSetCoordMode use.
// The rotation center are coordinates passed to gSetCoord*.
#include <pspkernel.h>
#include "../../glib2d.h"
PSP_MODULE_INFO("App",0,1,1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
/* Callbacks */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0; }
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0; }
int SetupCallbacks() {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) sceKernelStartThread(thid, 0, 0);
return thid; }
int main()
{
SetupCallbacks();
int rot = 0;
while (1)
{
if ((rot++) > 360) rot -= 360;
gClear(WHITE);
gBegin(NULL);
gSetScaleWH(42,42);
gSetColor(RED);
gSetCoordMode(G_UP_LEFT);
gSetCoordXY(0,0);
gSetRotation(rot);
gAdd();
gSetCoordMode(G_UP_RIGHT);
gSetCoordXY(G_SCR_W,0);
gSetRotation(-rot);
gAdd();
gSetCoordMode(G_DOWN_RIGHT);
gSetCoordXY(G_SCR_W,G_SCR_H);
gSetRotation(rot);
gAdd();
gSetCoordMode(G_DOWN_LEFT);
gSetCoordXY(0,G_SCR_H);
gSetRotation(-rot);
gAdd();
gSetCoordMode(G_CENTER);
gSetCoordXY(G_SCR_W/2,G_SCR_H/2);
gSetRotation(rot);
gAdd();
gEnd();
gFlip(G_TRUE); // Vsync enabled
}
sceKernelExitGame();
return 0;
}

BIN
sample/depth/EBOOT.PBP Normal file

Binary file not shown.

21
sample/depth/Makefile Normal file
View File

@ -0,0 +1,21 @@
MEDIA = /media/PANDORA/psp/game/CAT_Homebrews\ perso/
TARGET = gLib2D-depth
OBJS = main.o ../../glib2d.o
LIBS = -ljpeg -lpng -lz -lpspgum -lpspgu -lpsprtc -lm
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = gLib2D sample - depth
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
install:
cp ./EBOOT.PBP $(MEDIA)$(TARGET)
dir:
mkdir $(MEDIA)$(TARGET)
lclean:
rm *.o

62
sample/depth/main.c Normal file
View File

@ -0,0 +1,62 @@
// Zbuffer use.
// Z range : nearest 0 - 65535 farest
// Objects are automatically sorted to have a proper rendering with blending.
#include <pspkernel.h>
#include "../../glib2d.h"
PSP_MODULE_INFO("App",0,1,1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
/* Callbacks */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0; }
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0; }
int SetupCallbacks() {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) sceKernelStartThread(thid, 0, 0);
return thid; }
int main()
{
SetupCallbacks();
while (1)
{
gClear(BLACK); // Clears zbuffer since Z coordinate is used in the loop
gBegin(NULL);
gSetColor(AZURE);
gSetAlpha(255);
gSetScaleWH(50,50);
gSetCoordXYZ(195,50,0);
gAdd();
gSetColor(CHARTREUSE);
gSetAlpha(200);
gSetScaleWH(200,100);
gSetCoordXYZ(20,20,0);
gAdd();
gSetColor(0xFFDDEEFF);
gSetAlpha(127);
gSetScaleWH(100,67);
gSetCoordXYZ(170,60,1);
gAdd();
gEnd();
gFlip(G_TRUE); // Vsync enabled
}
sceKernelExitGame();
return 0;
}

BIN
sample/objcontrol/EBOOT.PBP Normal file

Binary file not shown.

View File

@ -0,0 +1,21 @@
MEDIA = /media/PANDORA/psp/game/CAT_Homebrews\ perso/
TARGET = gLib2D-objcontrol
OBJS = main.o ../../glib2d.o
LIBS = -ljpeg -lpng -lz -lpspgum -lpspgu -lpsprtc -lm
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = gLib2D sample - objcontrol
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
install:
cp ./EBOOT.PBP $(MEDIA)$(TARGET)
dir:
mkdir $(MEDIA)$(TARGET)
lclean:
rm *.o

69
sample/objcontrol/main.c Normal file
View File

@ -0,0 +1,69 @@
// Control object properties.
#include <pspkernel.h>
#include <pspctrl.h>
#include "../../glib2d.h"
PSP_MODULE_INFO("App",0,1,1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
/* Callbacks */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0; }
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0; }
int SetupCallbacks() {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) sceKernelStartThread(thid, 0, 0);
return thid; }
int main()
{
SetupCallbacks();
SceCtrlData pad;
gImage* tex = gTexLoad("tex.png",G_TRUE);
int alpha = 255, x = G_SCR_W/2, y = G_SCR_H/2, w = 125, h = 125, rot = 0;
while (1)
{
// Controls
sceCtrlPeekBufferPositive(&pad,1);
if (pad.Buttons & PSP_CTRL_SELECT) alpha-=2;
if (pad.Buttons & PSP_CTRL_START) alpha+=2;
if (pad.Buttons & PSP_CTRL_LEFT) x-=2;
if (pad.Buttons & PSP_CTRL_RIGHT) x+=2;
if (pad.Buttons & PSP_CTRL_UP) y-=2;
if (pad.Buttons & PSP_CTRL_DOWN) y+=2;
if (pad.Buttons & PSP_CTRL_SQUARE) w--;
if (pad.Buttons & PSP_CTRL_CIRCLE) w++;
if (pad.Buttons & PSP_CTRL_TRIANGLE) h--;
if (pad.Buttons & PSP_CTRL_CROSS) h++;
if (pad.Buttons & PSP_CTRL_LTRIGGER) rot-=2;
if (pad.Buttons & PSP_CTRL_RTRIGGER) rot+=2;
// Display
gClear(WHITE);
gBegin(tex);
if (tex == NULL) gSetColor(RED);
gSetCoordMode(G_CENTER);
gSetAlpha(alpha);
gSetScaleWH(w,h);
gSetCoordXY(x,y);
gSetRotation(rot);
gAdd();
gEnd();
gFlip(G_TRUE); // Vsync enabled
}
sceKernelExitGame();
return 0;
}

BIN
sample/objcontrol/tex.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

View File

@ -0,0 +1,21 @@
MEDIA = /media/PANDORA/psp/game/CAT_Homebrews\ perso/
TARGET = gLib2D-screensaver
OBJS = main.o ../../glib2d.o
LIBS = -ljpeg -lpng -lz -lpspgum -lpspgu -lpsprtc -lm
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = gLib2D sample - screensaver
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
install:
cp ./EBOOT.PBP $(MEDIA)$(TARGET)
dir:
mkdir $(MEDIA)$(TARGET)
lclean:
rm *.o

53
sample/screensaver/main.c Normal file
View File

@ -0,0 +1,53 @@
// The famous DVD screensaver.
#include <pspkernel.h>
#include "../../glib2d.h"
PSP_MODULE_INFO("App",0,1,1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
/* Callbacks */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0; }
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0; }
int SetupCallbacks() {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) sceKernelStartThread(thid, 0, 0);
return thid; }
int main()
{
SetupCallbacks();
int size = 42, x=0, y=0, dx=2, dy=2;
while (1)
{
x += dx;
y += dy;
if (x < 0 || x+size > G_SCR_W) dx = -dx;
if (y < 0 || y+size > G_SCR_H) dy = -dy;
gClear(WHITE);
gBegin(NULL); // No texture
gSetColor(AZURE);
gSetScaleWH(size,size);
gSetCoordXY(x,y);
gSetAlpha(x*255/G_SCR_W); // Useless alpha effect ;)
gAdd();
gEnd();
gFlip(G_TRUE); // Vsync enabled
}
sceKernelExitGame();
return 0;
}

BIN
sample/transform/EBOOT.PBP Normal file

Binary file not shown.

21
sample/transform/Makefile Normal file
View File

@ -0,0 +1,21 @@
MEDIA = /media/PANDORA/psp/game/CAT_Homebrews\ perso/
TARGET = gLib2D-transform
OBJS = main.o ../../glib2d.o
LIBS = -ljpeg -lpng -lz -lpspgum -lpspgu -lpsprtc -lm
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = gLib2D sample - transform
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
install:
cp ./EBOOT.PBP $(MEDIA)$(TARGET)
dir:
mkdir $(MEDIA)$(TARGET)
lclean:
rm *.o

76
sample/transform/main.c Normal file
View File

@ -0,0 +1,76 @@
// OpenGL-like transformations.
// gPush saves the current transformation (position/rotation/scale) to the stack
// gPop reads the current transformation from the stack
#include <pspkernel.h>
#include "../../glib2d.h"
PSP_MODULE_INFO("App",0,1,1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
/* Callbacks */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0; }
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0; }
int SetupCallbacks() {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) sceKernelStartThread(thid, 0, 0);
return thid; }
int main()
{
SetupCallbacks();
int rot = 0, i, branches = 4;
while (1)
{
if ((rot++) > 360) rot -= 360;
gClear(WHITE);
gBegin(NULL);
gSetScaleWH(15,15);
gSetCoordMode(G_CENTER);
gSetCoordXY(G_SCR_W/2,G_SCR_H/2);
gSetRotation(rot);
gSetColor(AZURE);
gAdd();
gSetRotation(-rot);
for (i=0; i!=branches; i++)
{
gPush();
gSetAlpha(200);
gSetCoordXYRelative(30,0,G_TRUE);
gAdd();
gPush();
gSetAlpha(127);
gSetCoordXYRelative(30,-10,G_TRUE);
gAdd();
gPop();
gSetScaleWH(5,5);
gSetCoordXYRelative(30,10,G_TRUE);
gAdd();
gPop();
gSetRotationRelative(360/branches);
}
gEnd();
gFlip(G_TRUE); // Vsync enabled
}
sceKernelExitGame();
return 0;
}