167 lines
4.3 KiB
C
167 lines
4.3 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <signal.h>
|
|
#include <time.h>
|
|
#include <stdint.h>
|
|
#include <wayland-client.h>
|
|
#include <wayland-util.h>
|
|
#include <SDL3/SDL.h>
|
|
#include <pthread.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, ®istry_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;
|
|
//}
|
|
//
|
|
//_Atomic bool running = true;
|
|
//
|
|
//void intHandler(int dummy) {
|
|
// printf("exiting\n");
|
|
// running = false;
|
|
// fclose(stdin);
|
|
//}
|
|
//
|
|
//bool reload_shader = false;
|
|
//
|
|
///// reads stdin on a separate thread.
|
|
//void *read_stdin(void *ptr) {
|
|
// char buff[10];
|
|
// while (running) {
|
|
// fgets(buff, 10, stdin);
|
|
// if (strcmp(buff, "r\n") == 0) {
|
|
// printf("reloading shader\n");
|
|
// reload_shader = true;
|
|
// }
|
|
// }
|
|
// return NULL;
|
|
//}
|
|
//
|
|
//int main(int argc, char *argv[]) {
|
|
// signal(SIGINT, intHandler);
|
|
// pthread_t stdin_thread;
|
|
// pthread_create( &stdin_thread, NULL, read_stdin, NULL);
|
|
//
|
|
// 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 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);
|
|
// }
|
|
// }
|
|
//
|
|
// char *shader_path = NULL;
|
|
// if (argc >= 2) {
|
|
// shader_path = argv[1];
|
|
// } else {
|
|
// printf("need to supply path to shader\n");
|
|
// exit(1);
|
|
// }
|
|
//
|
|
// double time = time_since_start();
|
|
// render(&renderer, w, h, time, shader_path, reload_shader);
|
|
// if (reload_shader) reload_shader = false;
|
|
//
|
|
// SDL_GL_SwapWindow(window);
|
|
// }
|
|
//
|
|
// pthread_join(stdin_thread, NULL);
|
|
//}
|
|
//
|