raytracer/main.c
2024-05-10 09:06:15 +12:00

64 lines
1.7 KiB
C

#include <gearlib.h>
int main() {
Window window = create_window(800, 600, "raytracing");
glfwSwapInterval(0);
enable_debugging();
RenderBatch* surface = create_batch(sizeof(vec2), 6);
surface->shader = load_shader_program(
compile_shader("raycast.vert", GL_VERTEX_SHADER),
compile_shader("raycast.frag", GL_FRAGMENT_SHADER), 0);
batch_add_attrib(surface, (VertexAttrib){
.type = GL_FLOAT, .size = sizeof(float), .count = 2
});
batch_bind_attribs(surface);
vec2 vertices[] = {
vec2(-1.0f, 1.0f), vec2(-1.0f, -1.0f), vec2(1.0f, -1.0f),
vec2(1.0f, -1.0f), vec2(1.0f, 1.0f), vec2(-1.0f, 1.0f),
};
glNamedBufferSubData(surface->vbo, 0, surface->vertex_size * 6, vertices);
glUseProgram(surface->shader);
float start_time = glfwGetTime();
float elapsed_time = 0.0f;
uint32_t ssbo;
glCreateBuffers(1, &ssbo);
glNamedBufferStorage(ssbo, sizeof(int), NULL, GL_DYNAMIC_STORAGE_BIT);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, ssbo);
int ray_count = 0;
while(!glfwWindowShouldClose(window)) {
//glNamedBufferSubData(ssbo, 0, sizeof(int), &ray_count);
int w, h;
glfwGetWindowSize(window, &w, &h);
float aspect_ratio = (float)w / (float)h;
glUniform1f(0, aspect_ratio);
glUniform1f(1, sin(elapsed_time));
renderer_draw(surface->vao, 6);
glfwSwapBuffers(window);
glfwPollEvents();
float end_time = glfwGetTime();
float frame_time = end_time - start_time;
start_time = end_time;
elapsed_time += frame_time;
float fps = 1.0f / frame_time;
printf("fps: %f\n", fps);
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}