void-packages/srcpkgs/cegui/patches/fix_glfw3.patch
jbu 03ffac780e cegui: build with glfw 3.x
This makes the package build the example, which unfortunately
does not yet work for me. Debugging and bug hunting required.
2015-08-07 03:53:32 +02:00

382 lines
17 KiB
Diff

diff -ru a/cmake/FindGLFW.cmake b/cmake/FindGLFW.cmake
--- cmake/FindGLFW.cmake 2013-04-29 10:26:36.000000000 +0200
+++ cmake/FindGLFW.cmake 2015-08-07 03:00:59.635191268 +0200
@@ -3,7 +3,7 @@
################################################################################
include(FindPackageHandleStandardArgs)
-find_path(GLFW_H_PATH NAMES GL/glfw.h glfw.h)
+find_path(GLFW_H_PATH NAMES GLFW/glfw3.h)
find_library(GLFW_LIB NAMES glfw PATH_SUFFIXES dynamic)
find_library(GLFW_LIB_DBG NAMES glfw_d PATH_SUFFIXES dynamic)
mark_as_advanced(GLFW_H_PATH GLFW_LIB GLFW_LIB_DBG)
diff -ru a/samples_framework/include/CEGuiGLFWSharedBase.h b/samples_framework/include/CEGuiGLFWSharedBase.h
--- samples_framework/include/CEGuiGLFWSharedBase.h 2014-07-07 09:06:18.000000000 +0200
+++ samples_framework/include/CEGuiGLFWSharedBase.h 2015-08-07 02:53:29.225235807 +0200
@@ -29,7 +29,7 @@
#include "CEGuiBaseApplication.h"
#include "CEGUI/MouseCursor.h"
-#include <GL/glfw.h>
+#include <GLFW/glfw3.h>
class SamplesFrameworkBase;
@@ -55,14 +55,14 @@
void drawFrame();
- static void GLFWCALL glfwKeyCallback(int key, int action);
- static void GLFWCALL glfwCharCallback(int character, int action);
- static void GLFWCALL glfwMouseButtonCallback(int key, int action);
- static void GLFWCALL glfwMouseWheelCallback(int position);
- static void GLFWCALL glfwMousePosCallback(int x, int y );
+ static void glfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
+ static void glfwCharCallback(GLFWwindow* window, unsigned int character);
+ static void glfwMouseButtonCallback(GLFWwindow* window, int key, int action, int mods);
+ static void glfwScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
+ static void glfwCursorPosCallback(GLFWwindow* window, double x, double y);
- static int GLFWCALL glfwWindowCloseCallback(void);
- static void GLFWCALL glfwWindowResizeCallback(int width, int height);
+ static void glfwWindowCloseCallback(GLFWwindow* window);
+ static void glfwWindowResizeCallback(GLFWwindow* window, int width, int height);
static CEGUI::Key::Scan GlfwToCeguiKey(int glfwKey);
static CEGUI::MouseButton GlfwToCeguiMouseButton(int glfwButton);
@@ -71,6 +71,7 @@
Data fields
*************************************************************************/
static CEGuiGLFWSharedBase* d_appInstance;
+ static GLFWwindow* d_window;
static double d_frameTime;
static int d_modifiers;
@@ -80,8 +81,8 @@
static bool d_mouseLeftWindow;
static bool d_mouseDisableCalled;
- static int d_oldMousePosX;
- static int d_oldMousePosY;
+ static double d_oldMousePosX;
+ static double d_oldMousePosY;
};
diff -ru a/samples_framework/src/CEGuiGLFWSharedBase.cpp b/samples_framework/src/CEGuiGLFWSharedBase.cpp
--- samples_framework/src/CEGuiGLFWSharedBase.cpp 2014-07-07 09:06:18.000000000 +0200
+++ samples_framework/src/CEGuiGLFWSharedBase.cpp 2015-08-07 02:59:43.268198820 +0200
@@ -38,6 +38,7 @@
//----------------------------------------------------------------------------//
CEGuiGLFWSharedBase* CEGuiGLFWSharedBase::d_appInstance = 0;
+GLFWwindow* CEGuiGLFWSharedBase::d_window = 0;
double CEGuiGLFWSharedBase::d_frameTime = 0;
int CEGuiGLFWSharedBase::d_modifiers = 0;
bool CEGuiGLFWSharedBase::d_windowSized = false;
@@ -45,8 +46,8 @@
int CEGuiGLFWSharedBase::d_newWindowHeight = CEGuiGLFWSharedBase::s_defaultWindowWidth;
bool CEGuiGLFWSharedBase::d_mouseLeftWindow = false;
bool CEGuiGLFWSharedBase::d_mouseDisableCalled = false;
-int CEGuiGLFWSharedBase::d_oldMousePosX = 0;
-int CEGuiGLFWSharedBase::d_oldMousePosY = 0;
+double CEGuiGLFWSharedBase::d_oldMousePosX = 0;
+double CEGuiGLFWSharedBase::d_oldMousePosY = 0;
//----------------------------------------------------------------------------//
CEGuiGLFWSharedBase::CEGuiGLFWSharedBase()
@@ -69,23 +70,22 @@
d_sampleApp->initialise();
// Input callbacks of glfw for CEGUI
- glfwSetKeyCallback(glfwKeyCallback);
- glfwSetCharCallback(glfwCharCallback);
- glfwSetMouseButtonCallback(glfwMouseButtonCallback);
- glfwSetMouseWheelCallback(glfwMouseWheelCallback);
- glfwSetMousePosCallback(glfwMousePosCallback);
+ glfwSetKeyCallback(d_window, glfwKeyCallback);
+ glfwSetCharCallback(d_window, glfwCharCallback);
+ glfwSetMouseButtonCallback(d_window, glfwMouseButtonCallback);
+ glfwSetScrollCallback(d_window, glfwScrollCallback);
+ glfwSetCursorPosCallback(d_window, glfwCursorPosCallback);
//Window callbacks
- glfwSetWindowCloseCallback(glfwWindowCloseCallback);
- glfwSetWindowSizeCallback(glfwWindowResizeCallback);
+ glfwSetWindowCloseCallback(d_window, glfwWindowCloseCallback);
+ glfwSetWindowSizeCallback(d_window, glfwWindowResizeCallback);
d_windowSized = false; //The resize callback is being called immediately after setting it in this version of glfw
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// set starting time
d_frameTime = glfwGetTime();
- while (!d_sampleApp->isQuitting() &&
- glfwGetWindowParam(GLFW_OPENED))
+ while (!d_sampleApp->isQuitting())
{
if (d_windowSized)
{
@@ -116,7 +116,8 @@
//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::endRendering()
{
- glfwSwapBuffers();
+ glfwPollEvents();
+ glfwSwapBuffers(d_window);
}
//----------------------------------------------------------------------------//
@@ -131,14 +132,13 @@
}
//----------------------------------------------------------------------------//
-int CEGuiGLFWSharedBase::glfwWindowCloseCallback(void)
+void CEGuiGLFWSharedBase::glfwWindowCloseCallback(GLFWwindow* window)
{
d_sampleApp->setQuitting(true);
- return GL_TRUE;
}
//----------------------------------------------------------------------------//
-void CEGuiGLFWSharedBase::glfwWindowResizeCallback(int w, int h)
+void CEGuiGLFWSharedBase::glfwWindowResizeCallback(GLFWwindow* window, int w, int h)
{
// We cache this in order to minimise calls to notifyDisplaySizeChanged,
// which happens in the main loop whenever d_windowSized is set to true.
@@ -152,43 +152,43 @@
{
switch(glfwKey)
{
- case GLFW_KEY_ESC : return CEGUI::Key::Escape;
- case GLFW_KEY_F1 : return CEGUI::Key::F1;
- case GLFW_KEY_F2 : return CEGUI::Key::F2;
- case GLFW_KEY_F3 : return CEGUI::Key::F3;
- case GLFW_KEY_F4 : return CEGUI::Key::F4;
- case GLFW_KEY_F5 : return CEGUI::Key::F5;
- case GLFW_KEY_F6 : return CEGUI::Key::F6;
- case GLFW_KEY_F7 : return CEGUI::Key::F7;
- case GLFW_KEY_F8 : return CEGUI::Key::F8;
- case GLFW_KEY_F9 : return CEGUI::Key::F9;
- case GLFW_KEY_F10 : return CEGUI::Key::F10;
- case GLFW_KEY_F11 : return CEGUI::Key::F11;
- case GLFW_KEY_F12 : return CEGUI::Key::F12;
- case GLFW_KEY_F13 : return CEGUI::Key::F13;
- case GLFW_KEY_F14 : return CEGUI::Key::F14;
- case GLFW_KEY_F15 : return CEGUI::Key::F15;
- case GLFW_KEY_UP : return CEGUI::Key::ArrowUp;
- case GLFW_KEY_DOWN : return CEGUI::Key::ArrowDown;
- case GLFW_KEY_LEFT : return CEGUI::Key::ArrowLeft;
- case GLFW_KEY_RIGHT : return CEGUI::Key::ArrowRight;
- case GLFW_KEY_LSHIFT : return CEGUI::Key::LeftShift;
- case GLFW_KEY_RSHIFT : return CEGUI::Key::RightShift;
- case GLFW_KEY_LCTRL : return CEGUI::Key::LeftControl;
- case GLFW_KEY_RCTRL : return CEGUI::Key::RightControl;
- case GLFW_KEY_LALT : return CEGUI::Key::LeftAlt;
- case GLFW_KEY_RALT : return CEGUI::Key::RightAlt;
- case GLFW_KEY_TAB : return CEGUI::Key::Tab;
- case GLFW_KEY_ENTER : return CEGUI::Key::Return;
- case GLFW_KEY_BACKSPACE : return CEGUI::Key::Backspace;
- case GLFW_KEY_INSERT : return CEGUI::Key::Insert;
- case GLFW_KEY_DEL : return CEGUI::Key::Delete;
- case GLFW_KEY_PAGEUP : return CEGUI::Key::PageUp;
- case GLFW_KEY_PAGEDOWN : return CEGUI::Key::PageDown;
- case GLFW_KEY_HOME : return CEGUI::Key::Home;
- case GLFW_KEY_END : return CEGUI::Key::End;
- case GLFW_KEY_KP_ENTER : return CEGUI::Key::NumpadEnter;
- default : return CEGUI::Key::Unknown;
+ case GLFW_KEY_ESCAPE : return CEGUI::Key::Escape;
+ case GLFW_KEY_F1 : return CEGUI::Key::F1;
+ case GLFW_KEY_F2 : return CEGUI::Key::F2;
+ case GLFW_KEY_F3 : return CEGUI::Key::F3;
+ case GLFW_KEY_F4 : return CEGUI::Key::F4;
+ case GLFW_KEY_F5 : return CEGUI::Key::F5;
+ case GLFW_KEY_F6 : return CEGUI::Key::F6;
+ case GLFW_KEY_F7 : return CEGUI::Key::F7;
+ case GLFW_KEY_F8 : return CEGUI::Key::F8;
+ case GLFW_KEY_F9 : return CEGUI::Key::F9;
+ case GLFW_KEY_F10 : return CEGUI::Key::F10;
+ case GLFW_KEY_F11 : return CEGUI::Key::F11;
+ case GLFW_KEY_F12 : return CEGUI::Key::F12;
+ case GLFW_KEY_F13 : return CEGUI::Key::F13;
+ case GLFW_KEY_F14 : return CEGUI::Key::F14;
+ case GLFW_KEY_F15 : return CEGUI::Key::F15;
+ case GLFW_KEY_UP : return CEGUI::Key::ArrowUp;
+ case GLFW_KEY_DOWN : return CEGUI::Key::ArrowDown;
+ case GLFW_KEY_LEFT : return CEGUI::Key::ArrowLeft;
+ case GLFW_KEY_RIGHT : return CEGUI::Key::ArrowRight;
+ case GLFW_KEY_LEFT_SHIFT : return CEGUI::Key::LeftShift;
+ case GLFW_KEY_RIGHT_SHIFT : return CEGUI::Key::RightShift;
+ case GLFW_KEY_LEFT_CONTROL : return CEGUI::Key::LeftControl;
+ case GLFW_KEY_RIGHT_CONTROL: return CEGUI::Key::RightControl;
+ case GLFW_KEY_LEFT_ALT : return CEGUI::Key::LeftAlt;
+ case GLFW_KEY_RIGHT_ALT : return CEGUI::Key::RightAlt;
+ case GLFW_KEY_TAB : return CEGUI::Key::Tab;
+ case GLFW_KEY_ENTER : return CEGUI::Key::Return;
+ case GLFW_KEY_BACKSPACE : return CEGUI::Key::Backspace;
+ case GLFW_KEY_INSERT : return CEGUI::Key::Insert;
+ case GLFW_KEY_DELETE : return CEGUI::Key::Delete;
+ case GLFW_KEY_PAGE_UP : return CEGUI::Key::PageUp;
+ case GLFW_KEY_PAGE_DOWN : return CEGUI::Key::PageDown;
+ case GLFW_KEY_HOME : return CEGUI::Key::Home;
+ case GLFW_KEY_END : return CEGUI::Key::End;
+ case GLFW_KEY_KP_ENTER : return CEGUI::Key::NumpadEnter;
+ default : return CEGUI::Key::Unknown;
}
}
@@ -205,7 +205,7 @@
}
//----------------------------------------------------------------------------//
-void GLFWCALL CEGuiGLFWSharedBase::glfwKeyCallback(int key, int action)
+void CEGuiGLFWSharedBase::glfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
CEGUI::Key::Scan ceguiKey = GlfwToCeguiKey(key);
@@ -216,14 +216,13 @@
}
//----------------------------------------------------------------------------//
-void GLFWCALL CEGuiGLFWSharedBase::glfwCharCallback(int character, int action)
+void CEGuiGLFWSharedBase::glfwCharCallback(GLFWwindow* window, unsigned int character)
{
- if(action == GLFW_PRESS)
- d_sampleApp->injectChar(character);
+ d_sampleApp->injectChar(character);
}
//----------------------------------------------------------------------------//
-void GLFWCALL CEGuiGLFWSharedBase::glfwMouseButtonCallback(int key, int action)
+void CEGuiGLFWSharedBase::glfwMouseButtonCallback(GLFWwindow* window, int key, int action, int mods)
{
CEGUI::MouseButton ceguiMouseButton = GlfwToCeguiMouseButton(key);
@@ -234,28 +233,28 @@
}
//----------------------------------------------------------------------------//
-void GLFWCALL CEGuiGLFWSharedBase::glfwMouseWheelCallback(int position)
+void CEGuiGLFWSharedBase::glfwScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
{
- static int lastPosition = 0;
- d_sampleApp->injectMouseWheelChange(static_cast<float>(position - lastPosition));
- lastPosition = position;
+ static double lastPosition = 0;
+ d_sampleApp->injectMouseWheelChange(yoffset - lastPosition);
+ lastPosition = yoffset;
}
//----------------------------------------------------------------------------//
-void GLFWCALL CEGuiGLFWSharedBase::glfwMousePosCallback(int x, int y)
+void CEGuiGLFWSharedBase::glfwCursorPosCallback(GLFWwindow* window, double x, double y)
{
if (!d_mouseDisableCalled)
{
// if cursor didn't leave the window nothing changes
- d_sampleApp->injectMousePosition(static_cast<float>(x), static_cast<float>(y));
+ d_sampleApp->injectMousePosition(x, y);
}
else
{
// if the cursor left the window, we need to use the saved position
// because glfw beams the cursor to the middle of the window if
// the cursor is disabled
- d_sampleApp->injectMousePosition(static_cast<float>(d_oldMousePosX), static_cast<float>(d_oldMousePosY));
- glfwSetMousePos(d_oldMousePosX, d_oldMousePosY);
+ d_sampleApp->injectMousePosition(d_oldMousePosX, d_oldMousePosY);
+ glfwSetCursorPos(d_window, d_oldMousePosX, d_oldMousePosY);
d_mouseDisableCalled = false;
}
@@ -265,10 +264,10 @@
|| y > d_newWindowHeight)
{
// show cursor
- glfwEnable(GLFW_MOUSE_CURSOR);
+ glfwSetInputMode(d_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
// move the cursor to the position where it left the window
- glfwSetMousePos(x, y);
+ glfwSetCursorPos(d_window, x, y);
// "note down" that the cursor left the window
d_mouseLeftWindow = true;
@@ -278,7 +277,7 @@
if (d_mouseLeftWindow)
{
// get cursor position to restore afterwards
- glfwGetMousePos(&d_oldMousePosX, &d_oldMousePosY);
+ glfwGetCursorPos(d_window, &d_oldMousePosX, &d_oldMousePosY);
// we need to inject the previous cursor position because
// glfw moves the cursor to the centre of the render
@@ -287,7 +286,7 @@
d_mouseDisableCalled = true;
// disable cursor
- glfwDisable(GLFW_MOUSE_CURSOR);
+ glfwSetInputMode(d_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// "note down" that the cursor is back in the render window
d_mouseLeftWindow = false;
@@ -306,24 +305,26 @@
//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::createGLFWWindow()
{
- if (glfwOpenWindow(s_defaultWindowWidth, s_defaultWindowHeight, 0, 0, 0, 0, 24, 8, GLFW_WINDOW) != GL_TRUE)
+ d_window = glfwCreateWindow(s_defaultWindowWidth, s_defaultWindowHeight, "Title", glfwGetPrimaryMonitor(), NULL);
+ if (NULL == d_window)
{
CEGUI_THROW(CEGUI::RendererException("Failed to open GLFW window."));
glfwTerminate();
}
+ glfwMakeContextCurrent(d_window);
}
//----------------------------------------------------------------------------//
void CEGuiGLFWSharedBase::setGLFWAppConfiguration()
{
- glfwSetWindowTitle("Crazy Eddie's GUI Mk-2 - Sample Application");
+ glfwSetWindowTitle(d_window, "Crazy Eddie's GUI Mk-2 - Sample Application");
//Deactivate VSYNC
glfwSwapInterval(0);
// Disable the mouse position in Non_Debug mode
#ifndef DEBUG
- glfwDisable(GLFW_MOUSE_CURSOR);
+ glfwSetInputMode(d_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
#endif
// Clear Errors by GLFW, even if Setup is correct.
glGetError();
diff -ru a/samples_framework/src/CEGuiOpenGL3BaseApplication.cpp b/samples_framework/src/CEGuiOpenGL3BaseApplication.cpp
--- samples_framework/src/CEGuiOpenGL3BaseApplication.cpp 2014-07-07 09:06:18.000000000 +0200
+++ samples_framework/src/CEGuiOpenGL3BaseApplication.cpp 2015-08-07 01:08:14.443860247 +0200
@@ -55,9 +55,9 @@
//----------------------------------------------------------------------------//
void CEGuiOpenGL3BaseApplication::setGLFWWindowCreationHints()
{
- glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
- glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
- glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
+ glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
}
//----------------------------------------------------------------------------//
diff -ru a/samples_framework/src/CEGuiOpenGLBaseApplication.cpp b/samples_framework/src/CEGuiOpenGLBaseApplication.cpp
--- samples_framework/src/CEGuiOpenGLBaseApplication.cpp 2014-07-07 09:06:18.000000000 +0200
+++ samples_framework/src/CEGuiOpenGLBaseApplication.cpp 2015-08-07 02:03:40.098531388 +0200
@@ -55,8 +55,8 @@
//----------------------------------------------------------------------------//
void CEGuiOpenGLBaseApplication::setGLFWWindowCreationHints()
{
- glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 1);
- glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
}
//----------------------------------------------------------------------------//