using renderer, shader not working
This commit is contained in:
parent
6565663d56
commit
caed914bcd
2 changed files with 112 additions and 1 deletions
111
glonkers.c
111
glonkers.c
|
|
@ -14,6 +14,20 @@
|
|||
#include <EGL/egl.h>
|
||||
#include <wayland-egl.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
struct client_state {
|
||||
int width, height;
|
||||
/* Globals */
|
||||
|
|
@ -206,6 +220,13 @@ static void egl_init(struct client_state *state) {
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char *shader_path = NULL;
|
||||
if (argc >= 2) {
|
||||
shader_path = argv[1];
|
||||
} else {
|
||||
printf("need to supply path to shader\n");
|
||||
exit(1);
|
||||
}
|
||||
int width = 700, height = 450;
|
||||
struct client_state state = { width, height, 0 };
|
||||
state.wl_display = wl_display_connect(NULL);
|
||||
|
|
@ -223,9 +244,99 @@ main(int argc, char *argv[])
|
|||
|
||||
egl_init(&state);
|
||||
|
||||
Renderer renderer = new_renderer();
|
||||
|
||||
while (wl_display_dispatch(state.wl_display)) {
|
||||
double time = time_since_start();
|
||||
render(&renderer, state.width, state.height, time, shader_path, false);
|
||||
eglSwapBuffers(state.egl_display, state.egl_surface);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
//_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);
|
||||
//}
|
||||
//
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ void render(Renderer *state, int w, int h, double time, char *shader_path, int r
|
|||
// Rendorrrr
|
||||
glViewport(0, 0, w, h);
|
||||
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); // Dark gray background
|
||||
glClearColor(0.3f, 0.3f, 0.3f, 1.0f); // Dark gray background
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Shader parameters.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue