diff --git a/grogs/README.md b/grogs/README.md new file mode 100644 index 0000000..d9c8e4a --- /dev/null +++ b/grogs/README.md @@ -0,0 +1,59 @@ +# grogs (Ground graphics) library + +This library uses SDL3 to add graphics support to Ground. + +## Compiling + +First, ensure SDL3 is installed on your system. Then: + +```bash +g++ -shared -fPIC -lSDL3 -o grogs.so grogs.cpp +``` + +## Functions + +### fun -int !initSDL -string &windowTitle -int &width -int &height + +This function initialises SDL for use in Grogs. **This must be run before trying to run any other Grogs functions!** + +First argument is the window title, second and third are width and height of the window, respectively. + +If everything goes fine, returns 0. + +If SDL couldn't create the window, returns 1. If already initialized, returns 2. + +Example: + +``` +pusharg "My Awesome Window" 640 480 +!grogs:initSDL &result +``` + +### fun -int !pollEvent + +Returns a code for an event that has been polled. For now, only window closing is supported, which will return 0. Anything else for now will return -1. + +### fun -int !clearRenderer + +Clears the renderer of any pixels to be rendered. Returns 0, unless SDL is not initialized. + +### fun -int !renderFrame + +Renders frame on the screen. Whichever pixels have been set will be displayed. Returns 0, unless SDL is not initialized. + +### fun -int !setPixel -int &xpos -int &ypos -int &red -int &green -int &blue + +Sets a pixel at the desired location to the desired colour. Returns 0, unless SDL is not initialized. + +First argument: xpos +Second argument: ypos +Third argument: red value (0 to 255) +Fourth argument: green value (0 to 255) +Fifth argument: blue value (0 to 255) + +This example sets the pixel at (10, 10) to white (RGB(255, 255, 255)): + +``` +pusharg 10 10 255 255 255 +call !grogs:setPixel &result +``` diff --git a/grogs/grogs.cpp b/grogs/grogs.cpp index 2dd9dec..3d59f69 100644 --- a/grogs/grogs.cpp +++ b/grogs/grogs.cpp @@ -57,7 +57,7 @@ GroundValue renderFrame(GroundValue* args, int arg_count) { return GROUND_INT_VAL(-1); } SDL_RenderPresent(renderer); - return GROUND_BOOL_VAL(true); + return GROUND_INT_VAL(0); } GroundValue setPixel(GroundValue* args, int arg_count) {