Blank window
This commit is contained in:
@@ -1,3 +1,16 @@
|
||||
project(UglyMain)
|
||||
|
||||
add_executable(${PROJECT_NAME} main.c)
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.cpp
|
||||
src/App.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ./src
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
GLEW::GLEW
|
||||
glfw
|
||||
glm::glm
|
||||
)
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
printf("hello world!\n");
|
||||
}
|
||||
12
source/app/main.cpp
Normal file
12
source/app/main.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "App.hpp"
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
auto args = std::vector<std::string>{};
|
||||
std::copy_n(argv, argc, std::back_inserter(args));
|
||||
return App::main(args);
|
||||
}
|
||||
63
source/app/src/App.cpp
Normal file
63
source/app/src/App.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "App.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
int App::main(std::vector<std::string> &args) {
|
||||
auto app = App{};
|
||||
app.game_loop();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void App::error_callback_s(int error, const char *description)
|
||||
{
|
||||
std::cerr << "[GLFW error]: " << description << '\n';
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
void App::key_callback_s(GLFWwindow *window, int key, int scancode, int action, int mods) {
|
||||
auto app = static_cast<App*>(glfwGetWindowUserPointer(window));
|
||||
app->key_callback(key, scancode, action, mods);
|
||||
}
|
||||
|
||||
|
||||
App::App():
|
||||
mpWindow{NULL} {
|
||||
glfwSetErrorCallback(error_callback_s);
|
||||
glfwInit();
|
||||
|
||||
mpWindow = glfwCreateWindow(640, 480, "uGLy", NULL, NULL);
|
||||
glfwSetWindowUserPointer(mpWindow, this);
|
||||
glfwSetKeyCallback(mpWindow, key_callback_s);
|
||||
|
||||
glfwMakeContextCurrent(mpWindow);
|
||||
if(glewInit() != GLEW_OK) {
|
||||
error_callback_s(GLFW_NO_ERROR, "glewInit() failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
App::~App() {
|
||||
glfwTerminate();
|
||||
glfwSetErrorCallback(NULL);
|
||||
}
|
||||
|
||||
|
||||
void App::game_loop() {
|
||||
while(!glfwWindowShouldClose(mpWindow)) {
|
||||
glfwPollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void App::key_callback(int key, int scancode, int action, int mods) {
|
||||
if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(mpWindow, GLFW_TRUE);
|
||||
}
|
||||
}
|
||||
23
source/app/src/App.hpp
Normal file
23
source/app/src/App.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct GLFWwindow;
|
||||
|
||||
class App {
|
||||
public:
|
||||
static int main(std::vector<std::string> &args);
|
||||
private:
|
||||
static void error_callback_s(int error, const char *description);
|
||||
static void key_callback_s(GLFWwindow *window, int key, int scancode, int action, int mods);
|
||||
|
||||
private:
|
||||
GLFWwindow *mpWindow;
|
||||
|
||||
private:
|
||||
App();
|
||||
~App();
|
||||
void game_loop();
|
||||
void key_callback(int key, int scancode, int action, int mods);
|
||||
};
|
||||
Reference in New Issue
Block a user