multiple files

This commit is contained in:
Rakarake 2025-12-14 14:03:57 +01:00
parent 5943b483ce
commit 864df46d69
6 changed files with 324 additions and 296 deletions

128
glonkers.c Normal file
View file

@ -0,0 +1,128 @@
#include <stdio.h>
#include <time.h>
#include <stdint.h>
#include <string.h>
#include <wayland-client.h>
#include <wayland-util.h>
#include <SDL3/SDL.h>
#include "renderer.h"
//int main() {
// struct wl_display *display = wl_display_connect(NULL);
// if (!display) {
// fprintf(stderr, "Failed to connect to Wayland display.\n");
// return 1;
// }
// fprintf(stderr, "Connection established!\n");
//
// while (wl_display_dispatch(display) != -1) {
// }
//
// wl_display_disconnect(display);
//}
//struct our_state {
// // ...
// struct wl_compositor *compositor;
// // ...
//};
//
//static void
//registry_handle_global(void *data, struct wl_registry *registry,
// uint32_t name, const char *interface, uint32_t version)
//{
// printf("interface: '%s', version: %d, name: %d\n",
// interface, version, name);
//
// struct our_state *state = data;
//
// if (strcmp(interface, wl_compositor_interface.name) == 0) {
// state->compositor = wl_registry_bind(
// registry, name, &wl_compositor_interface, 4);
// }
//}
//
//static void
//registry_handle_global_remove(void *data, struct wl_registry *registry,
// uint32_t name)
//{
// // This space deliberately left blank
//}
//
//static const struct wl_registry_listener
//registry_listener = {
// .global = registry_handle_global,
// .global_remove = registry_handle_global_remove,
//};
//
//int
//main(int argc, char *argv[])
//{
// struct our_state state = { 0 };
// struct wl_display *display = wl_display_connect(NULL);
// struct wl_registry *registry = wl_display_get_registry(display);
// wl_registry_add_listener(registry, &registry_listener, &state);
// wl_display_roundtrip(display);
// return 0;
//}
struct timespec program_start;
void init_timer() {
clock_gettime(CLOCK_MONOTONIC, &program_start);
}
double time_since_start() {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
return (now.tv_sec - program_start.tv_sec) +
(now.tv_nsec - program_start.tv_nsec) / 1e9;
}
int main() {
init_timer();
printf("Good Morning 🍵\n");
SDL_Init(SDL_INIT_VIDEO);
SDL_SetHint(SDL_HINT_OPENGL_ES_DRIVER, "1");
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_Window* window = SDL_CreateWindow("SDL3 OpenGL Cube",
800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (!window) {
printf("CreateWindow Error: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
SDL_GLContext glContext = SDL_GL_CreateContext(window);
if (!glContext) {
printf("GL Context Error: %s\n", SDL_GetError());
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
Renderer renderer = new_renderer();
SDL_Event e;
int running = 1;
int w, h;
while (running) {
while (SDL_PollEvent(&e)) {
if (e.type == SDL_EVENT_QUIT) running = false;
if (e.type == SDL_EVENT_WINDOW_RESIZED) {
SDL_GetWindowSize(window, &w, &h);
}
}
double time = time_since_start();
render(&renderer, w, h, time);
SDL_GL_SwapWindow(window);
}
}