Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add raylib examples #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions examples/dreamcast/raylib/cubicmap/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Cubic map Raylib program
# Copyright (C) 2024
#

TARGET = cubicmap.elf
OBJS = cubicmap.o romdisk.o
KOS_ROMDISK_DIR = romdisk

KOS_CFLAGS += -I${KOS_PORTS}/include/raylib

all: rm-elf $(TARGET)

include $(KOS_BASE)/Makefile.rules

clean: rm-elf
-rm -f $(OBJS)

rm-elf:
-rm -f $(TARGET) romdisk.*

$(TARGET): $(OBJS)
kos-cc -o $(TARGET) $(OBJS) -lraylib -lGL -lkosutils

run: $(TARGET)
$(KOS_LOADER) $(TARGET)

dist: $(TARGET)
-rm -f $(OBJS) romdisk.img
$(KOS_STRIP) $(TARGET)

118 changes: 118 additions & 0 deletions examples/dreamcast/raylib/cubicmap/cubicmap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* KallistiOS ##version##
examples/dreamcast/raylib/cubicmap/cubicmap.c
Copyright (C) 2024
*/

/*******************************************************************************************
*
* raylib [models] example - Cubicmap loading and drawing
*
* Example originally created with raylib 1.8, last time updated with raylib 3.5
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2015-2024 Ramon Santamaria (@raysan5)
*
********************************************************************************************/

#include <raylib.h>

#define ATTR_ORBIS_WIDTH 640
#define ATTR_ORBIS_HEIGHT 480

static bool done = false;

static void updateController(void) {
bool startPressed;

if(!IsGamepadAvailable(0))
return;

startPressed = IsGamepadButtonPressed(0, GAMEPAD_BUTTON_MIDDLE_RIGHT);

if(startPressed)
done = true;
}

int main(int argc, char** argv) {

// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = ATTR_ORBIS_WIDTH;
const int screenHeight = ATTR_ORBIS_HEIGHT;

InitWindow(screenWidth, screenHeight, "raylib [models] example - cubicmap");

// Define the camera to look into our 3d world
Camera camera = { 0 };
camera.position = (Vector3){ 16.0f, 14.0f, 16.0f }; // Camera position
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 45.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type

Image image = LoadImage("/rd/cubicmap.png"); // Load cubicmap image (RAM)
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)

Mesh mesh = GenMeshCubicmap(image, (Vector3){ 1.0f, 1.0f, 1.0f });
Model model = LoadModelFromMesh(mesh);

// NOTE: By default each cube is mapped to one part of texture atlas
Texture2D texture = LoadTexture("/rd/cubicmap_atlas.png"); // Load map texture
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture

Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position

UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM

SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//----------------------------------------------------------

// Main game loop
while(!done) {

updateController();

UpdateCamera(&camera, CAMERA_ORBITAL);

// Draw
//----------------------------------------------------------------------------------
BeginDrawing();

ClearBackground(RAYWHITE);

BeginMode3D(camera);

DrawModel(model, mapPosition, 1.0f, WHITE);

EndMode3D();

DrawTextureEx(cubicmap, (Vector2){ screenWidth - cubicmap.width*4.0f - 20, 20.0f }, 0.0f, 4.0f, WHITE);
DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);

DrawText("cubicmap image used to", 658, 90, 10, GRAY);
DrawText("generate map 3d model", 658, 104, 10, GRAY);

DrawFPS(10, 10);

EndDrawing();
//-----------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(cubicmap); // Unload cubicmap texture
UnloadTexture(texture); // Unload map texture
UnloadModel(model); // Unload map model

CloseWindow(); // Close window and OpenGL context
//----------------------------------------------------------

return 0;
}





Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions examples/dreamcast/raylib/shapes/basic_shapes/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Basic shapes Raylib program
# Copyright (C) 2024
#

TARGET = basic.elf
OBJS = basic.o

KOS_CFLAGS += -I${KOS_PORTS}/include/raylib

all: rm-elf $(TARGET)

include $(KOS_BASE)/Makefile.rules

clean: rm-elf
-rm -f $(OBJS)

rm-elf:
-rm -f $(TARGET)

$(TARGET): $(OBJS)
kos-cc -o $(TARGET) $(OBJS) -lraylib -lGL -lkosutils

run: $(TARGET)
$(KOS_LOADER) $(TARGET)

dist: $(TARGET)
-rm -f $(OBJS)
$(KOS_STRIP) $(TARGET)

104 changes: 104 additions & 0 deletions examples/dreamcast/raylib/shapes/basic_shapes/basic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* KallistiOS ##version##
examples/dreamcast/raylib/shapes/basic_shapes/basic.c
Copyright (C) 2024
*/

/*******************************************************************************************
*
* raylib [shapes] example - Draw basic shapes 2d (rectangle, circle, line...)
*
* Example originally created with raylib 1.0, last time updated with raylib 4.2
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2014-2024 Ramon Santamaria (@raysan5)
*
********************************************************************************************/

#include <raylib.h>

#define ATTR_DREAMCAST_WIDTH 640
#define ATTR_DREAMCAST_HEIGHT 480

static bool done = false;

static void updateController(void) {
bool startPressed;

if(!IsGamepadAvailable(0))
return;

startPressed = IsGamepadButtonPressed(0, GAMEPAD_BUTTON_MIDDLE_RIGHT);

if(startPressed)
done = true;
}

int main(int argc, char** argv) {

// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = ATTR_DREAMCAST_WIDTH;
const int screenHeight = ATTR_DREAMCAST_HEIGHT;

InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes");

float rotation = 0.0f;

SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//----------------------------------------------------------

// Main game loop
while(!done) { // Detect window close with Start button

updateController();

rotation += 0.2f;

// Draw
//----------------------------------------------------------------------------------
BeginDrawing();

ClearBackground(RAYWHITE);

DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY);

// Circle shapes and lines
DrawCircle(screenWidth/5, 120, 35, DARKBLUE);
DrawCircleGradient(screenWidth/5, 220, 60, GREEN, SKYBLUE);
DrawCircleLines(screenWidth/5, 340, 80, DARKBLUE); //not supported on Dreamcast

// Rectangle shapes and lines
DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED);
DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD);
DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE); // NOTE: Uses QUADS internally, not lines

// Triangle shapes and lines
DrawTriangle((Vector2){ screenWidth/4.0f *3.0f, 80.0f },
(Vector2){ screenWidth/4.0f *3.0f - 60.0f, 150.0f },
(Vector2){ screenWidth/4.0f *3.0f + 60.0f, 150.0f }, VIOLET);

DrawTriangleLines((Vector2){ screenWidth/4.0f*3.0f, 160.0f },
(Vector2){ screenWidth/4.0f*3.0f - 20.0f, 230.0f },
(Vector2){ screenWidth/4.0f*3.0f + 20.0f, 230.0f }, DARKBLUE);//Not supported on Dreamcast

// Polygon shapes and lines
DrawPoly((Vector2){ screenWidth/4.0f*3, 330 }, 6, 80, rotation, BROWN);
DrawPolyLines((Vector2){ screenWidth/4.0f*3, 330 }, 6, 90, rotation, BROWN); //Not supported on Dreamcast
DrawPolyLinesEx((Vector2){ screenWidth/4.0f*3, 330 }, 6, 85, rotation, 6, BEIGE);

// NOTE: We draw all LINES based shapes together to optimize internal drawing,
// this way, all LINES are rendered in a single draw pass
//DrawLine(18, 42, screenWidth - 18, 42, BLACK); //not supported on Dreamcast
EndDrawing();
//-----------------------------------------------------
}

// De-Initialization
//---------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//----------------------------------------------------------

return 0;
}
30 changes: 30 additions & 0 deletions examples/dreamcast/raylib/shapes/collision_area/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Collision area Raylib program
# Copyright (C) 2024
#

TARGET = collision.elf
OBJS = collision.o

KOS_CFLAGS += -I${KOS_PORTS}/include/raylib

all: rm-elf $(TARGET)

include $(KOS_BASE)/Makefile.rules

clean: rm-elf
-rm -f $(OBJS)

rm-elf:
-rm -f $(TARGET)

$(TARGET): $(OBJS)
kos-cc -o $(TARGET) $(OBJS) -lraylib -lGL -lkosutils

run: $(TARGET)
$(KOS_LOADER) $(TARGET)

dist: $(TARGET)
-rm -f $(OBJS)
$(KOS_STRIP) $(TARGET)

Loading