basic glfw app setup
This commit is contained in:
commit
eed4eec20c
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
.vs/
|
||||
[Oo]ut/
|
||||
[Bb]uild/
|
||||
|
||||
*.json
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "vendor/glfw"]
|
||||
path = vendor/glfw
|
||||
url = git@github.com:glfw/glfw.git
|
18
CMakeLists.txt
Normal file
18
CMakeLists.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
# CMakeList.txt : Top-level CMake project file, do global configuration
|
||||
# and include sub-projects here.
|
||||
#
|
||||
cmake_minimum_required (VERSION 3.8)
|
||||
|
||||
project ("Visualizer")
|
||||
|
||||
find_package(glfw3)
|
||||
if(NOT GLFW3_FOUND)
|
||||
message(STATUS "Could not find GLFW binaries on system, building from source instead")
|
||||
add_subdirectory("vendor/glfw")
|
||||
|
||||
set(GLFW3_INCLUDE_DIRS glfw)
|
||||
set(GLFW3_LIBRARIES glfw)
|
||||
endif()
|
||||
|
||||
# Include sub-projects.
|
||||
add_subdirectory ("src")
|
47
src/Application.cpp
Normal file
47
src/Application.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "Application.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
if (window != nullptr)
|
||||
{
|
||||
glfwDestroyWindow(window);
|
||||
window = nullptr;
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
void Application::Init(int width, int height, const std::string& title)
|
||||
{
|
||||
if(window == nullptr)
|
||||
glfwInit();
|
||||
|
||||
window = glfwCreateWindow(width, height, title.c_str(), NULL, NULL);
|
||||
if (window == nullptr)
|
||||
{
|
||||
const char* errorbuf;
|
||||
int errorcode = glfwGetError(&errorbuf);
|
||||
|
||||
glfwTerminate();
|
||||
|
||||
std::stringstream errorstream;
|
||||
errorstream << "Failed to create GLFWwindow (" << errorcode << "): \n" << errorbuf << std::endl;
|
||||
throw std::runtime_error(errorstream.str());
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
}
|
||||
|
||||
void Application::Launch()
|
||||
{
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
glfwPollEvents();
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
}
|
35
src/Application.hpp
Normal file
35
src/Application.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
struct GLFWwindow;
|
||||
|
||||
class Application
|
||||
{
|
||||
/////////////////////////////////////////////////////////
|
||||
////// SINGLETON BOILERPLATE ////////////////////////////
|
||||
/////////////////////////////////////////////////////////
|
||||
public:
|
||||
static Application& Instance()
|
||||
{
|
||||
static Application app;
|
||||
return app;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Application() = default;
|
||||
~Application();
|
||||
Application(const Application& other) = delete;
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
////// APPLICATION IMPLEMENTATION ///////////////////////
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
public:
|
||||
void Init(int width, int height, const std::string& title);
|
||||
void Launch();
|
||||
|
||||
private:
|
||||
GLFWwindow* window = nullptr;
|
||||
};
|
7
src/CMakeLists.txt
Normal file
7
src/CMakeLists.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
add_executable(visualizer
|
||||
"main.cpp" "Application.cpp"
|
||||
)
|
||||
|
||||
target_include_directories(visualizer PUBLIC ${GLFW3_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(visualizer PUBLIC ${GLFW3_INCLUDE_DIRS})
|
21
src/main.cpp
Normal file
21
src/main.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <iostream>
|
||||
#include "Application.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Application& app = Application::Instance();
|
||||
|
||||
try
|
||||
{
|
||||
app.Init(800, 800, "Visualizer");
|
||||
}
|
||||
catch (const std::runtime_error& err)
|
||||
{
|
||||
std::cerr << "Application initialization failed\n\n" << err.what();
|
||||
return 1;
|
||||
}
|
||||
|
||||
app.Launch();
|
||||
|
||||
return 0;
|
||||
}
|
1
vendor/glfw
vendored
Submodule
1
vendor/glfw
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 6281f498c875f49d8ac5c5a02d968fb1792fd9f5
|
Loading…
Reference in a new issue