Initial (glfwCreateWindow broken)
This commit is contained in:
@@ -21,11 +21,11 @@ find_package(OpenGL)
|
||||
set (CMAKE_DEBUG_POSTFIX "_d")
|
||||
|
||||
if(WIN32)
|
||||
set(COMMON_LIBS sb7 optimized glfw3 debug glfw3_d ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES})
|
||||
set(COMMON_LIBS sb7 optimized glfw debug glfw3_d ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES})
|
||||
elseif (UNIX)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(GLFW REQUIRED glfw3)
|
||||
set(COMMON_LIBS sb7 glfw3 X11 Xrandr Xinerama Xi Xxf86vm Xcursor GL rt dl)
|
||||
set(COMMON_LIBS sb7 glfw X11 Xrandr Xinerama Xi Xxf86vm Xcursor GL rt dl)
|
||||
else()
|
||||
set(COMMON_LIBS sb7)
|
||||
endif()
|
||||
|
133
include/sb7.h
133
include/sb7.h
@@ -49,31 +49,31 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace sb7
|
||||
{
|
||||
|
||||
class application
|
||||
{
|
||||
class application {
|
||||
private:
|
||||
static void APIENTRY debug_callback(GLenum source,
|
||||
GLenum type,
|
||||
GLuint id,
|
||||
GLenum severity,
|
||||
GLsizei length,
|
||||
const GLchar* message,
|
||||
GLvoid* userParam);
|
||||
const GLchar *message,
|
||||
GLvoid *userParam);
|
||||
|
||||
public:
|
||||
application() {}
|
||||
|
||||
virtual ~application() {}
|
||||
virtual void run(sb7::application* the_app)
|
||||
{
|
||||
|
||||
virtual void run(sb7::application *the_app) {
|
||||
bool running = true;
|
||||
app = the_app;
|
||||
|
||||
if (!glfwInit())
|
||||
{
|
||||
if (!glfwInit()) {
|
||||
fprintf(stderr, "Failed to initialize GLFW\n");
|
||||
return;
|
||||
}
|
||||
@@ -83,14 +83,15 @@ public:
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, info.majorVersion);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, info.minorVersion);
|
||||
|
||||
|
||||
#ifndef _DEBUG
|
||||
if (info.flags.debug)
|
||||
#endif /* _DEBUG */
|
||||
{
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
|
||||
}
|
||||
if (info.flags.robust)
|
||||
{
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
|
||||
if (info.flags.robust) {
|
||||
glfwWindowHint(GLFW_CONTEXT_ROBUSTNESS, GLFW_LOSE_CONTEXT_ON_RESET);
|
||||
}
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
@@ -112,9 +113,9 @@ public:
|
||||
// }
|
||||
// else
|
||||
{
|
||||
window = glfwCreateWindow(info.windowWidth, info.windowHeight, info.title, info.flags.fullscreen ? glfwGetPrimaryMonitor() : NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
window = glfwCreateWindow(info.windowWidth, info.windowHeight, info.title,
|
||||
info.flags.fullscreen ? glfwGetPrimaryMonitor() : NULL, NULL);
|
||||
if (!window) {
|
||||
fprintf(stderr, "Failed to open window\n");
|
||||
return;
|
||||
}
|
||||
@@ -127,8 +128,8 @@ public:
|
||||
glfwSetMouseButtonCallback(window, glfw_onMouseButton);
|
||||
glfwSetCursorPosCallback(window, glfw_onMouseMove);
|
||||
glfwSetScrollCallback(window, glfw_onMouseWheel);
|
||||
if (!info.flags.cursor)
|
||||
{
|
||||
glfwSetErrorCallback(glfw_onError);
|
||||
if (!info.flags.cursor) {
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
}
|
||||
|
||||
@@ -142,24 +143,19 @@ public:
|
||||
fprintf(stderr, "RENDERER: %s\n", (char *)glGetString(GL_RENDERER));
|
||||
#endif
|
||||
|
||||
if (info.flags.debug)
|
||||
{
|
||||
if (gl3wIsSupported(4, 3))
|
||||
{
|
||||
glDebugMessageCallback((GLDEBUGPROC)debug_callback, this);
|
||||
if (info.flags.debug) {
|
||||
if (gl3wIsSupported(4, 3)) {
|
||||
glDebugMessageCallback((GLDEBUGPROC) debug_callback, this);
|
||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||
}
|
||||
else if (sb6IsExtensionSupported("GL_ARB_debug_output"))
|
||||
{
|
||||
glDebugMessageCallbackARB((GLDEBUGPROC)debug_callback, this);
|
||||
} else if (sb6IsExtensionSupported("GL_ARB_debug_output")) {
|
||||
glDebugMessageCallbackARB((GLDEBUGPROC) debug_callback, this);
|
||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
||||
}
|
||||
}
|
||||
|
||||
startup();
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
render(glfwGetTime());
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
@@ -175,8 +171,7 @@ public:
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
virtual void init()
|
||||
{
|
||||
virtual void init() {
|
||||
strcpy(info.title, "OpenGL SuperBible Example");
|
||||
info.windowWidth = 800;
|
||||
info.windowHeight = 600;
|
||||
@@ -195,49 +190,40 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void startup()
|
||||
{
|
||||
virtual void startup() {
|
||||
|
||||
}
|
||||
|
||||
virtual void render(double currentTime)
|
||||
{
|
||||
virtual void render(double currentTime) {
|
||||
|
||||
}
|
||||
|
||||
virtual void shutdown()
|
||||
{
|
||||
virtual void shutdown() {
|
||||
|
||||
}
|
||||
|
||||
void setWindowTitle(const char * title)
|
||||
{
|
||||
void setWindowTitle(const char *title) {
|
||||
glfwSetWindowTitle(window, title);
|
||||
}
|
||||
|
||||
virtual void onResize(int w, int h)
|
||||
{
|
||||
virtual void onResize(int w, int h) {
|
||||
info.windowWidth = w;
|
||||
info.windowHeight = h;
|
||||
}
|
||||
|
||||
virtual void onKey(int key, int action)
|
||||
{
|
||||
virtual void onKey(int key, int action) {
|
||||
|
||||
}
|
||||
|
||||
virtual void onMouseButton(int button, int action)
|
||||
{
|
||||
virtual void onMouseButton(int button, int action) {
|
||||
|
||||
}
|
||||
|
||||
virtual void onMouseMove(int x, int y)
|
||||
{
|
||||
virtual void onMouseMove(int x, int y) {
|
||||
|
||||
}
|
||||
|
||||
virtual void onMouseWheel(int pos)
|
||||
{
|
||||
virtual void onMouseWheel(int pos) {
|
||||
|
||||
}
|
||||
|
||||
@@ -246,16 +232,14 @@ public:
|
||||
GLuint id,
|
||||
GLenum severity,
|
||||
GLsizei length,
|
||||
const GLchar* message)
|
||||
{
|
||||
const GLchar *message) {
|
||||
#ifdef _WIN32
|
||||
OutputDebugStringA(message);
|
||||
OutputDebugStringA("\n");
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
void getMousePosition(int& x, int& y)
|
||||
{
|
||||
void getMousePosition(int &x, int &y) {
|
||||
double dx, dy;
|
||||
glfwGetCursorPos(window, &dx, &dy);
|
||||
|
||||
@@ -264,59 +248,56 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
struct APPINFO
|
||||
{
|
||||
struct APPINFO {
|
||||
char title[128];
|
||||
int windowWidth;
|
||||
int windowHeight;
|
||||
int majorVersion;
|
||||
int minorVersion;
|
||||
int samples;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned int fullscreen : 1;
|
||||
unsigned int vsync : 1;
|
||||
unsigned int cursor : 1;
|
||||
unsigned int stereo : 1;
|
||||
unsigned int debug : 1;
|
||||
unsigned int robust : 1;
|
||||
union {
|
||||
struct {
|
||||
unsigned int fullscreen: 1;
|
||||
unsigned int vsync: 1;
|
||||
unsigned int cursor: 1;
|
||||
unsigned int stereo: 1;
|
||||
unsigned int debug: 1;
|
||||
unsigned int robust: 1;
|
||||
};
|
||||
unsigned int all;
|
||||
unsigned int all;
|
||||
} flags;
|
||||
};
|
||||
|
||||
protected:
|
||||
APPINFO info;
|
||||
static sb7::application * app;
|
||||
GLFWwindow* window;
|
||||
APPINFO info;
|
||||
static sb7::application *app;
|
||||
GLFWwindow *window;
|
||||
|
||||
static void glfw_onResize(GLFWwindow* window, int w, int h)
|
||||
{
|
||||
static void glfw_onResize(GLFWwindow *window, int w, int h) {
|
||||
app->onResize(w, h);
|
||||
}
|
||||
|
||||
static void glfw_onKey(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
static void glfw_onKey(GLFWwindow *window, int key, int scancode, int action, int mods) {
|
||||
app->onKey(key, action);
|
||||
}
|
||||
|
||||
static void glfw_onMouseButton(GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
static void glfw_onMouseButton(GLFWwindow *window, int button, int action, int mods) {
|
||||
app->onMouseButton(button, action);
|
||||
}
|
||||
|
||||
static void glfw_onMouseMove(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
static void glfw_onMouseMove(GLFWwindow *window, double x, double y) {
|
||||
app->onMouseMove(static_cast<int>(x), static_cast<int>(y));
|
||||
}
|
||||
|
||||
static void glfw_onMouseWheel(GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
static void glfw_onMouseWheel(GLFWwindow *window, double xoffset, double yoffset) {
|
||||
app->onMouseWheel(static_cast<int>(yoffset));
|
||||
}
|
||||
|
||||
static void glfw_onError(int code, const char* data)
|
||||
{
|
||||
std::cout << data << std::endl;
|
||||
}
|
||||
|
||||
void setVsync(bool enable)
|
||||
{
|
||||
info.flags.vsync = enable ? 1 : 0;
|
||||
|
Reference in New Issue
Block a user