From 90fb30cf3a92690178e5ad39095f604c2bc50afa Mon Sep 17 00:00:00 2001 From: pryazha Date: Fri, 6 Jun 2025 10:30:01 +0500 Subject: trying to add windows support, also a lot of changes, some ui modifications --- src/game/game.c | 117 -------------------------------------------------------- 1 file changed, 117 deletions(-) delete mode 100644 src/game/game.c (limited to 'src/game/game.c') diff --git a/src/game/game.c b/src/game/game.c deleted file mode 100644 index 47d70eb..0000000 --- a/src/game/game.c +++ /dev/null @@ -1,117 +0,0 @@ -void init(State *state) -{ - U32 nmeshes; - Mesh *meshes; - - state->parena = arena_alloc(Kilobytes(256)); - - state->camera = camera_init(v3(0.0f, 0.0f, 3.0f), - 90.0f, 0.1f, 100.0f, - 0.0f, 0.0f, 0.0f); - state->camera_dp = V3_ZERO; - - state->mesh_shader = load_shader("shaders/default.vert", 0, "shaders/default.frag"); - state->ui_shader = load_shader("shaders/ui.vert", 0, "shaders/ui.frag"); - - state->texture = load_texture(state->parena, str8lit("data/textures/grid.png"), 0); - - nmeshes = 2; - meshes = arena_push(state->parena, nmeshes*sizeof(Mesh)); - meshes[0] = *mesh_gen_circle(state->parena, v3(0.0f, 0.0f, 2.0f), V3_ZERO, 3.0f, 6); - meshes[1] = *mesh_gen_quad(state->parena, V3_ZERO, v3(0.0f, 90.0f, 0.0f), 2.0f, 2.0f); - - mesh_add_texture(&meshes[0], state->texture); - - state->model = model_init(state->parena, V3_ZERO, V3_ZERO, meshes, nmeshes); -} - -void update_camera_first_person(State *state, Input *input, F32 speed, F32 mouse_sens) -{ - V3 ddp, r, u, f; - - camera_get_vectors_first_person(&state->camera, &r, &u, &f); - ddp = V3_ZERO; - if (key_is_pressed(input->move_forward)) - ddp = v3add(ddp, v3inv(f)); - if (key_is_pressed(input->move_backward)) - ddp = v3add(ddp, f); - if (key_is_pressed(input->move_right)) - ddp = v3add(ddp, r); - if (key_is_pressed(input->move_left)) - ddp = v3add(ddp, v3inv(r)); - if (key_is_pressed(input->move_up)) - ddp = v3add(ddp, u); - if (key_is_pressed(input->move_down)) - ddp = v3add(ddp, v3inv(u)); - ddp = v3norm(ddp); - - state->camera.pos = v3add(state->camera.pos, state->camera_dp); - state->camera_dp = v3scalef(v3add(state->camera_dp, v3scalef(ddp, input->dt*speed)), 0.8f); - - /* NOTE(pryazha): Camera angles */ - if (input->capture_mouse) { - state->camera.yaw += input->mouse_offset.x*mouse_sens; - state->camera.pitch += input->mouse_offset.y*mouse_sens; - if (state->camera.pitch > 89.0f) - state->camera.pitch = 89.0f; - if (state->camera.pitch < -89.0f) - state->camera.pitch = -89.0f; - } -} - -void update_and_render(Window *wnd, State *state, Input *input) -{ - /* NOTE(pryazha): Update */ - if (key_first_press(input->exit)) { - if (input->capture_mouse) { - input->capture_mouse = 0; - } else { - input->is_running = 0; - } - } - - /* NOTE(pryazha): Camera movement */ - update_camera_first_person(state, input, 1.0f, 0.3f); - - state->model->rotate.z += 20.0f*input->dt; - state->model->rotate.x += 20.0f*input->dt; - - /* NOTE(pryazha): Render */ - MAT4 proj, view; - F32 ar; - Arena *ui_arena; - - glViewport(0, 0, wnd->width, wnd->height); - - glClearColor(0.15f, 0.15f, 0.15f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); - - ar = (F32)wnd->width/(F32)wnd->height; - proj = camera_persp(state->camera, ar); - view = camera_get_view_matrix_first_person(&state->camera); - - model_draw(state->mesh_shader, &proj, &view, state->model); - - glUseProgram(state->ui_shader); - proj = ortho(0.0f, (F32)wnd->width, 0.0f, (F32)wnd->height, -1.0f, 1.0f); - shader_set_mat4fv(state->ui_shader, "proj", proj); - ui_arena = arena_alloc(0); - glDisable(GL_DEPTH_TEST); - - if (button(wnd, state->ui_shader, input, ui_arena, str8lit("some name"), - v2(wnd->width/8.0f, wnd->height/8.0f), 50.0f, 30.0f)) - { - input->capture_mouse = 1; - } - - glEnable(GL_DEPTH_TEST); - glUseProgram(0); - arena_release(ui_arena); - - state->t += input->dt; -} - -void clear(State *state) -{ - arena_release(state->parena); -} -- cgit v1.2.3-70-g09d2