diff options
| author | KonAki <konaki@anokonaki.org> | 2026-10-07 19:07:15 +0800 |
|---|---|---|
| committer | KonAki <konaki@anokonaki.org> | 2026-10-07 19:07:15 +0800 |
| commit | ea7ecfd33cd633d3ce2d4c87f87bfbfb4b8bfa85 (patch) | |
| tree | 6dc6f2dd3bf625f4fb80e7bdda9ae2167ff7eda1 /src | |
| parent | dfa9a616c3d89a935a4c0bf68f7801581d8b5037 (diff) | |
Move engine.c and impl stubs from kon/src to src
Diffstat (limited to 'src')
| -rw-r--r-- | src/engine.c | 68 | ||||
| -rw-r--r-- | src/impl/konfont.c | 2 | ||||
| -rw-r--r-- | src/impl/koninput.c | 2 | ||||
| -rw-r--r-- | src/impl/konsofren.c | 2 | ||||
| -rw-r--r-- | src/impl/kontime.c | 2 | ||||
| -rw-r--r-- | src/impl/kontoml.c | 2 | ||||
| -rw-r--r-- | src/impl/konwinlib.c | 2 |
7 files changed, 80 insertions, 0 deletions
diff --git a/src/engine.c b/src/engine.c new file mode 100644 index 0000000..06bac29 --- /dev/null +++ b/src/engine.c @@ -0,0 +1,68 @@ +#include "konwinlib.h" +#include "konsofren.h" +#include "kontime.h" + +#define GAME_WIDTH 320 +#define GAME_HEIGHT 180 + +int main(void) +{ + kon_window_t *window; + kon_display_t *display; + kon_camera_t camera; + kon_material_t material; + kon_light_t light; + kon_time last; + float angle = 0.0f; + + if (!kon_init()) return 1; + + window = kon_createWindow("engine", 0, 0, 800, 600, KON_WINDOW_CENTER | KON_WINDOW_RESIZABLE); + if (!window) return 1; + kon_setExitKey(window, KON_KEY_ESCAPE); + + display = kon_createDisplay(GAME_WIDTH, GAME_HEIGHT, 800, 600); + if (!display) return 1; + + camera = kon_cameraDefault(); + camera.position = KON_VEC3(3, 3, 6); + material = kon_materialColor(0xFFC8C8FF); + light = kon_lightDefault(); + last = kon_getTime(); + + while (!kon_windowShouldClose(window)) { + kon_event_t ev; + kon_time now; + kon_mat4_t model, viewProjection; + + while (kon_pollEvent(window, &ev)) { + if (ev.type == KON_EVENT_RESIZE) { + kon_resizeDisplay(display, ev.width, ev.height); + } + if (ev.type == KON_EVENT_KEY_DOWN && ev.key == KON_KEY_O) { + camera.projection = (camera.projection == KON_PROJECTION_PERSPECTIVE) + ? KON_PROJECTION_ORTHOGRAPHIC : KON_PROJECTION_PERSPECTIVE; + } + } + + now = kon_getTime(); + angle += (float)(now - last); + last = now; + + model = kon_mat4Identity(); + model = kon_mat4Rotate(model, KON_VEC3(angle * 0.5f, angle, 0)); + viewProjection = kon_cameraViewProjection(&camera, display->game->width, display->game->height); + + kon_clearFramebuffer(display->game, KON_BACKGROUND_COLOR); + kon_drawMesh(display->game, viewProjection, model, &kon_cubeMesh, &material, &light, KON_RENDER_DEFAULT); + + kon_presentDisplay(display); + kon_blitPixels(window, display->screen->data, display->screen->width, display->screen->height); + kon_sleep(0.008); + } + + kon_freeDisplay(display); + kon_destroyWindow(window); + kon_deinit(); + return 0; +} diff --git a/src/impl/konfont.c b/src/impl/konfont.c new file mode 100644 index 0000000..04c3bd8 --- /dev/null +++ b/src/impl/konfont.c @@ -0,0 +1,2 @@ +#define KONFONT_IMPLEMENTATION +#include "konfont.h" diff --git a/src/impl/koninput.c b/src/impl/koninput.c new file mode 100644 index 0000000..30f2479 --- /dev/null +++ b/src/impl/koninput.c @@ -0,0 +1,2 @@ +#define KONINPUT_IMPLEMENTATION +#include "koninput.h" diff --git a/src/impl/konsofren.c b/src/impl/konsofren.c new file mode 100644 index 0000000..9d7a5ea --- /dev/null +++ b/src/impl/konsofren.c @@ -0,0 +1,2 @@ +#define KONSOFREN_IMPLEMENTATION +#include "konsofren.h" diff --git a/src/impl/kontime.c b/src/impl/kontime.c new file mode 100644 index 0000000..c7f00b6 --- /dev/null +++ b/src/impl/kontime.c @@ -0,0 +1,2 @@ +#define KONTIME_IMPLEMENTATION +#include "kontime.h" diff --git a/src/impl/kontoml.c b/src/impl/kontoml.c new file mode 100644 index 0000000..c0eca58 --- /dev/null +++ b/src/impl/kontoml.c @@ -0,0 +1,2 @@ +#define KONTOML_IMPLEMENTATION +#include "kontoml.h" diff --git a/src/impl/konwinlib.c b/src/impl/konwinlib.c new file mode 100644 index 0000000..89d791a --- /dev/null +++ b/src/impl/konwinlib.c @@ -0,0 +1,2 @@ +#define KONWINLIB_IMPLEMENTATION +#include "konwinlib.h" |
