commit 5abdcd400984525b9e752836000f17b619e4b0b3 Author: sam Date: Sun Apr 28 10:19:23 2024 +1200 remove imgui submodule diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e613a59 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "rlImGui"] + path = rlImGui + url = https://github.com/raylib-extras/rlImGui diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1f04a03 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +BINARY=gear + +CC=g++ +CFLAGS=-O3 -Wall -Wextra -Iimgui -IrlImGui +LDFLAGS=-lraylib -lm + +CFILES=$(shell find -L * -type f -name '*.cpp') +OBJ=$(CFILES:.cpp=.o) + +$(BINARY): $(OBJ) Makefile + $(CC) $(OBJ) $(LDFLAGS) -o $@ + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +run: $(BINARY) + ./$(BINARY) + +clean: + rm -rf $(OBJ) $(BINARY) + diff --git a/gear b/gear new file mode 100755 index 0000000..41d2a69 Binary files /dev/null and b/gear differ diff --git a/imgui b/imgui new file mode 160000 index 0000000..913151c --- /dev/null +++ b/imgui @@ -0,0 +1 @@ +Subproject commit 913151caa8905370229e361486b10c890aeaed45 diff --git a/imgui.ini b/imgui.ini new file mode 100644 index 0000000..39adeec --- /dev/null +++ b/imgui.ini @@ -0,0 +1,36 @@ +[Window][DockSpaceViewport_11111111] +Pos=0,19 +Size=1362,710 + +[Window][Debug##Default] +Pos=60,60 +Size=400,400 + +[Window][Game Objects] +Pos=0,19 +Size=231,710 + +[Window][Properties] +Pos=781,20 +Size=281,528 + +[Window][Viewport] +Pos=233,19 +Size=846,710 + +[Window][Dear ImGui Demo] +Pos=233,476 +Size=846,253 + +[Window][Dear ImGui Metrics/Debugger] +Pos=233,476 +Size=846,253 + +[Window][About] +Pos=1081,545 +Size=281,184 + +[Window][Debug] +Pos=781,549 +Size=281,180 + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e08f75d --- /dev/null +++ b/main.cpp @@ -0,0 +1,214 @@ +#include +#include +#include +#include + +#include "viewport.h" + +typedef struct game_object_t { + char name[128]; +} game_object; + +const char* gl_versions[7] = { + "UNKNOWN", + "1.1", + "2.1", + "3.3", + "4.3", + "ES 2.0", + "ES 3.0" +}; + +Camera camera; + +int main() { + SetConfigFlags(FLAG_WINDOW_RESIZABLE); + InitWindow(800, 600, "gear"); + //InitViewport(); + + rlImGuiSetup(true); + /*ImGuiIO *ioptr = igGetIO(); + ioptr->ConfigFlags |= ImGuiConfigFlags_DockingEnable;*/ + + camera = (Camera){}; + camera.position = (Vector3) { 10.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 = 70.0f; + camera.projection = CAMERA_PERSPECTIVE; + + //SetTargetFPS(60); + + ImVec4* colors = ImGui::GetStyle().Colors; + colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); + colors[ImGuiCol_WindowBg] = ImVec4(0.29f, 0.34f, 0.26f, 1.00f); + colors[ImGuiCol_ChildBg] = ImVec4(0.29f, 0.34f, 0.26f, 1.00f); + colors[ImGuiCol_PopupBg] = ImVec4(0.24f, 0.27f, 0.20f, 1.00f); + colors[ImGuiCol_Border] = ImVec4(0.54f, 0.57f, 0.51f, 0.50f); + colors[ImGuiCol_BorderShadow] = ImVec4(0.14f, 0.16f, 0.11f, 0.52f); + colors[ImGuiCol_FrameBg] = ImVec4(0.24f, 0.27f, 0.20f, 1.00f); + colors[ImGuiCol_FrameBgHovered] = ImVec4(0.27f, 0.30f, 0.23f, 1.00f); + colors[ImGuiCol_FrameBgActive] = ImVec4(0.30f, 0.34f, 0.26f, 1.00f); + colors[ImGuiCol_TitleBg] = ImVec4(0.24f, 0.27f, 0.20f, 1.00f); + colors[ImGuiCol_TitleBgActive] = ImVec4(0.29f, 0.34f, 0.26f, 1.00f); + colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f); + colors[ImGuiCol_MenuBarBg] = ImVec4(0.24f, 0.27f, 0.20f, 1.00f); + colors[ImGuiCol_ScrollbarBg] = ImVec4(0.35f, 0.42f, 0.31f, 1.00f); + colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.28f, 0.32f, 0.24f, 1.00f); + colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.25f, 0.30f, 0.22f, 1.00f); + colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.23f, 0.27f, 0.21f, 1.00f); + colors[ImGuiCol_CheckMark] = ImVec4(0.59f, 0.54f, 0.18f, 1.00f); + colors[ImGuiCol_SliderGrab] = ImVec4(0.35f, 0.42f, 0.31f, 1.00f); + colors[ImGuiCol_SliderGrabActive] = ImVec4(0.54f, 0.57f, 0.51f, 0.50f); + colors[ImGuiCol_Button] = ImVec4(0.29f, 0.34f, 0.26f, 0.40f); + colors[ImGuiCol_ButtonHovered] = ImVec4(0.35f, 0.42f, 0.31f, 1.00f); + colors[ImGuiCol_ButtonActive] = ImVec4(0.54f, 0.57f, 0.51f, 0.50f); + colors[ImGuiCol_Header] = ImVec4(0.35f, 0.42f, 0.31f, 1.00f); + colors[ImGuiCol_HeaderHovered] = ImVec4(0.35f, 0.42f, 0.31f, 0.6f); + colors[ImGuiCol_HeaderActive] = ImVec4(0.54f, 0.57f, 0.51f, 0.50f); + colors[ImGuiCol_Separator] = ImVec4(0.14f, 0.16f, 0.11f, 1.00f); + colors[ImGuiCol_SeparatorHovered] = ImVec4(0.54f, 0.57f, 0.51f, 1.00f); + colors[ImGuiCol_SeparatorActive] = ImVec4(0.59f, 0.54f, 0.18f, 1.00f); + colors[ImGuiCol_ResizeGrip] = ImVec4(0.19f, 0.23f, 0.18f, 0.00f); // grip invis + colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.54f, 0.57f, 0.51f, 1.00f); + colors[ImGuiCol_ResizeGripActive] = ImVec4(0.59f, 0.54f, 0.18f, 1.00f); + colors[ImGuiCol_Tab] = ImVec4(0.35f, 0.42f, 0.31f, 1.00f); + colors[ImGuiCol_TabHovered] = ImVec4(0.54f, 0.57f, 0.51f, 0.78f); + colors[ImGuiCol_TabActive] = ImVec4(0.59f, 0.54f, 0.18f, 1.00f); + colors[ImGuiCol_TabUnfocused] = ImVec4(0.24f, 0.27f, 0.20f, 1.00f); + colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.35f, 0.42f, 0.31f, 1.00f); + colors[ImGuiCol_DockingPreview] = ImVec4(0.59f, 0.54f, 0.18f, 1.00f); + colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); + colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); + colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.59f, 0.54f, 0.18f, 1.00f); + colors[ImGuiCol_PlotHistogram] = ImVec4(1.00f, 0.78f, 0.28f, 1.00f); + colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); + colors[ImGuiCol_TextSelectedBg] = ImVec4(0.59f, 0.54f, 0.18f, 1.00f); + colors[ImGuiCol_DragDropTarget] = ImVec4(0.73f, 0.67f, 0.24f, 1.00f); + colors[ImGuiCol_NavHighlight] = ImVec4(0.59f, 0.54f, 0.18f, 1.00f); + colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); + colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); + colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); + + ImGuiStyle& style = ImGui::GetStyle(); + style.FrameBorderSize = 1.0f; + style.WindowRounding = 0.0f; + style.ChildRounding = 0.0f; + style.FrameRounding = 0.0f; + style.PopupRounding = 0.0f; + style.ScrollbarRounding = 0.0f; + style.GrabRounding = 0.0f; + style.TabRounding = 0.0f; + + bool show_demo = false; + bool show_debug = true; + + /*sl_vec(game_object*) game_objects = { 0 }; + for(int i = 0; i < 10000; i++) { + game_object* obj = calloc(sizeof(game_object), 1); + snprintf(obj->name, 128, "bob %d", i); + sl_vec_push(game_objects, obj); + }*/ + + game_object* selected = NULL; + + while(!WindowShouldClose()) { + //UpdateViewport(); + + BeginDrawing(); + { + ClearBackground(BLACK); + + /*BeginViewport(); + { + ClearBackground(BLACK); + BeginMode3D(camera); + { + DrawCube((Vector3){0.0f, 0.0f, 0.0f}, 5.0f, 5.0f, 5.0f, RED); + DrawGrid(10, 10); + } + EndMode3D(); + + DrawFPS(10, 10); + //DrawText(TextFormat( + + int y = 50; + for(sl_vec_it(obj, game_objects)) { + DrawText(obj->name, 10, y, 20, WHITE); + y += 20; + } + } + EndViewport();*/ + + rlImGuiBegin(); + { + if(ImGui::BeginMainMenuBar()) { + if(ImGui::BeginMenu("File", true)) { + if(ImGui::MenuItem("Quit", "ESC", false, true)) { + CloseWindow(); + } + ImGui::EndMenu(); + } + + if(ImGui::BeginMenu("Debug", true)) { + ImGui::Checkbox("Show demo window", &show_demo); + ImGui::EndMenu(); + } + + ImGui::EndMainMenuBar(); + } + + //ImGui::DockSpaceOverViewport(NULL, 0, NULL); + + if(show_demo) + ImGui::ShowDemoWindow(&show_demo); + + //RenderViewport(); + + ImGui::Begin("Game Objects", NULL, 0); + { + /*for(sl_vec_it(obj, game_objects)) { + char* name = (*obj)->name; + if(strcmp(name, "") == 0) name = " "; + if(igSelectable_Bool(name, selected == *obj, 0, (ImVec2){0, 0})) + selected = *obj; + }*/ + } + ImGui::End(); + + ImGui::Begin("Properties", NULL, 0); + { + if(selected != NULL) { + ImGui::InputText("##name", selected->name, 128, 0, NULL, NULL); + } + } + ImGui::End(); + + if(show_debug) { + ImGui::Begin("Debug", &show_debug, 0); + { + ImGui::Text("raylib %s", RAYLIB_VERSION); + ImGui::Text("OpenGL %s", gl_versions[rlGetVersion()]); + ImGui::Text("FPS: %d", GetFPS()); + ImGui::Text("Frame time: %f", GetFrameTime()); + ImGui::Text("Cursor hidden: %d", IsCursorHidden()); + + ImGui::Text("\nResolutions"); + ImGui::Text("Window: %dx%d", GetScreenWidth(), GetScreenHeight()); + for(int i = 0; i < GetMonitorCount(); i++) { + ImGui::Text("%s: %dx%d@%d", GetMonitorName(i), GetMonitorWidth(i), + GetMonitorHeight(i), GetMonitorRefreshRate(i)); + } + } + ImGui::End(); + } + } + rlImGuiEnd(); + } + EndDrawing(); + } + + rlImGuiShutdown(); + CloseWindow(); +} diff --git a/main.o b/main.o new file mode 100644 index 0000000..e24924a Binary files /dev/null and b/main.o differ diff --git a/rlImGui b/rlImGui new file mode 160000 index 0000000..30cd744 --- /dev/null +++ b/rlImGui @@ -0,0 +1 @@ +Subproject commit 30cd744e9d291644fc39d5b0fb79ad6c132f2b40 diff --git a/viewport.c b/viewport.c new file mode 100644 index 0000000..46b8a05 --- /dev/null +++ b/viewport.c @@ -0,0 +1,64 @@ +#include "viewport.h" +#include +#include +#include +#include + +extern Camera camera; +RenderTexture viewport; +RenderTexture new_viewport; +bool swap_viewport = false; + +void InitViewport() { + viewport = LoadRenderTexture(800, 600); +} + +void UpdateViewport() { + if(swap_viewport) { + UnloadRenderTexture(viewport); + viewport = new_viewport; + swap_viewport = false; + } +} + +void BeginViewport() { + BeginTextureMode(viewport); +} + +void EndViewport() { + EndTextureMode(); +} + +void RenderViewport() { + igPushStyleVar_Vec2(ImGuiStyleVar_WindowPadding, (ImVec2){0.0f, 0.0f}); + + igBegin("Viewport", NULL, ImGuiWindowFlags_NoScrollbar); + { + if(igIsWindowHovered(0)) { + if(IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) { + if(!IsCursorHidden()) + DisableCursor(); + UpdateCamera(&camera, CAMERA_FREE); + } else { + if(IsCursorHidden()) + EnableCursor(); + } + } else { + if(IsCursorHidden()) + EnableCursor(); + } + + ImVec2 area; + igGetContentRegionAvail(&area); + + if(viewport.texture.width != area.x || viewport.texture.height != area.y) { + new_viewport = LoadRenderTexture(area.x, area.y); + swap_viewport = true; + } + + rligImageRenderTexture(&viewport); + } + igEnd(); + + igPopStyleVar(1); +} diff --git a/viewport.h b/viewport.h new file mode 100644 index 0000000..8e05713 --- /dev/null +++ b/viewport.h @@ -0,0 +1,10 @@ +#ifndef __VIEWPORT_H__ +#define __VIEWPORT_H__ + +void InitViewport(); +void UpdateViewport(); +void BeginViewport(); +void EndViewport(); +void RenderViewport(); + +#endif