gearlib/test/main.c

128 lines
3.2 KiB
C

#include <gearlib.h>
Camera* create_camera(vec2 pos) {
Camera* camera = calloc(sizeof(Camera), 1);
camera->view = mat4Transpose(mat4Translate(pos.x, pos.y, -3.0f));
return camera;
}
void update_camera(Camera* camera, Window window) {
int width, height;
glfwGetWindowSize(window, &width, &height);
assert(camera != NULL);
camera->projection = mat4Transpose(mat4Ortho(0.0f, width, height, 0.0f, 0.0f, 1000.0f));
//camera->projection = mat4Transpose(mat4Perspective(45.0f * DEG2RAD, ((double)width / (double)height), 0.1f, 100.0f));
}
typedef struct CameraData {
mat4 view_projection;
} CameraData;
int main() {
Window window = create_window(800, 600, "gearlib");
glfwSwapInterval(0);
enable_debugging();
setup_quads();
setup_textures();
Camera* camera = create_camera(vec2(0.0f, 0.0f));
set_active_camera(camera);
Texture cat = load_texture("assets/cat.png");
/*uint32_t cat = load_texture("assets/cat.png");
uint32_t cuddle = load_texture("assets/cuddle.png");
uint32_t parrots = load_texture("assets/parrots.png");*/
double time = glfwGetTime();
/*double total_time = 0;
int frames = 0;
int fps = 0;*/
uint32_t ubo;
glCreateBuffers(1, &ubo);
glNamedBufferStorage(ubo, sizeof(Camera), NULL, GL_DYNAMIC_STORAGE_BIT);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, ubo);
float angle = 0;
while (!glfwWindowShouldClose(window)) {
process_input(window);
update_camera(camera, window);
glNamedBufferSubData(ubo, 0, sizeof(Camera), camera);
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
/*for(int i = 0; i < 33; i++) {
draw_texture(parrots, vec3(-0.4f, 0.4f, 0.0f), WHITE);
draw_texture(cat, vec3(0.0f, 0.0f, 0.0f), WHITE);
draw_texture(cuddle, vec3(0.0f, -0.4f, 0.0f), WHITE);
}*/
//draw_texture(cat, vec2(300, 400), vec2(700, 700), WHITE);
//for(int i = 0; i < 255; i++)
//draw_quad(vec2(i, i), vec2(10, 10), vec4(i / 255.0f, i / 255.0f, i / 255.0f, 1.0f));
mat4 transform = mat4Multiply(
mat4Multiply(
mat4Scale(100, 100, 1),
mat4Identity()),
/*mat4Rotate(vec3(1.0f, 0.5f, 0.0f), angle)),*/
mat4Translate(0, 0, 1));
transform = mat4Multiply(mat4Translate(0.5, 0.5f, 0.0f), transform);
draw_texture_trans(cat, transform, WHITE);
flush();
double end_time = glfwGetTime();
double frame_time = end_time - time;
//total_time += frame_time;
double fps = 1 / frame_time;
angle += frame_time;
time = end_time;
/*frames++;
if(total_time > 1.0) {
fps = frames;
frames = 0;
total_time = 0;
}*/
//printf("%lf, %lf\n", frame_time, fps);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
/*
double time = glfwGetTime();
...
double end_time = glfwGetTime();
double frame_time = end_time - time;
double fps = 1 / frame_time;
time = end_time;
printf("%lf, %lf, %d, %d\n", frame_time, fps, 0, 0);
*/