Compare commits
No commits in common. "window" and "master" have entirely different histories.
|
@ -4,15 +4,10 @@
|
||||||
cmake_minimum_required (VERSION 3.8)
|
cmake_minimum_required (VERSION 3.8)
|
||||||
|
|
||||||
# Add source to this project's executable.
|
# Add source to this project's executable.
|
||||||
add_library (GLFramework "alibi.cpp" "window.cpp")
|
add_library (GLFramework "alibi.cpp")
|
||||||
|
|
||||||
file(GLOB vendor_SRC
|
|
||||||
"${CMAKE_SOURCE_DIR}/vendor/src/*.cpp"
|
|
||||||
"${CMAKE_SOURCE_DIR}/vendor/src/*.c"
|
|
||||||
)
|
|
||||||
|
|
||||||
target_sources(GLFramework PRIVATE
|
target_sources(GLFramework PRIVATE
|
||||||
${vendor_SRC}
|
${CMAKE_SOURCE_DIR}/vendor/src
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(GLFramework PRIVATE
|
target_include_directories(GLFramework PRIVATE
|
||||||
|
|
|
@ -1,24 +1,2 @@
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#ifndef glfInit
|
|
||||||
|
|
||||||
void _glfInit()
|
|
||||||
{
|
|
||||||
// Initialize GLFW
|
|
||||||
int result = glfwInit();
|
|
||||||
if (result == GLFW_FALSE)
|
|
||||||
throw std::exception("Failed to initialize GLFW");
|
|
||||||
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
|
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define glfInit _glfInit
|
|
||||||
|
|
||||||
#endif // glfInit
|
|
||||||
|
|
||||||
#include "window.hpp"
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <glad/glad.h>
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
|
|
||||||
namespace glf
|
|
||||||
{
|
|
||||||
#define USER_CALLBACK virtual void
|
|
||||||
#define LIB_CALLBACK static void
|
|
||||||
|
|
||||||
class IWindow
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void Create(int width, int height, const char* title, bool fullscreen = false, GLFWwindow* share = nullptr);
|
|
||||||
void Close() noexcept;
|
|
||||||
|
|
||||||
int ShouldClose();
|
|
||||||
|
|
||||||
void Display();
|
|
||||||
void PollEvents(); // TODO: needed?
|
|
||||||
|
|
||||||
protected:
|
|
||||||
IWindow();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
GLFWwindow* window;
|
|
||||||
|
|
||||||
GLFWmonitor* monitor;
|
|
||||||
GLFWwindow* share;
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
#include "window.hpp"
|
|
||||||
|
|
||||||
#include <exception>
|
|
||||||
|
|
||||||
namespace glf
|
|
||||||
{
|
|
||||||
IWindow::IWindow() :
|
|
||||||
window(nullptr), monitor(nullptr), share(nullptr)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void IWindow::Create(int width, int height, const char* title, bool fullscreen /*= false*/, GLFWwindow* share /*= nullptr*/)
|
|
||||||
{
|
|
||||||
// Create window
|
|
||||||
if (window == nullptr)
|
|
||||||
{
|
|
||||||
if (fullscreen)
|
|
||||||
true; // TODO: Implement monitor stuff
|
|
||||||
|
|
||||||
this->share = share;
|
|
||||||
window = glfwCreateWindow(width, height, title, monitor, share);
|
|
||||||
if (window == nullptr)
|
|
||||||
{
|
|
||||||
throw std::exception("Failed to create GLFWwindow");
|
|
||||||
}
|
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
|
|
||||||
// Initialize GLAD
|
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
|
||||||
throw std::exception("Failed to initialize GLAD");
|
|
||||||
|
|
||||||
// Set viewport
|
|
||||||
glViewport(0, 0, width, height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IWindow::Close() noexcept
|
|
||||||
{
|
|
||||||
glfwDestroyWindow(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
int IWindow::ShouldClose()
|
|
||||||
{
|
|
||||||
return glfwWindowShouldClose(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IWindow::Display()
|
|
||||||
{
|
|
||||||
glfwSwapBuffers(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IWindow::PollEvents()
|
|
||||||
{
|
|
||||||
glfwPollEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
add_executable(example
|
add_executable(example
|
||||||
"main.cpp"
|
"main.cpp"
|
||||||
"MyWindow.hpp")
|
)
|
||||||
|
|
||||||
target_include_directories(example PRIVATE
|
target_include_directories(example PRIVATE
|
||||||
${CMAKE_SOURCE_DIR}/GLFramework/include
|
${CMAKE_SOURCE_DIR}/GLFramework/include
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
#include "glf.hpp"
|
|
||||||
|
|
||||||
using namespace glf;
|
|
||||||
|
|
||||||
class MyWindow :
|
|
||||||
public IWindow
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MyWindow() :
|
|
||||||
IWindow()
|
|
||||||
{
|
|
||||||
Create(800, 600, "Example Window");
|
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(window, FramebufferSizeCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void FramebufferSizeCallback(GLFWwindow* window, int width, int height)
|
|
||||||
{
|
|
||||||
glViewport(0, 0, width, height);
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,27 +1,8 @@
|
||||||
#include "glf.hpp"
|
#include "glf.hpp"
|
||||||
#include "MyWindow.hpp"
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
MyWindow* window = nullptr;
|
glfwInit();
|
||||||
try {
|
|
||||||
glfInit();
|
|
||||||
window = new MyWindow;
|
|
||||||
}
|
|
||||||
catch (std::exception e)
|
|
||||||
{
|
|
||||||
std::cout << e.what() << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!window->ShouldClose())
|
|
||||||
{
|
|
||||||
glfwPollEvents();
|
|
||||||
window->Display();
|
|
||||||
}
|
|
||||||
|
|
||||||
window->Close();
|
|
||||||
glfwTerminate();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in a new issue