first commit

This commit is contained in:
sam 2024-04-28 12:53:57 +12:00
commit 2432fc4998
9 changed files with 471 additions and 0 deletions

21
Makefile Normal file
View file

@ -0,0 +1,21 @@
BINARY=gear
CC=gcc
CFLAGS=-O3 -Wall -Wextra -Werror
LDFLAGS=-lraylib -lm -lrlcimgui -lcimgui -lstdc++ -lGL
CFILES=$(shell find -L * -type f -name '*.c')
OBJ=$(CFILES:.c=.o)
$(BINARY): $(OBJ) Makefile
$(CC) $(OBJ) $(LDFLAGS) -o $@
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
run: $(BINARY)
./$(BINARY)
clean:
rm -rf $(OBJ) $(BINARY)

BIN
gear Executable file

Binary file not shown.

65
imgui.ini Normal file
View file

@ -0,0 +1,65 @@
[Window][DockSpaceViewport_11111111]
Pos=0,19
Size=1362,710
Collapsed=0
[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0
[Window][Game Objects]
Pos=0,19
Size=231,710
Collapsed=0
DockId=0x00000001,0
[Window][Properties]
Pos=1081,19
Size=281,710
Collapsed=0
DockId=0x00000009,0
[Window][Viewport]
Pos=233,19
Size=846,710
Collapsed=0
DockId=0x00000005,0
[Window][Dear ImGui Demo]
Pos=233,476
Size=846,253
Collapsed=0
DockId=0x00000006,0
[Window][Dear ImGui Metrics/Debugger]
Pos=233,476
Size=846,253
Collapsed=0
DockId=0x00000006,1
[Window][About]
Pos=1081,545
Size=281,184
Collapsed=0
DockId=0x00000008,0
[Window][Debug]
Pos=1081,549
Size=281,180
Collapsed=0
DockId=0x0000000A,0
[Docking][Data]
DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,19 Size=1362,710 Split=X Selected=0x13926F0B
DockNode ID=0x00000003 Parent=0x8B93E3BD SizeRef=1079,710 Split=X
DockNode ID=0x00000001 Parent=0x00000003 SizeRef=231,710 Selected=0x09CA5163
DockNode ID=0x00000002 Parent=0x00000003 SizeRef=846,710 Split=Y Selected=0x13926F0B
DockNode ID=0x00000005 Parent=0x00000002 SizeRef=846,455 CentralNode=1 Selected=0x13926F0B
DockNode ID=0x00000006 Parent=0x00000002 SizeRef=846,253 Selected=0xE87781F4
DockNode ID=0x00000004 Parent=0x8B93E3BD SizeRef=281,710 Split=Y Selected=0x199AB496
DockNode ID=0x00000007 Parent=0x00000004 SizeRef=281,524 Split=Y Selected=0x199AB496
DockNode ID=0x00000009 Parent=0x00000007 SizeRef=281,528 Selected=0x199AB496
DockNode ID=0x0000000A Parent=0x00000007 SizeRef=281,180 Selected=0x392A5ADD
DockNode ID=0x00000008 Parent=0x00000004 SizeRef=281,184 Selected=0x3FEF9A19

243
main.c Normal file
View file

@ -0,0 +1,243 @@
#include <raylib.h>
#include <rlcimgui.h>
#include <imgui_impl_raylib.h>
#include <slibs/slibs.h>
#include <rlgl.h>
#include "viewport.h"
typedef struct game_object_t {
char name[128];
char* uuid;
} game_object;
const char* gl_versions[7] = {
"UNKNOWN",
"1.1",
"2.1",
"3.3",
"4.3",
"ES 2.0",
"ES 3.0"
};
Camera camera;
char* gen_uuid() {
char v[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
//3fb17ebc-bc38-4939-bc8b-74f2443281d4
//8 dash 4 dash 4 dash 4 dash 12
static char buf[37] = {0};
//gen random for all spaces because lazy
for(int i = 0; i < 36; ++i) {
buf[i] = v[rand()%16];
}
//put dashes in place
buf[8] = '-';
buf[13] = '-';
buf[18] = '-';
buf[23] = '-';
//needs end byte
buf[36] = '\0';
return buf;
}
int main() {
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(800, 600, "gear");
InitViewport();
rligSetup(true);
ImGuiIO *ioptr = igGetIO();
ioptr->ConfigFlags |= ImGuiConfigFlags_DockingEnable;
camera = (Camera){ 0 };
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);
ImGuiStyle* style = igGetStyle();
ImVec4* colors = style->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};
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);
obj->uuid = gen_uuid();
sl_vec_push(game_objects, obj);
}
//sl_vec_push(game_objects, (game_object){"john"});
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();
rligBegin();
{
if(igBeginMainMenuBar()) {
if(igBeginMenu("File", true)) {
if(igMenuItem_Bool("Quit", "ESC", false, true)) {
CloseWindow();
}
igEndMenu();
}
if(igBeginMenu("Debug", true)) {
igCheckbox("Show demo window", &show_demo);
igEndMenu();
}
igEndMainMenuBar();
}
igDockSpaceOverViewport(NULL, 0, NULL);
if(show_demo)
igShowDemoWindow(&show_demo);
RenderViewport();
igBegin("Game Objects", NULL, 0);
{
for(sl_vec_it(obj_ptr, game_objects)) {
game_object* obj = *obj_ptr;
igPushID_Str(obj->uuid);
if(igSelectable_Bool(obj->name, selected == obj, 0, (ImVec2){0, 0}))
selected = obj;
igPopID();
}
}
igEnd();
igBegin("Properties", NULL, 0);
{
if(selected != NULL) {
igInputText("##name", selected->name, 128, 0, NULL, NULL);
}
}
igEnd();
if(show_debug) {
igBegin("Debug", &show_debug, 0);
{
igText("raylib %s", RAYLIB_VERSION);
igText("OpenGL %s", gl_versions[rlGetVersion()]);
igText("FPS: %d", GetFPS());
igText("Frame time: %f", GetFrameTime());
igText("Cursor hidden: %d", IsCursorHidden());
igText("\nResolutions");
igText("Window: %dx%d", GetScreenWidth(), GetScreenHeight());
for(int i = 0; i < GetMonitorCount(); i++) {
igText("%s: %dx%d@%d", GetMonitorName(i), GetMonitorWidth(i),
GetMonitorHeight(i), GetMonitorRefreshRate(i));
}
}
igEnd();
}
}
rligEnd();
}
EndDrawing();
}
rligShutdown();
CloseWindow();
}

BIN
main.o Normal file

Binary file not shown.

68
old.oc Normal file
View file

@ -0,0 +1,68 @@
#include <raylib.h>
#include <slibs/slibs.h>
typedef struct {
Vector2 pos;
Vector2 size;
} window_state;
sl_vec(const char*) window_titles = { 0 };
sl_vec(window_state) window_states = { 0 };
int current_window = -1;
void BeginWindow(const char* title) {
for(int i = 0; i < window_titles.size; i++) {
if(window_titles.data[i] == title) {
current_window = i;
window_state* w = &window_states.data[current_window];
DrawRectangleV(w->pos, w->size, BLUE);
w->size = (Vector2) { 0.0f, 0.0f };
return;
}
}
window_state new_state = {
.pos = { 50.0f, 50.0f },
.size = { 0.0f, 0.0f }
};
sl_vec_push(window_titles, title);
sl_vec_push(window_states, new_state);
current_window = window_titles.size - 1;
}
void Text(const char* text) {
window_state* w = &window_states.data[current_window];
DrawText(text, w->pos.x, w->pos.y + w->size.y, 20, WHITE);
w->size.x += MeasureText(text, 20);
w->size.y += 20;
}
void EndWindow() {
window_state w = window_states.data[current_window];
}
int main() {
InitWindow(800, 600, "gear");
while(!WindowShouldClose()) {
BeginDrawing();
{
ClearBackground(BLACK);
BeginWindow("hi");
{
Text("balls");
Text("peter what are you doing");
}
EndWindow();
}
EndDrawing();
}
CloseWindow();
}

64
viewport.c Normal file
View file

@ -0,0 +1,64 @@
#include "viewport.h"
#include <raylib.h>
#include <rlcimgui.h>
#include <imgui_impl_raylib.h>
#include <stddef.h>
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);
}

10
viewport.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef __VIEWPORT_H__
#define __VIEWPORT_H__
void InitViewport();
void UpdateViewport();
void BeginViewport();
void EndViewport();
void RenderViewport();
#endif

BIN
viewport.o Normal file

Binary file not shown.