mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-23 02:38:52 -05:00
Updated some tests to new API.
This commit is contained in:
parent
b0ce8006e3
commit
b54334a451
|
@ -38,6 +38,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static GLFWwindow window_handle = NULL;
|
||||||
static GLboolean closed = GL_FALSE;
|
static GLboolean closed = GL_FALSE;
|
||||||
|
|
||||||
static const char* get_mode_name(int mode)
|
static const char* get_mode_name(int mode)
|
||||||
|
@ -53,19 +54,19 @@ static const char* get_mode_name(int mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_size_callback(int width, int height)
|
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
{
|
{
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int window_close_callback(void)
|
static int window_close_callback(GLFWwindow window)
|
||||||
{
|
{
|
||||||
printf("Close callback triggered\n");
|
printf("Close callback triggered\n");
|
||||||
closed = GL_TRUE;
|
window_handle = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_callback(int key, int action)
|
static void key_callback(GLFWwindow window, int key, int action)
|
||||||
{
|
{
|
||||||
if (action != GLFW_PRESS)
|
if (action != GLFW_PRESS)
|
||||||
return;
|
return;
|
||||||
|
@ -83,16 +84,17 @@ static int open_window(int width, int height, int mode)
|
||||||
{
|
{
|
||||||
double base = glfwGetTime();
|
double base = glfwGetTime();
|
||||||
|
|
||||||
if (!glfwOpenWindow(width, height, 0, 0, 0, 0, 16, 0, mode))
|
window_handle = glfwOpenWindow(width, height, 0, 0, 0, 0, 16, 0, mode);
|
||||||
|
if (!window_handle)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to create %s mode GLFW window\n", get_mode_name(mode));
|
fprintf(stderr, "Failed to create %s mode GLFW window\n", get_mode_name(mode));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowTitle("Window Re-opener");
|
glfwSetWindowTitle(window_handle, "Window Re-opener");
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_handle, window_size_callback);
|
||||||
glfwSetWindowCloseCallback(window_close_callback);
|
glfwSetWindowCloseCallback(window_handle, window_close_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(window_handle, key_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
printf("Opening %s mode window took %0.3f seconds\n",
|
printf("Opening %s mode window took %0.3f seconds\n",
|
||||||
|
@ -106,7 +108,8 @@ static void close_window(void)
|
||||||
{
|
{
|
||||||
double base = glfwGetTime();
|
double base = glfwGetTime();
|
||||||
|
|
||||||
glfwCloseWindow();
|
glfwCloseWindow(window_handle);
|
||||||
|
window_handle = NULL;
|
||||||
|
|
||||||
printf("Closing window took %0.3f seconds\n", glfwGetTime() - base);
|
printf("Closing window took %0.3f seconds\n", glfwGetTime() - base);
|
||||||
}
|
}
|
||||||
|
@ -152,7 +155,7 @@ int main(int argc, char** argv)
|
||||||
if (closed)
|
if (closed)
|
||||||
close_window();
|
close_window();
|
||||||
|
|
||||||
if (!glfwGetWindowParam(GLFW_OPENED))
|
if (!glfwIsWindow(window_handle))
|
||||||
{
|
{
|
||||||
printf("User closed window\n");
|
printf("User closed window\n");
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
static void window_size_callback(int width, int height)
|
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
{
|
{
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ static void window_size_callback(int width, int height)
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
float position;
|
float position;
|
||||||
|
GLFWwindow window;
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
|
@ -49,7 +50,8 @@ int main(void)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
|
window = glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
|
||||||
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
|
@ -57,8 +59,8 @@ int main(void)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowTitle("Tearing Detector");
|
glfwSetWindowTitle(window, "Tearing Detector");
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
|
@ -68,7 +70,7 @@ int main(void)
|
||||||
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
|
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
while (glfwGetWindowParam(GLFW_OPENED) == GL_TRUE)
|
while (glfwIsWindow(window) == GL_TRUE)
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
@ -76,6 +78,7 @@ int main(void)
|
||||||
glRectf(position - 0.25f, -1.f, position + 0.25f, 1.f);
|
glRectf(position - 0.25f, -1.f, position + 0.25f, 1.f);
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers();
|
||||||
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user