a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit 3885c5b602323f1b955680b32b48f7462c6cf1d9
parent cf9499da4a0512a2c0de111c9d584c5001bee60e
Author: amin <dev@aminmesbah.com>
Date:   Wed, 16 May 2018 06:46:57 +0000

Make window resizeable

FossilOrigin-Name: a1eab61508850e9832294cfede2fd4dad269582f3d13d81c10408f034092d08a
Diffstat:
Msrc/main.c | 59++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 44 insertions(+), 15 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -3,56 +3,85 @@ #include <glad/glad.h> #include <GLFW/glfw3.h> -#ifdef GLAD_DEBUG -void pre_gl_callback(const char *func_name, void *func_ptr, int len_args, ...) -{ - printf("Calling: %s (%d arguments)\n", func_name, len_args); -} -#endif +#include "shader.h" +#include "glmth.h" -void error_callback(int error, const char* description) -{ - fprintf(stderr, "Error: %s\n", description); -} #define SCR_WIDTH 800 #define SCR_HEIGHT 600 +void error_callback(int error, const char* description); +void framebuffer_size_callback(GLFWwindow* window, int width, int height); + +#ifdef GLAD_DEBUG +void pre_gl_callback(const char *func_name, void *func_ptr, int len_args, ...); +#endif + + int main(void) { glfwSetErrorCallback(error_callback); if (!glfwInit()) { - fprintf(stderr, "GLFW initialization failed"); + fprintf(stderr, "GLFW initialization failed\n"); return -1; } + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "A Game", NULL, NULL); if (!window) { - fprintf(stderr, "GLFW window creation failed"); + fprintf(stderr, "GLFW window creation failed\n"); glfwTerminate(); return -1; } - glfwMakeContextCurrent(window); + glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); + if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) { - fprintf(stderr, "glad initialization failed"); + fprintf(stderr, "glad initialization failed\n"); + glfwDestroyWindow(window); + glfwTerminate(); return -1; } - printf("Hello, world"); + glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT); while (!glfwWindowShouldClose(window)) { + glClearColor(0.1f, 0.1f, 0.1f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + glfwSwapBuffers(window); + glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); return 0; } + + +void error_callback(int error, const char* description) +{ + fprintf(stderr, "Error: %s\n", description); +} + + +void framebuffer_size_callback(GLFWwindow* window, int width, int height) +{ + glViewport(0, 0, width, height); +} + + +#ifdef GLAD_DEBUG +void pre_gl_callback(const char *func_name, void *func_ptr, int len_args, ...) +{ + printf("Calling: %s (%d arguments)\n", func_name, len_args); +} +#endif