summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2024-05-10 18:10:54 -0400
committerrealtradam <[email protected]>2024-05-10 18:10:54 -0400
commit3249a9d1f225c941ec336872b5275af664d1851d (patch)
tree2989a31f6724ce677aa7228de1312e7cfb30aa99
downloadtojam2024-3249a9d1f225c941ec336872b5275af664d1851d.tar.gz
tojam2024-3249a9d1f225c941ec336872b5275af664d1851d.zip
init
-rw-r--r--.gitignore1
-rw-r--r--Makefile39
-rw-r--r--assets/cubicmap_atlas32x32.pngbin0 -> 1847 bytes
-rw-r--r--assets/plane.m3dbin0 -> 9662 bytes
-rw-r--r--assets/seagull.m3dbin0 -> 10263 bytes
-rw-r--r--main.c288
6 files changed, 328 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9bf3746
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+compile_commands.json
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..5b66644
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,39 @@
+BUILD_DIR=build
+include $(N64_INST)/include/n64.mk
+
+src = main.c
+assets_png = $(wildcard assets/*.png)
+#assets_m3d = $(wildcard assets/*.m3d)
+
+assets_conv = $(addprefix filesystem/,$(notdir $(assets_png:%.png=%.sprite)))
+#assets_conv = $(addprefix filesystem/,$(notdir $(assets_m3d:%.m3d=%.m3d)))
+
+MKSPRITE_FLAGS ?=
+
+LDFLAGS += -lraylib
+all: raylib.z64
+
+filesystem/%.sprite: assets/%.png
+ @mkdir -p $(dir $@)
+ @echo " [SPRITE] $@"
+ echo @$(N64_MKSPRITE) -v -f RGBA16 --compress -o "$(dir $@)" "$<"
+ @cp "$<" "$(dir $@)"
+
+#filesystem/%.m3d: assets/%.m3d
+# @mkdir -p $(dir $@)
+# @echo " [MODEL] $@"
+# echo @$(N64_MKMODEL) -v -o "$(dir $@)" "$<"
+# @cp "$<" "$(dir $@)"
+
+$(BUILD_DIR)/raylib.dfs: $(assets_conv)
+$(BUILD_DIR)/raylib.elf: $(src:%.c=$(BUILD_DIR)/%.o)
+
+raylib.z64: N64_ROM_TITLE="raylib"
+raylib.z64: $(BUILD_DIR)/raylib.dfs
+
+clean:
+ rm -rf $(BUILD_DIR) filesystem/ raylib.z64
+
+-include $(wildcard $(BUILD_DIR)/*.d)
+
+.PHONY: all clean
diff --git a/assets/cubicmap_atlas32x32.png b/assets/cubicmap_atlas32x32.png
new file mode 100644
index 0000000..105bd6e
--- /dev/null
+++ b/assets/cubicmap_atlas32x32.png
Binary files differ
diff --git a/assets/plane.m3d b/assets/plane.m3d
new file mode 100644
index 0000000..008e906
--- /dev/null
+++ b/assets/plane.m3d
Binary files differ
diff --git a/assets/seagull.m3d b/assets/seagull.m3d
new file mode 100644
index 0000000..8236820
--- /dev/null
+++ b/assets/seagull.m3d
Binary files differ
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..fb0b0b5
--- /dev/null
+++ b/main.c
@@ -0,0 +1,288 @@
+/*******************************************************************************************
+*
+* raylib [models] example - Draw textured cube
+*
+* Example originally created with raylib 4.5, last time updated with raylib 4.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) 2022-2024 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+
+#include <libdragon.h>
+
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include <raylib.h>
+#include <rlgl.h>
+//#include "raylib_font_RGBA16_5551.h"
+#define ATTR_NINTENDO64_WIDTH 320
+#define ATTR_NINTENDO64_HEIGHT 240
+bool flag=true;
+bool xflag=false;
+
+
+
+
+
+void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); // Draw cube textured
+void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, float width, float height, float length, Color color); // Draw cube with a region of a texture
+
+void updateController()
+{
+
+}
+
+bool initApp()
+{
+ return true;
+}
+void finishApp()
+{
+
+
+}
+extern Texture2D getFontGLTextureId(char *text);
+Rectangle src={0.0f,0.0f,5.0f,10.0f};
+Rectangle dst={0.0f,0.0f,32.0f,32.0f};
+
+//------------------------------------------------------------------------------------
+// Program main entry point
+//------------------------------------------------------------------------------------
+int main(void)
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = ATTR_NINTENDO64_WIDTH;
+ const int screenHeight = ATTR_NINTENDO64_HEIGHT;
+
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes");
+
+
+ // Define the camera to look into our 3d world
+ Camera camera = { 0 };
+ camera.position = (Vector3){ 0.0f, 10.0f, 10.0f };
+ camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
+ camera.fovy = 45.0f;
+ camera.projection = CAMERA_PERSPECTIVE;
+
+
+
+ Texture2D texture = LoadTexture("rom:/cubicmap_atlas32x32.png"); // Load map texture
+ //Model model = LoadModel("rom:/plane.m3d");
+
+ Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
+
+ //BoundingBox bounds = GetMeshBoundingBox(model.meshes[0]); // Set model bounds
+
+
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //----------------------------------------------------------
+
+ // Main game loop
+ while (flag) // Detect window close with Start button
+ {
+ // Update
+ //-----------------------------------------------------
+ updateController();
+
+ // Update
+ //----------------------------------------------------------------------------------
+ //UpdateCamera(&camera, CAMERA_ORBITAL);
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(BLACK);
+
+ BeginMode3D(camera);
+
+ DrawModel(model, position, 2.0f, WHITE);
+
+ // Draw cube with an applied texture
+ //DrawCubeTexture(texture, (Vector3){ -0.0f, 0.0f, 0.0f }, 2.0f, 4.0f, 2.0f, WHITE);
+
+ // Draw cube with an applied texture, but only a defined rectangle piece of the texture
+ //DrawCubeTextureRec(texture, (Rectangle){ 0, texture.height/2, texture.width/2, texture.height/2 },
+ // (Vector3){ 2.0f, 1.0f, 0.0f }, 2.0f, 2.0f, 2.0f, WHITE);
+
+ DrawGrid(10, 1.0f); // Draw a grid
+
+
+ EndMode3D();
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+
+
+
+ //-----------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(texture); // Unload map texture
+
+ CloseWindow(); // Close window and OpenGL context
+ //----------------------------------------------------------
+
+ finishApp();
+ return 0;
+}
+void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color)
+{
+ float x = position.x;
+ float y = position.y;
+ float z = position.z;
+
+ // Set desired texture to be enabled while drawing following vertex data
+ rlSetTexture(texture.id);
+
+ // Vertex data transformation can be defined with the commented lines,
+ // but in this example we calculate the transformed vertex data directly when calling rlVertex3f()
+ //rlPushMatrix();
+ // NOTE: Transformation is applied in inverse order (scale -> rotate -> translate)
+ //rlTranslatef(2.0f, 0.0f, 0.0f);
+ //rlRotatef(45, 0, 1, 0);
+ //rlScalef(2.0f, 2.0f, 2.0f);
+
+ rlBegin(RL_QUADS);
+ rlColor4ub(color.r, color.g, color.b, color.a);
+ // Front Face
+ rlNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer
+ rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad
+ rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad
+ rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Right Of The Texture and Quad
+ rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left Of The Texture and Quad
+ // Back Face
+ rlNormal3f(0.0f, 0.0f, - 1.0f); // Normal Pointing Away From Viewer
+ rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Right Of The Texture and Quad
+ rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad
+ rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad
+ rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Left Of The Texture and Quad
+ // Top Face
+ rlNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up
+ rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad
+ rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Bottom Left Of The Texture and Quad
+ rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right Of The Texture and Quad
+ rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad
+ // Bottom Face
+ rlNormal3f(0.0f, - 1.0f, 0.0f); // Normal Pointing Down
+ rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Right Of The Texture and Quad
+ rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Top Left Of The Texture and Quad
+ rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad
+ rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad
+ // Right face
+ rlNormal3f(1.0f, 0.0f, 0.0f); // Normal Pointing Right
+ rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right Of The Texture and Quad
+ rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad
+ rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left Of The Texture and Quad
+ rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad
+ // Left Face
+ rlNormal3f( - 1.0f, 0.0f, 0.0f); // Normal Pointing Left
+ rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Left Of The Texture and Quad
+ rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad
+ rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Right Of The Texture and Quad
+ rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad
+ rlEnd();
+ //rlPopMatrix();
+
+ rlSetTexture(0);
+}
+
+// Draw cube with texture piece applied to all faces
+void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, float width, float height, float length, Color color)
+{
+ float x = position.x;
+ float y = position.y;
+ float z = position.z;
+ float texWidth = (float)texture.width;
+ float texHeight = (float)texture.height;
+
+ // Set desired texture to be enabled while drawing following vertex data
+ rlSetTexture(texture.id);
+
+ // We calculate the normalized texture coordinates for the desired texture-source-rectangle
+ // It means converting from (tex.width, tex.height) coordinates to [0.0f, 1.0f] equivalent
+ rlBegin(RL_QUADS);
+ rlColor4ub(color.r, color.g, color.b, color.a);
+
+ // Front face
+ rlNormal3f(0.0f, 0.0f, 1.0f);
+ rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
+ rlVertex3f(x - width/2, y - height/2, z + length/2);
+ rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
+ rlVertex3f(x + width/2, y - height/2, z + length/2);
+ rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
+ rlVertex3f(x + width/2, y + height/2, z + length/2);
+ rlTexCoord2f(source.x/texWidth, source.y/texHeight);
+ rlVertex3f(x - width/2, y + height/2, z + length/2);
+
+ // Back face
+ rlNormal3f(0.0f, 0.0f, - 1.0f);
+ rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
+ rlVertex3f(x - width/2, y - height/2, z - length/2);
+ rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
+ rlVertex3f(x - width/2, y + height/2, z - length/2);
+ rlTexCoord2f(source.x/texWidth, source.y/texHeight);
+ rlVertex3f(x + width/2, y + height/2, z - length/2);
+ rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
+ rlVertex3f(x + width/2, y - height/2, z - length/2);
+
+ // Top face
+ rlNormal3f(0.0f, 1.0f, 0.0f);
+ rlTexCoord2f(source.x/texWidth, source.y/texHeight);
+ rlVertex3f(x - width/2, y + height/2, z - length/2);
+ rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
+ rlVertex3f(x - width/2, y + height/2, z + length/2);
+ rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
+ rlVertex3f(x + width/2, y + height/2, z + length/2);
+ rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
+ rlVertex3f(x + width/2, y + height/2, z - length/2);
+
+ // Bottom face
+ rlNormal3f(0.0f, - 1.0f, 0.0f);
+ rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
+ rlVertex3f(x - width/2, y - height/2, z - length/2);
+ rlTexCoord2f(source.x/texWidth, source.y/texHeight);
+ rlVertex3f(x + width/2, y - height/2, z - length/2);
+ rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
+ rlVertex3f(x + width/2, y - height/2, z + length/2);
+ rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
+ rlVertex3f(x - width/2, y - height/2, z + length/2);
+
+ // Right face
+ rlNormal3f(1.0f, 0.0f, 0.0f);
+ rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
+ rlVertex3f(x + width/2, y - height/2, z - length/2);
+ rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
+ rlVertex3f(x + width/2, y + height/2, z - length/2);
+ rlTexCoord2f(source.x/texWidth, source.y/texHeight);
+ rlVertex3f(x + width/2, y + height/2, z + length/2);
+ rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
+ rlVertex3f(x + width/2, y - height/2, z + length/2);
+
+ // Left face
+ rlNormal3f( - 1.0f, 0.0f, 0.0f);
+ rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
+ rlVertex3f(x - width/2, y - height/2, z - length/2);
+ rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
+ rlVertex3f(x - width/2, y - height/2, z + length/2);
+ rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
+ rlVertex3f(x - width/2, y + height/2, z + length/2);
+ rlTexCoord2f(source.x/texWidth, source.y/texHeight);
+ rlVertex3f(x - width/2, y + height/2, z - length/2);
+
+ rlEnd();
+
+ rlSetTexture(0);
+}