93 lines
2.0 KiB
C
93 lines
2.0 KiB
C
#include <assert.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "pltf/pltf.h"
|
|
#include "pltf/gl_funcs.h"
|
|
#include "shader.h"
|
|
|
|
void counter_cb(void* user_data) {
|
|
int* counter = (int*) user_data;
|
|
printf("Counter: %d\n", *counter);
|
|
(*counter)++;
|
|
}
|
|
|
|
int main() {
|
|
pltf_init();
|
|
pltf_window_create();
|
|
pltf_gl_ctx_create();
|
|
pltf_gl_funcs_load();
|
|
|
|
pltf_gl_ctx_info_print();
|
|
|
|
pltf_key_callback_set(PLTF_KEY_ESC, pltf_window_close, NULL);
|
|
int counter = 0;
|
|
pltf_key_callback_set(PLTF_KEY_Q, counter_cb, &counter);
|
|
|
|
// clang-format off
|
|
const float triangle_verts[] = {
|
|
// pos
|
|
0.0f, 0.5f, 0.0f, // top
|
|
-0.25f, -0.25f, 0.0f, // bottom-left
|
|
0.25f, -0.25f, 0.0f // bottom-right
|
|
|
|
};
|
|
// clang-format on
|
|
|
|
const size_t triangle_vert_count = sizeof(triangle_verts) / sizeof(triangle_verts[0]) / 3;
|
|
|
|
unsigned int triangle_vao = 0;
|
|
glGenVertexArrays(1, &triangle_vao);
|
|
glBindVertexArray(triangle_vao);
|
|
|
|
unsigned int triangle_vbo = 0;
|
|
glGenBuffers(1, &triangle_vbo);
|
|
glBindBuffer(GL_ARRAY_BUFFER, triangle_vbo);
|
|
glBufferData(
|
|
GL_ARRAY_BUFFER,
|
|
sizeof(triangle_verts),
|
|
triangle_verts,
|
|
GL_STATIC_DRAW
|
|
);
|
|
glEnableVertexAttribArray(0);
|
|
glVertexAttribPointer(
|
|
0,
|
|
3,
|
|
GL_FLOAT,
|
|
GL_FALSE,
|
|
sizeof(float) * 3,
|
|
(void*) 0
|
|
);
|
|
|
|
glBindVertexArray(0);
|
|
|
|
const unsigned int shader = shader_create(
|
|
"shader.vert",
|
|
"shader.frag"
|
|
);
|
|
|
|
glClearColor(0.0f, 0.0f, 0.8f, 1.0f);
|
|
|
|
while (true) {
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
glUseProgram(shader);
|
|
glBindVertexArray(triangle_vao);
|
|
glDrawArrays(GL_TRIANGLES, 0, triangle_vert_count);
|
|
|
|
pltf_swap_buffers();
|
|
|
|
const int pltf_we = pltf_window_event_handle();
|
|
if (pltf_we == PLTF_WE_DESTROY) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
pltf_gl_ctx_destroy();
|
|
pltf_window_destroy();
|
|
pltf_deinit();
|
|
|
|
return 0;
|
|
}
|