Much much better

This commit is contained in:
2021-02-23 07:57:24 +11:00
parent adc7f5e208
commit 4f02128553
24 changed files with 371 additions and 360 deletions

View File

@ -0,0 +1,75 @@
// Copyright (c) 2021 Dominic Msters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "glwfwplatform.h"
GLFWwindow *window;
game_t *runningGame;
int32_t main() {
// Create out platform context
platform_t platform = {
.name = "glfw",
.screenWidth = WINDOW_WIDTH_DEFAULT,
.screenHeight = WINDOW_HEIGHT_DEFAULT
};
// Attempt to init GLFW
if(!glfwInit()) return NULL;
window = glfwCreateWindow(platform.screenWidth, platform.screenHeight,
"", NULL, NULL
);
if(!window) {
glfwTerminate();
return 1;
}
// Load GLAD
glfwMakeContextCurrent(window);
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
// Setup window listeners
glfwSetWindowSizeCallback(window, &glfwOnResize);
glfwSetKeyCallback(window, &glfwOnKey);
// Create the game instance
runningGame = gameInit(&platform);
if(runningGame == NULL) return 1;
// Main Render Loop
while(!glfwWindowShouldClose(window)) {
gameUpdate(runningGame);
glfwSwapBuffers(window);
glfwPollEvents();
}
// Game has finished running, cleanup.
gameDispose(runningGame);
// Terminate the GLFW context.
glfwSetWindowSizeCallback(window, NULL);
glfwTerminate();
return 0;
}
void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height) {
engine_t *engine = gameGetEngine(runningGame);
engine->platform->screenWidth = width;
engine->platform->screenWidth = height;
renderSetResolution(engine->render, width, height);
}
void glfwOnKey(GLFWwindow *window,
int32_t key, int32_t scancode, int32_t action, int32_t mods
) {
char *title = glfwGetKeyName(key, scancode);
if(title == NULL) {
printf("Unknown Key %d", scancode);
} else {
printf(title);
}
printf("\n");
}

View File

@ -0,0 +1,47 @@
// Copyright (c) 2021 Dominic Msters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
// I load GLAD and GLFW Here because they need to be included in specific orders
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <stdint.h>
#include "../../engine/platform.h"
#include "../../engine/game/game.h"
#include "../../engine/display/render.h"
#define WINDOW_WIDTH_DEFAULT 480
#define WINDOW_HEIGHT_DEFAULT 270
/** The GLFW Window Context Pointer */
extern GLFWwindow *window;
extern game_t *runningGame;
/**
* Entry of the program
* @return 0 if success, anything else for failure.
*/
int32_t main();
/**
* Resize callbacks.
*
* @param window Window that was resized.
* @param width New window width.
* @param height New window height.
*/
void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height);
/**
* Keyboard Input callbacks.
*
* @param window Window that was resized.
*/
void glfwOnKey(GLFWwindow *window,
int32_t key, int32_t scancode, int32_t action, int32_t mods
);