Created
January 4, 2014 15:23
-
-
Save faithandbrave/8256388 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyWindow { // AppじゃなくMyWindowなのがポイント | |
GLFWWindow* raw_window_; | |
public: | |
MyWindow() | |
{ | |
raw_window_ = glfwCreateWindow(960, 640, | |
PREPRO_TO_STR(PRODUCT_NAME), nullptr, nullptr); | |
glfwSetWindowUserPointer(raw_window_, this); | |
glfwSetMouseButtonCallback(raw_window_, mouseButtonCallbackImpl); | |
} | |
private: | |
static void mouseButtonCallbackImpl(GLFWWindow* raw_window) | |
{ | |
MyWindow* window = | |
reinterpret_cast<MyWindow*>( | |
glfwGetWindowUserPointer(raw_window) | |
); | |
// 静的メンバ関数から非静的メンバ関数を呼び出す | |
window->mouseButtonCallback(); | |
} | |
void mouseButtonCallback() {} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GLFW 3.0で入った、User Pointerの用途。
ウィンドウのコールバック関数内で、GLFWWindow*のほかに、ユーザー定義のウィンドウクラスのインスタンスを使用するためにある。(C++のためのC API)
ウィンドウ固有のコールバック関数を登録するたびに、毎回thisを設定させるのがイヤだったのだろう。
GLFW 3.0でマルチウィンドウサポートが入ったので、そのためにウィンドウごとに値を持たせる仕組みが必要だったのだろう。