Skip to content

Commit

Permalink
use C++ for sample shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Daniel authored and dogo committed Nov 26, 2024
1 parent 953e134 commit 6190bd3
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 98 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ samples/**/*.SFO

# Ignore documentation directory
OSLib_Documentation/
src/libpspmath/*.a
98 changes: 0 additions & 98 deletions samples/shapes/main.c

This file was deleted.

21 changes: 21 additions & 0 deletions samples/shapes/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "shapes.hpp"

int main(int argc, char** argv)
{
sys::init();

while(!sys::quit)
{
if(!sys::skip)
{
sys::keys();
sys::vid::draw();
sys::swap();
}
}

sys::halt();

exit(EXIT_SUCCESS);
}

104 changes: 104 additions & 0 deletions samples/shapes/shapes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#pragma once
#include <pspkernel.h>
#include <oslib/oslib.h>

PSP_MODULE_INFO("OSLib Shape Example", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
PSP_HEAP_SIZE_KB(12*1024);

namespace sys
{
int32_t w = 320;
int32_t h = 240;
float ratio = (float)w/(float)h;
float z = 1.0f;
float x = 0.0f;
bool skip = false;
bool quit = false;
int mode = 0;
inline bool init()
{
oslInit(0);
oslInitGfx(OSL_PF_8888, 1);
oslInitAudio();
oslSetQuitOnLoadFailure(1);
oslSetKeyAutorepeatInit(40);
oslSetKeyAutorepeatInterval(10);
return true;
}
inline void keys()
{
oslReadKeys();
if (osl_keys->pressed.cross)
mode = 1;
else if (osl_keys->pressed.triangle)
mode = 2;
else if (osl_keys->pressed.square)
mode = 3;
else if (osl_keys->pressed.circle)
mode = 4;
else if (osl_keys->pressed.start)
oslQuit();
quit = osl_quit;
}
inline bool swap()
{
oslEndFrame();
return oslSyncFrame() != 0;
}
inline bool halt()
{
oslEndGfx();
sceKernelExitGame();
return true;
}
inline bool draw()
{
oslStartDrawing();
oslDrawFillRect(0, 0, 480, 272, RGBA(0, 0, 0, 255)); // Clear screen with black
oslDrawString(50, 10, "Press X, Triangle, Square, or Circle to draw:");
oslDrawString(50, 30, "Press Start to quit");

// Check which button is pressed and set the corresponding drawing mode
switch (mode)
{
case 1:
{
oslDrawString(50, 250, "Drawing a line (X Button pressed)");
OSL_COLOR lineColor = RGBA(255, 0, 0, 255);
oslDrawLine(100, 100, 300, 200, lineColor);
}
break;
case 2:
{
oslDrawString(50, 250, "Drawing a rectangle (Triangle Button pressed)");
OSL_COLOR rectColor = RGBA(0, 255, 0, 255); // Green
oslDrawRect(50, 100, 250, 200, rectColor);
}
break;
case 3:
{
oslDrawString(50, 250, "Drawing a filled rectangle (Square Button pressed)");
OSL_COLOR fillColor = RGBA(0, 0, 255, 255); // Blue
oslDrawFillRect(50, 100, 250, 200, fillColor);
}
break;
case 4:
{
oslDrawString(50, 250, "Drawing a gradient rectangle (Circle Button pressed)");
OSL_COLOR topLeft = RGBA(255, 0, 0, 255); // Red (top-left corner)
OSL_COLOR topRight = RGBA(0, 255, 0, 255); // Green (top-right corner)
OSL_COLOR bottomLeft = RGBA(0, 0, 255, 255); // Blue (bottom-left corner)
OSL_COLOR bottomRight = RGBA(255, 255, 0, 255);// Yellow (bottom-right corner)
oslDrawGradientRect(50, 100, 250, 200, topLeft, topRight, bottomLeft, bottomRight);
}
break;
default:
break;
}

oslEndDrawing();
return true;
}
};

0 comments on commit 6190bd3

Please sign in to comment.