From 419f9f17a1e735593ad6235d27d021cb2cdaa1a5 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Mon, 4 Oct 2010 23:13:33 +0200
Subject: [PATCH] Added glfwGetCurrentWindow.
---
include/GL/glfw3.h | 1 +
readme.html | 1 +
src/window.c | 16 ++++++++++++++++
tests/sharing.c | 5 +++++
4 files changed, 23 insertions(+)
diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h
index c4a6ea45..cc1f01b0 100644
--- a/include/GL/glfw3.h
+++ b/include/GL/glfw3.h
@@ -417,6 +417,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode, const char* t
GLFWAPI void glfwOpenWindowHint(int target, int hint);
GLFWAPI void glfwMakeWindowCurrent(GLFWwindow window);
GLFWAPI int glfwIsWindow(GLFWwindow window);
+GLFWAPI GLFWwindow glfwGetCurrentWindow(void);
GLFWAPI void glfwCloseWindow(GLFWwindow window);
GLFWAPI void glfwSetWindowTitle(GLFWwindow, const char* title);
GLFWAPI void glfwGetWindowSize(GLFWwindow, int* width, int* height);
diff --git a/readme.html b/readme.html
index fb08e385..a11b614d 100644
--- a/readme.html
+++ b/readme.html
@@ -270,6 +270,7 @@ version of GLFW.
Added glfwGetWindowPos
function for querying the position of the specified window
Added glfwSetWindowFocusCallback
function and GLFWwindowfocusfun
type for receiving window focus events
Added glfwSetWindowIconifyCallback
function and GLFWwindowiconifyfun
type for receiving window iconification events
+ Added glfwGetCurrentWindow
function for retrieving the window whose OpenGL context is current
Added windows
simple multi-window test program
Added sharing
simple OpenGL object sharing test program
Added a parameter to glfwOpenWindow
for specifying a context the new window's context will share objects with
diff --git a/src/window.c b/src/window.c
index 0129fad8..4843d242 100644
--- a/src/window.c
+++ b/src/window.c
@@ -639,6 +639,22 @@ GLFWAPI int glfwIsWindow(GLFWwindow window)
}
+//========================================================================
+// Returns GL_TRUE if the specified window handle is an actual window
+//========================================================================
+
+GLFWAPI GLFWwindow glfwGetCurrentWindow(void)
+{
+ if (!_glfwInitialized)
+ {
+ _glfwSetError(GLFW_NOT_INITIALIZED);
+ return GL_FALSE;
+ }
+
+ return _glfwLibrary.currentWindow;
+}
+
+
//========================================================================
// Set hints for opening the window
//========================================================================
diff --git a/tests/sharing.c b/tests/sharing.c
index 0c6f5988..d2f47dbe 100644
--- a/tests/sharing.c
+++ b/tests/sharing.c
@@ -72,6 +72,11 @@ static GLuint create_texture(void)
static void draw_quad(GLuint texture)
{
+ int width, height;
+ glfwGetWindowSize(glfwGetCurrentWindow(), &width, &height);
+
+ glViewport(0, 0, width, height);
+
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.f, 1.f, 0.f, 1.f);