commit c29245c47049c0fcdd78c59f0b4fe0cbc3033c45 Author: Nikola Petrov Date: Wed Feb 21 01:02:31 2024 +0100 Initial commit diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..6793f7b --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,21 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/inc", + "${workspaceFolder}/raylib/src" + ], + "defines": [ + "GRAPHICS_API_OPENGL_33", + "PLATFORM_DESKTOP", + "_GNU_SOURCE" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c23", + "cppStandard": "gnu++23", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..665e2de --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,33 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Debug", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/main", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "build" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7616c8a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,49 @@ +{ + "files.associations": { + "iostream": "cpp", + "cmath": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..d646e39 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,21 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "make", + "args": [ + "main" + ] + }, + { + "label": "clean", + "type": "shell", + "command": "make", + "args": [ + "clean" + ] + } + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8f1a28f --- /dev/null +++ b/Makefile @@ -0,0 +1,63 @@ +RAYFLAGS= -D_GNU_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33 +RAYINCLUDE= -Iraylib/src -Iraylib/src/external/glfw/include -Iraylib/src/external/glfw/deps/mingw +RAYOBJECTS= obj/rcore.o obj/rshapes.o obj/rtextures.o obj/rtext.o obj/utils.o obj/rglfw.o obj/rmodels.o obj/raudio.o + +#RAYOPT= -O3 +RAYOPT= -ggdb + +CPPFLAGS= -std=c++23 + +all: setup main run + +setup: + if [ ! -d "raylib" ]; then \ + git clone --depth 1 --branch "5.0" git@github.com:raysan5/raylib.git; \ + fi + +$(shell mkdir -p obj) + +obj/rcore.o: raylib/src/rcore.c + gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE) + +obj/rshapes.o: raylib/src/rshapes.c + gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE) + +obj/rtextures.o: raylib/src/rtextures.c + gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE) + +obj/rtext.o: raylib/src/rtext.c + gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE) + +obj/utils.o: raylib/src/utils.c + gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE) + +obj/rglfw.o: raylib/src/rglfw.c + gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE) + +obj/rmodels.o: raylib/src/rmodels.c + gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE) + +obj/raudio.o: raylib/src/raudio.c + gcc -c $< -o $@ $(RAYOPT) $(RAYFLAGS) $(RAYINCLUDE) + +SRCDIR = src +OBJDIR = obj +INCLUDE = -Iinc + +SOURCES = $(wildcard $(SRCDIR)/*.cpp) + +OBJECTS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SOURCES)) + +$(OBJDIR)/%.o: $(SRCDIR)/%.cpp + $(CC) -c $< -o $@ $(RAYOPT) $(RAYINCLUDE) $(INCLUDE) $(CFLAGS) + +main: main.cpp setup $(RAYOBJECTS) $(OBJECTS) + g++ main.cpp $(RAYOBJECTS) $(OBJECTS) -o main $(RAYOPT) $(RAYINCLUDE) $(INCLUDE) $(CFLAGS) + +run: main + ./main + +clean: + rm -rf obj + rm -rf raylib + rm main \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..464c55c --- /dev/null +++ b/main.cpp @@ -0,0 +1,61 @@ +#include +#include "raylib.h" +#include "raymath.h" + +#define MAX_DEPTH 10 + +Vector2 draw_line(Vector2 start, float angleDeg, float lenghth) +{ + angleDeg += 180.0f; + float angle = (angleDeg * PI) / 180.0f; + float nx = lenghth * std::sin(angle); + float ny = lenghth * std::cos(angle); + Vector2 end = {start.x + nx, start.y + ny}; + DrawLineEx(start, end, 2.0f, PURPLE); + return end; +} + +void draw_branch(Vector2 start, float angle, float len, int dep) +{ + Vector2 next = draw_line(start, angle, len); + + if (len < MAX_DEPTH) + return; + + float next_len = 0.7f; + draw_branch(next, angle + 45, len * next_len, dep + 1); + draw_branch(next, angle - 45, len * next_len, dep + 1); +} + +int main(void) +{ + const int screenWidth = 800; + const int screenHeight = 800; + + InitWindow(screenWidth, screenHeight, "raylib"); + + Camera2D camera = {0}; + camera.target = (Vector2){0.0f, 0.0f}; + camera.offset = (Vector2){screenWidth / 2, screenHeight}; + camera.rotation = 0.0f; + camera.zoom = 1.0f; + + SetTargetFPS(60); + Vector2 start = {0}; + while (!WindowShouldClose()) + { + + BeginDrawing(); + ClearBackground(RAYWHITE); + BeginMode2D(camera); + + DrawCircle(0, 0, 10.0f, RED); + draw_branch(start, 0, screenHeight / 4, 0); + + EndMode2D(); + EndDrawing(); + } + + CloseWindow(); + return 0; +} \ No newline at end of file