2024-05-03 11:18:50 +12:00
|
|
|
#include <gearlib.h>
|
2024-05-03 22:52:53 +12:00
|
|
|
|
|
|
|
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;
|
2024-04-29 19:32:59 +12:00
|
|
|
|
2024-04-29 22:41:13 +12:00
|
|
|
int main() {
|
2024-04-30 23:02:19 +12:00
|
|
|
Window window = create_window(800, 600, "gearlib");
|
2024-05-03 11:18:50 +12:00
|
|
|
glfwSwapInterval(0);
|
|
|
|
enable_debugging();
|
2024-05-03 22:52:53 +12:00
|
|
|
setup_quads();
|
2024-05-03 11:18:50 +12:00
|
|
|
setup_textures();
|
2024-05-03 22:52:53 +12:00
|
|
|
|
|
|
|
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");
|
2024-05-03 11:18:50 +12:00
|
|
|
uint32_t cuddle = load_texture("assets/cuddle.png");
|
2024-05-03 22:52:53 +12:00
|
|
|
uint32_t parrots = load_texture("assets/parrots.png");*/
|
2024-05-03 11:18:50 +12:00
|
|
|
|
|
|
|
double time = glfwGetTime();
|
2024-05-03 22:52:53 +12:00
|
|
|
/*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;
|
2024-04-29 19:32:59 +12:00
|
|
|
|
|
|
|
while (!glfwWindowShouldClose(window)) {
|
|
|
|
process_input(window);
|
2024-05-03 22:52:53 +12:00
|
|
|
update_camera(camera, window);
|
|
|
|
|
|
|
|
glNamedBufferSubData(ubo, 0, sizeof(Camera), camera);
|
2024-04-29 19:32:59 +12:00
|
|
|
|
|
|
|
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2024-05-03 22:52:53 +12:00
|
|
|
|
|
|
|
/*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));
|
2024-04-29 19:32:59 +12:00
|
|
|
|
2024-05-03 22:52:53 +12:00
|
|
|
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);
|
2024-05-03 11:18:50 +12:00
|
|
|
|
2024-05-03 22:52:53 +12:00
|
|
|
draw_texture_trans(cat, transform, WHITE);
|
|
|
|
|
|
|
|
flush();
|
2024-04-30 23:02:19 +12:00
|
|
|
|
2024-05-03 11:18:50 +12:00
|
|
|
double end_time = glfwGetTime();
|
|
|
|
double frame_time = end_time - time;
|
2024-05-03 22:52:53 +12:00
|
|
|
//total_time += frame_time;
|
2024-05-03 11:18:50 +12:00
|
|
|
double fps = 1 / frame_time;
|
2024-05-03 22:52:53 +12:00
|
|
|
|
|
|
|
angle += frame_time;
|
|
|
|
|
2024-05-03 11:18:50 +12:00
|
|
|
time = end_time;
|
2024-04-30 23:02:19 +12:00
|
|
|
|
2024-05-03 22:52:53 +12:00
|
|
|
/*frames++;
|
|
|
|
if(total_time > 1.0) {
|
|
|
|
fps = frames;
|
|
|
|
frames = 0;
|
|
|
|
total_time = 0;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
//printf("%lf, %lf\n", frame_time, fps);
|
2024-04-29 22:41:13 +12:00
|
|
|
|
2024-04-29 19:32:59 +12:00
|
|
|
glfwSwapBuffers(window);
|
|
|
|
glfwPollEvents();
|
|
|
|
}
|
|
|
|
|
2024-05-03 22:52:53 +12:00
|
|
|
glfwDestroyWindow(window);
|
2024-04-29 19:32:59 +12:00
|
|
|
glfwTerminate();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-03 22:52:53 +12:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
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);
|
|
|
|
*/
|