initial commit
This commit is contained in:
80
src/main.cpp
Normal file
80
src/main.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "glad/gl.h"
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
GLFWwindow* gWindow;
|
||||
int gWindowWidth = 800;
|
||||
int gWindowHeight = 600;
|
||||
|
||||
int glVersionMajor;
|
||||
int glVersionMinor;
|
||||
|
||||
void glfw_error_callback(int error, const char* description);
|
||||
void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
void glfw_framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||
|
||||
int main() {
|
||||
spdlog::info("b_engine start");
|
||||
|
||||
if (!glfwInit()) {
|
||||
spdlog::error("could not initialize glfw");
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
glfwSetErrorCallback(glfw_error_callback);
|
||||
|
||||
gWindow = glfwCreateWindow(gWindowWidth, gWindowHeight, "b_engine v0.0.1", nullptr, nullptr);
|
||||
if (!gWindow) {
|
||||
spdlog::error("failed to create glfw window");
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(gWindow);
|
||||
|
||||
glfwSetKeyCallback(gWindow, glfw_key_callback);
|
||||
glfwSetFramebufferSizeCallback(gWindow, glfw_framebuffer_size_callback);
|
||||
|
||||
int version = gladLoadGL(glfwGetProcAddress);
|
||||
glVersionMajor = GLAD_VERSION_MAJOR(version);
|
||||
glVersionMinor = GLAD_VERSION_MINOR(version);
|
||||
spdlog::info("gl version {}.{}", glVersionMajor, glVersionMinor);
|
||||
|
||||
int fbWidth, fbHeight;
|
||||
glfwGetFramebufferSize(gWindow, &fbWidth, &fbHeight);
|
||||
glViewport(0, 0, fbWidth, fbHeight);
|
||||
|
||||
while (!glfwWindowShouldClose(gWindow)) {
|
||||
glfwPollEvents();
|
||||
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glfwSwapBuffers(gWindow);
|
||||
}
|
||||
|
||||
glfwDestroyWindow(gWindow);
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void glfw_error_callback(int error, const char* description) {
|
||||
spdlog::error("glfw error: {}", description);
|
||||
}
|
||||
|
||||
void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
void glfw_framebuffer_size_callback(GLFWwindow *window, int width, int height) {
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
Reference in New Issue
Block a user