Initial bootstrap developed on mbp 2015
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
set(HEADERS
|
||||
${HEADERS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/peripherals.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/peripherals_glfw.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
set(SOURCE
|
||||
${SOURCE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/peripherals_glfw.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define BEGIN_NAMESPACE namespace acidrain {
|
||||
#define END_NAMESPACE };
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "defines.h"
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
class peripherals {
|
||||
public:
|
||||
virtual bool init() = 0;
|
||||
virtual void swap_buffers() = 0;
|
||||
virtual void poll_events() = 0;
|
||||
virtual bool should_close() = 0;
|
||||
};
|
||||
|
||||
END_NAMESPACE
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "peripherals_glfw.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
static void error_callback(int error, const char* description) {
|
||||
std::cerr << "GLFW error callback. Error: " << error << ", " << description << std::endl;
|
||||
}
|
||||
|
||||
static void window_size_callback(GLFWwindow* window, int width, int height) {
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
}
|
||||
}
|
||||
|
||||
bool peripherals_glfw::init() {
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
window = glfwCreateWindow(800, 600, "Demo", nullptr, nullptr);
|
||||
if (window == nullptr) {
|
||||
std::cerr << "Unable to create window!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
if (window == nullptr) {
|
||||
std::cerr << "Unable to create window2!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||
|
||||
if (!gladLoadGL()) {
|
||||
std::cerr << "Unable to load OpenGL functions!" << std::endl;
|
||||
return false;
|
||||
} else {
|
||||
std::cout << "Successfully created window and loaded GL" << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void peripherals_glfw::swap_buffers() {
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
void peripherals_glfw::poll_events() {
|
||||
glfwPollEvents();
|
||||
};
|
||||
|
||||
bool peripherals_glfw::should_close() {
|
||||
return glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
END_NAMESPACE
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "peripherals.h"
|
||||
#include <glad/glad.h>
|
||||
|
||||
// forward declares
|
||||
class GLFWwindow;
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
class peripherals_glfw : public peripherals {
|
||||
public:
|
||||
|
||||
bool init() override;
|
||||
void swap_buffers() override;
|
||||
void poll_events() override;
|
||||
bool should_close() override;
|
||||
|
||||
::GLFWwindow *window;
|
||||
};
|
||||
|
||||
END_NAMESPACE
|
||||
Reference in New Issue
Block a user