Created
May 3, 2021 19:15
-
-
Save untodesu/ac4470f58eb183460be93f5e0c038456 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <GLFW/glfw3.h> | |
#include <physfs.h> | |
#include "common/util.h" | |
#include "render/render.h" | |
#include "globals.h" | |
#include "window.h" | |
static void error_callback(int code, const char *message) | |
{ | |
lprintf("glfw error %d: %s", code, message); | |
} | |
int main(int argc, char **argv) | |
{ | |
if(!PHYSFS_init(argv[0])) | |
die("physfs: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); | |
PHYSFS_setWriteDir("."); | |
PHYSFS_mount(".", "/", false); | |
PHYSFS_mkdir("/assets"); | |
glfwSetErrorCallback(error_callback); | |
if(!glfwInit()) | |
die("glfw: init failed"); | |
init_globals(); | |
init_window(); | |
init_render(); | |
const vector2D vertices[3] = { | |
{ 000.0f, 600.0f }, | |
{ 400.0f, 000.0f }, | |
{ 800.0f, 600.0f } | |
}; | |
GLuint ubo; | |
glCreateBuffers(1, &ubo); | |
glNamedBufferData(ubo, (GLsizeiptr)sizeof(matrix4x4), NULL, GL_DYNAMIC_DRAW); | |
GLuint vbo; | |
glCreateBuffers(1, &vbo); | |
glNamedBufferData(vbo, (GLsizeiptr)sizeof(vertices), vertices, GL_STATIC_DRAW); | |
GLuint vao; | |
glCreateVertexArrays(1, &vao); | |
glVertexArrayVertexBuffer(vao, 0, vbo, 0, sizeof(vector2D)); | |
glEnableVertexArrayAttrib(vao, 0); | |
glVertexArrayAttribFormat(vao, 0, 2, GL_FLOAT, GL_FALSE, 0); | |
glVertexArrayAttribBinding(vao, 0, 0); | |
struct shader_s shaders[2]; | |
load_vertex_shader_file(shaders + 0, "/assets/shaders/init.vert.spv"); | |
load_fragment_shader_file(shaders + 1, "/assets/shaders/init.frag.spv"); | |
struct pipeline_s pipeline = { 0 }; | |
create_pipeline(&pipeline, shaders, 2); | |
while(!glfwWindowShouldClose(g_window)) { | |
globals_frame(); | |
glNamedBufferSubData(ubo, 0, (GLsizeiptr)sizeof(matrix4x4), g_globals.view.matrix); | |
glClear(GL_COLOR_BUFFER_BIT); | |
bind_pipeline(&pipeline); | |
glBindVertexArray(vao); | |
glBindBufferBase(GL_UNIFORM_BUFFER, 0, ubo); | |
glDrawArrays(GL_TRIANGLES, 0, 3); | |
glfwSwapBuffers(g_window); | |
glfwPollEvents(); | |
} | |
shutdown_window(); | |
shutdown_render(); | |
glfwTerminate(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment