Merge branch 'master' into EGL

Conflicts:
	include/GL/glfw3.h
	src/opengl.c
	src/win32_opengl.c
	src/window.c
	src/x11_fullscreen.c
	src/x11_glx_opengl.c
	src/x11_platform.h
	src/x11_window.c
	tests/glfwinfo.c
This commit is contained in:
Camilla Berglund
2012-09-06 21:05:03 +02:00
76 changed files with 1473 additions and 3805 deletions

View File

@@ -12,16 +12,19 @@ include_directories(${GLFW_SOURCE_DIR}/include
${GLFW_SOURCE_DIR}/support
${OPENGL_INCLUDE_DIR})
add_executable(clipboard clipboard.c getopt.c)
set(GETOPT ${GLFW_SOURCE_DIR}/support/getopt.h
${GLFW_SOURCE_DIR}/support/getopt.c)
add_executable(clipboard clipboard.c ${GETOPT})
add_executable(defaults defaults.c)
add_executable(events events.c)
add_executable(fsaa fsaa.c getopt.c)
add_executable(fsaa fsaa.c ${GETOPT})
add_executable(fsfocus fsfocus.c)
add_executable(gamma gamma.c getopt.c)
add_executable(glfwinfo glfwinfo.c getopt.c)
add_executable(iconify iconify.c getopt.c)
add_executable(gamma gamma.c ${GETOPT})
add_executable(glfwinfo glfwinfo.c ${GETOPT})
add_executable(iconify iconify.c ${GETOPT})
add_executable(joysticks joysticks.c)
add_executable(modes modes.c getopt.c)
add_executable(modes modes.c ${GETOPT})
add_executable(peter peter.c)
add_executable(reopen reopen.c)

View File

@@ -37,6 +37,19 @@
static int cursor_x = 0, cursor_y = 0;
static int window_width = 640, window_height = 480;
static int swap_interval = 1;
static void set_swap_interval(GLFWwindow window, int interval)
{
char title[256];
swap_interval = interval;
glfwSwapInterval(swap_interval);
sprintf(title, "Cursor Inaccuracy Detector (interval %i)", swap_interval);
glfwSetWindowTitle(window, title);
}
static void window_size_callback(GLFWwindow window, int width, int height)
{
@@ -56,9 +69,16 @@ static void cursor_position_callback(GLFWwindow window, int x, int y)
cursor_y = y;
}
static void key_callback(GLFWwindow window, int key, int action)
{
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
set_swap_interval(window, 1 - swap_interval);
}
int main(void)
{
GLFWwindow window;
int width, height;
if (!glfwInit())
{
@@ -66,7 +86,11 @@ int main(void)
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(window_width, window_height, GLFW_WINDOWED, "Cursor Inaccuracy Detector", NULL);
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetKeyCallback(key_callback);
window = glfwCreateWindow(window_width, window_height, GLFW_WINDOWED, "", NULL);
if (!window)
{
glfwTerminate();
@@ -75,11 +99,14 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
glfwMakeContextCurrent(window);
while (glfwIsWindow(window))
glfwGetWindowSize(window, &width, &height);
window_size_callback(window, width, height);
set_swap_interval(window, swap_interval);
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
{
glClear(GL_COLOR_BUFFER_BIT);
@@ -90,7 +117,7 @@ int main(void)
glVertex2f((GLfloat) cursor_x, (GLfloat) window_height);
glEnd();
glfwSwapBuffers();
glfwSwapBuffers(window);
glfwPollEvents();
}

View File

@@ -53,7 +53,7 @@ static void key_callback(GLFWwindow window, int key, int action)
switch (key)
{
case GLFW_KEY_ESCAPE:
glfwCloseWindow(window);
glfwDestroyWindow(window);
break;
case GLFW_KEY_V:
@@ -117,7 +117,7 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Clipboard Test", NULL);
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Clipboard Test", NULL);
if (!window)
{
glfwTerminate();
@@ -126,7 +126,9 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(size_callback);
@@ -136,14 +138,14 @@ int main(int argc, char** argv)
glClearColor(0.5f, 0.5f, 0.5f, 0);
while (glfwIsWindow(window))
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.8f, 0.2f, 0.4f);
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
glfwSwapBuffers();
glfwSwapBuffers(window);
glfwWaitEvents();
}

View File

@@ -30,6 +30,7 @@
//========================================================================
#include <GL/glfw3.h>
#include <GL/glext.h>
#include <stdio.h>
#include <stdlib.h>
@@ -37,30 +38,38 @@
typedef struct
{
int param;
char* name;
} Param;
const char* ext;
const char* name;
} ParamGL;
static Param parameters[] =
typedef struct
{
int param;
const char* name;
} ParamGLFW;
static ParamGL gl_params[] =
{
{ GL_RED_BITS, NULL, "red bits" },
{ GL_GREEN_BITS, NULL, "green bits" },
{ GL_BLUE_BITS, NULL, "blue bits" },
{ GL_ALPHA_BITS, NULL, "alpha bits" },
{ GL_DEPTH_BITS, NULL, "depth bits" },
{ GL_STENCIL_BITS, NULL, "stencil bits" },
{ GL_STEREO, NULL, "stereo" },
{ GL_SAMPLES_ARB, "GL_ARB_multisample", "FSAA samples" },
{ 0, NULL, NULL }
};
static ParamGLFW glfw_params[] =
{
{ GLFW_RED_BITS, "red bits" },
{ GLFW_GREEN_BITS, "green bits" },
{ GLFW_BLUE_BITS, "blue bits" },
{ GLFW_ALPHA_BITS, "alpha bits" },
{ GLFW_DEPTH_BITS, "depth bits" },
{ GLFW_STENCIL_BITS, "stencil bits" },
{ GLFW_REFRESH_RATE, "refresh rate" },
{ GLFW_ACCUM_RED_BITS, "accum red bits" },
{ GLFW_ACCUM_GREEN_BITS, "accum green bits" },
{ GLFW_ACCUM_BLUE_BITS, "accum blue bits" },
{ GLFW_ACCUM_ALPHA_BITS, "accum alpha bits" },
{ GLFW_AUX_BUFFERS, "aux buffers" },
{ GLFW_STEREO, "stereo" },
{ GLFW_FSAA_SAMPLES, "FSAA samples" },
{ GLFW_OPENGL_VERSION_MAJOR, "OpenGL major" },
{ GLFW_OPENGL_VERSION_MINOR, "OpenGL minor" },
{ GLFW_OPENGL_FORWARD_COMPAT, "OpenGL forward compatible" },
{ GLFW_OPENGL_DEBUG_CONTEXT, "OpenGL debug context" },
{ GLFW_OPENGL_PROFILE, "OpenGL profile" },
{ 0, NULL }
};
int main(void)
@@ -74,7 +83,7 @@ int main(void)
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Defaults", NULL);
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Defaults", NULL);
if (!window)
{
glfwTerminate();
@@ -83,18 +92,34 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwGetWindowSize(window, &width, &height);
printf("window size: %ix%i\n", width, height);
for (i = 0; (size_t) i < sizeof(parameters) / sizeof(parameters[0]); i++)
for (i = 0; glfw_params[i].name; i++)
{
printf("%s: %i\n",
parameters[i].name,
glfwGetWindowParam(window, parameters[i].param));
glfw_params[i].name,
glfwGetWindowParam(window, glfw_params[i].param));
}
glfwCloseWindow(window);
for (i = 0; gl_params[i].name; i++)
{
GLint value = 0;
if (gl_params[i].ext)
{
if (!glfwExtensionSupported(gl_params[i].ext))
continue;
}
glGetIntegerv(gl_params[i].param, &value);
printf("%s: %i\n", gl_params[i].name, value);
}
glfwDestroyWindow(window);
window = NULL;
glfwTerminate();

View File

@@ -40,9 +40,12 @@
#include <ctype.h>
#include <locale.h>
// These must match the input mode defaults
static GLboolean keyrepeat = GL_FALSE;
static GLboolean systemkeys = GL_TRUE;
static GLboolean closeable = GL_TRUE;
// Event index
static unsigned int counter = 0;
static const char* get_key_name(int key)
@@ -231,6 +234,7 @@ static void window_size_callback(GLFWwindow window, int width, int height)
static int window_close_callback(GLFWwindow window)
{
printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime());
return closeable;
}
@@ -238,8 +242,11 @@ static void window_refresh_callback(GLFWwindow window)
{
printf("%08x at %0.3f: Window refresh\n", counter++, glfwGetTime());
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
if (glfwGetCurrentContext())
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
}
}
static void window_focus_callback(GLFWwindow window, int activated)
@@ -344,6 +351,7 @@ static void char_callback(GLFWwindow window, int character)
int main(void)
{
GLFWwindow window;
int width, height;
setlocale(LC_ALL, "");
@@ -367,7 +375,7 @@ int main(void)
glfwSetKeyCallback(key_callback);
glfwSetCharCallback(char_callback);
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Event Linter", NULL);
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Event Linter", NULL);
if (!window)
{
glfwTerminate();
@@ -378,14 +386,18 @@ int main(void)
printf("Window opened\n");
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwGetWindowSize(window, &width, &height);
printf("Window size should be %ix%i\n", width, height);
printf("Key repeat should be %s\n", keyrepeat ? "enabled" : "disabled");
printf("System keys should be %s\n", systemkeys ? "enabled" : "disabled");
printf("Main loop starting\n");
while (glfwIsWindow(window) == GL_TRUE)
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
glfwWaitEvents();
glfwTerminate();

View File

@@ -96,9 +96,9 @@ int main(int argc, char** argv)
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, samples);
glfwWindowHint(GLFW_FSAA_SAMPLES, samples);
window = glfwOpenWindow(800, 400, GLFW_WINDOWED, "Aliasing Detector", NULL);
window = glfwCreateWindow(800, 400, GLFW_WINDOWED, "Aliasing Detector", NULL);
if (!window)
{
glfwTerminate();
@@ -107,6 +107,9 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
if (!glfwExtensionSupported("GL_ARB_multisample"))
{
glfwTerminate();
@@ -115,9 +118,7 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
glfwSwapInterval(1);
samples = glfwGetWindowParam(window, GLFW_FSAA_SAMPLES);
glGetIntegerv(GL_SAMPLES_ARB, &samples);
if (samples)
printf("Context reports FSAA is available with %i samples\n", samples);
else
@@ -127,7 +128,7 @@ int main(int argc, char** argv)
gluOrtho2D(0.f, 1.f, 0.f, 0.5f);
glMatrixMode(GL_MODELVIEW);
while (glfwIsWindow(window))
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
{
GLfloat time = (GLfloat) glfwGetTime();
@@ -147,7 +148,7 @@ int main(int argc, char** argv)
glEnable(GL_MULTISAMPLE_ARB);
glRectf(-0.15f, -0.15f, 0.15f, 0.15f);
glfwSwapBuffers();
glfwSwapBuffers(window);
glfwPollEvents();
}

View File

@@ -68,6 +68,7 @@ static void window_key_callback(GLFWwindow window, int key, int action)
static int window_close_callback(GLFWwindow window)
{
printf("%0.3f: User closed window\n", glfwGetTime());
running = GL_FALSE;
return GL_TRUE;
}
@@ -81,7 +82,7 @@ int main(void)
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(640, 480, GLFW_FULLSCREEN, "Fullscreen focus", NULL);
window = glfwCreateWindow(640, 480, GLFW_FULLSCREEN, "Fullscreen focus", NULL);
if (!window)
{
glfwTerminate();
@@ -90,17 +91,19 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
glfwSetWindowFocusCallback(window_focus_callback);
glfwSetKeyCallback(window_key_callback);
glfwSetWindowCloseCallback(window_close_callback);
while (running && glfwIsWindow(window) == GL_TRUE)
while (running)
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwSwapBuffers(window);
glfwWaitEvents();
}

View File

@@ -37,7 +37,7 @@
#define STEP_SIZE 0.1f
static GLfloat gamma = 1.0f;
static GLfloat gamma_value = 1.0f;
static void usage(void)
{
@@ -46,9 +46,9 @@ static void usage(void)
static void set_gamma(float value)
{
gamma = value;
printf("Gamma: %f\n", gamma);
glfwSetGamma(gamma);
gamma_value = value;
printf("Gamma: %f\n", gamma_value);
glfwSetGamma(gamma_value);
}
static void key_callback(GLFWwindow window, int key, int action)
@@ -60,22 +60,22 @@ static void key_callback(GLFWwindow window, int key, int action)
{
case GLFW_KEY_ESCAPE:
{
glfwCloseWindow(window);
glfwDestroyWindow(window);
break;
}
case GLFW_KEY_KP_ADD:
case GLFW_KEY_Q:
{
set_gamma(gamma + STEP_SIZE);
set_gamma(gamma_value + STEP_SIZE);
break;
}
case GLFW_KEY_KP_SUBTRACT:
case GLFW_KEY_W:
{
if (gamma - STEP_SIZE > 0.f)
set_gamma(gamma - STEP_SIZE);
if (gamma_value - STEP_SIZE > 0.f)
set_gamma(gamma_value - STEP_SIZE);
break;
}
@@ -119,10 +119,10 @@ int main(int argc, char** argv)
if (mode == GLFW_FULLSCREEN)
{
GLFWvidmode mode;
glfwGetDesktopMode(&mode);
width = mode.width;
height = mode.height;
GLFWvidmode desktop_mode;
glfwGetDesktopMode(&desktop_mode);
width = desktop_mode.width;
height = desktop_mode.height;
}
else
{
@@ -130,7 +130,7 @@ int main(int argc, char** argv)
height = 0;
}
window = glfwOpenWindow(width, height, mode, "Gamma Test", NULL);
window = glfwCreateWindow(width, height, mode, "Gamma Test", NULL);
if (!window)
{
glfwTerminate();
@@ -141,7 +141,9 @@ int main(int argc, char** argv)
set_gamma(1.f);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(size_callback);
@@ -151,14 +153,14 @@ int main(int argc, char** argv)
glClearColor(0.5f, 0.5f, 0.5f, 0);
while (glfwIsWindow(window))
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.8f, 0.2f, 0.4f);
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
glfwSwapBuffers();
glfwSwapBuffers(window);
glfwPollEvents();
}

View File

@@ -1,258 +0,0 @@
/*****************************************************************************
* getopt.c - competent and free getopt library.
* $Header: /cvsroot/freegetopt/freegetopt/getopt.c,v 1.2 2003/10/26 03:10:20 vindaci Exp $
*
* Copyright (c)2002-2003 Mark K. Kim
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the original author of this software nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "getopt.h"
/* 2011-07-27 Camilla Berglund <elmindreda@elmindreda.org>
*
* Added _CRT_SECURE_NO_WARNINGS macro.
*/
/* 2009-10-12 Camilla Berglund <elmindreda@elmindreda.org>
*
* Removed unused global static variable 'ID'.
*/
char* optarg = NULL;
int optind = 0;
int opterr = 1;
int optopt = '?';
static char** prev_argv = NULL; /* Keep a copy of argv and argc to */
static int prev_argc = 0; /* tell if getopt params change */
static int argv_index = 0; /* Option we're checking */
static int argv_index2 = 0; /* Option argument we're checking */
static int opt_offset = 0; /* Index into compounded "-option" */
static int dashdash = 0; /* True if "--" option reached */
static int nonopt = 0; /* How many nonopts we've found */
static void increment_index()
{
/* Move onto the next option */
if(argv_index < argv_index2)
{
while(prev_argv[++argv_index] && prev_argv[argv_index][0] != '-'
&& argv_index < argv_index2+1);
}
else argv_index++;
opt_offset = 1;
}
/*
* Permutes argv[] so that the argument currently being processed is moved
* to the end.
*/
static int permute_argv_once()
{
/* Movability check */
if(argv_index + nonopt >= prev_argc) return 1;
/* Move the current option to the end, bring the others to front */
else
{
char* tmp = prev_argv[argv_index];
/* Move the data */
memmove(&prev_argv[argv_index], &prev_argv[argv_index+1],
sizeof(char**) * (prev_argc - argv_index - 1));
prev_argv[prev_argc - 1] = tmp;
nonopt++;
return 0;
}
}
int getopt(int argc, char** argv, char* optstr)
{
int c = 0;
/* If we have new argv, reinitialize */
if(prev_argv != argv || prev_argc != argc)
{
/* Initialize variables */
prev_argv = argv;
prev_argc = argc;
argv_index = 1;
argv_index2 = 1;
opt_offset = 1;
dashdash = 0;
nonopt = 0;
}
/* Jump point in case we want to ignore the current argv_index */
getopt_top:
/* Misc. initializations */
optarg = NULL;
/* Dash-dash check */
if(argv[argv_index] && !strcmp(argv[argv_index], "--"))
{
dashdash = 1;
increment_index();
}
/* If we're at the end of argv, that's it. */
if(argv[argv_index] == NULL)
{
c = -1;
}
/* Are we looking at a string? Single dash is also a string */
else if(dashdash || argv[argv_index][0] != '-' || !strcmp(argv[argv_index], "-"))
{
/* If we want a string... */
if(optstr[0] == '-')
{
c = 1;
optarg = argv[argv_index];
increment_index();
}
/* If we really don't want it (we're in POSIX mode), we're done */
else if(optstr[0] == '+' || getenv("POSIXLY_CORRECT"))
{
c = -1;
/* Everything else is a non-opt argument */
nonopt = argc - argv_index;
}
/* If we mildly don't want it, then move it back */
else
{
if(!permute_argv_once()) goto getopt_top;
else c = -1;
}
}
/* Otherwise we're looking at an option */
else
{
char* opt_ptr = NULL;
/* Grab the option */
c = argv[argv_index][opt_offset++];
/* Is the option in the optstr? */
if(optstr[0] == '-') opt_ptr = strchr(optstr+1, c);
else opt_ptr = strchr(optstr, c);
/* Invalid argument */
if(!opt_ptr)
{
if(opterr)
{
fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
}
optopt = c;
c = '?';
/* Move onto the next option */
increment_index();
}
/* Option takes argument */
else if(opt_ptr[1] == ':')
{
/* ie, -oARGUMENT, -xxxoARGUMENT, etc. */
if(argv[argv_index][opt_offset] != '\0')
{
optarg = &argv[argv_index][opt_offset];
increment_index();
}
/* ie, -o ARGUMENT (only if it's a required argument) */
else if(opt_ptr[2] != ':')
{
/* One of those "you're not expected to understand this" moment */
if(argv_index2 < argv_index) argv_index2 = argv_index;
while(argv[++argv_index2] && argv[argv_index2][0] == '-');
optarg = argv[argv_index2];
/* Don't cross into the non-option argument list */
if(argv_index2 + nonopt >= prev_argc) optarg = NULL;
/* Move onto the next option */
increment_index();
}
else
{
/* Move onto the next option */
increment_index();
}
/* In case we got no argument for an option with required argument */
if(optarg == NULL && opt_ptr[2] != ':')
{
optopt = c;
c = '?';
if(opterr)
{
fprintf(stderr,"%s: option requires an argument -- %c\n",
argv[0], optopt);
}
}
}
/* Option does not take argument */
else
{
/* Next argv_index */
if(argv[argv_index][opt_offset] == '\0')
{
increment_index();
}
}
}
/* Calculate optind */
if(c == -1)
{
optind = argc - nonopt;
}
else
{
optind = argv_index;
}
return c;
}
/* vim:ts=3
*/

View File

@@ -1,63 +0,0 @@
/*****************************************************************************
* getopt.h - competent and free getopt library.
* $Header: /cvsroot/freegetopt/freegetopt/getopt.h,v 1.2 2003/10/26 03:10:20 vindaci Exp $
*
* Copyright (c)2002-2003 Mark K. Kim
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the original author of this software nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
#ifndef GETOPT_H_
#define GETOPT_H_
#ifdef __cplusplus
extern "C" {
#endif
extern char* optarg;
extern int optind;
extern int opterr;
extern int optopt;
int getopt(int argc, char** argv, char* optstr);
#ifdef __cplusplus
}
#endif
#endif /* GETOPT_H_ */
/* vim:ts=3
*/

View File

@@ -120,6 +120,32 @@ static void list_extensions(int api, int major, int minor)
putchar('\n');
}
static GLboolean valid_version(void)
{
int major, minor, revision;
glfwGetVersion(&major, &minor, &revision);
printf("GLFW header version: %u.%u.%u\n",
GLFW_VERSION_MAJOR,
GLFW_VERSION_MINOR,
GLFW_VERSION_REVISION);
printf("GLFW library version: %u.%u.%u\n", major, minor, revision);
if (major != GLFW_VERSION_MAJOR)
{
printf("*** ERROR: GLFW major version mismatch! ***\n");
return GL_FALSE;
}
if (minor != GLFW_VERSION_MINOR || revision != GLFW_VERSION_REVISION)
printf("*** WARNING: GLFW version mismatch! ***\n");
printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
return GL_TRUE;
}
int main(int argc, char** argv)
{
int ch, api = 0, profile = 0, strategy = 0, major = 1, minor = 0, revision;
@@ -127,6 +153,9 @@ int main(int argc, char** argv)
GLint flags, mask;
GLFWwindow window;
if (!valid_version())
exit(EXIT_FAILURE);
while ((ch = getopt(argc, argv, "a:dfhlm:n:p:r:")) != -1)
{
switch (ch)
@@ -190,6 +219,8 @@ int main(int argc, char** argv)
argc -= optind;
argv += optind;
// Initialize GLFW and create window
glfwSetErrorCallback(error_callback);
if (!glfwInit())
@@ -200,51 +231,33 @@ int main(int argc, char** argv)
if (major != 1 || minor != 0)
{
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, minor);
glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, minor);
}
if (api != 0)
glfwOpenWindowHint(GLFW_CLIENT_API, api);
glfwWindowHint(GLFW_CLIENT_API, api);
if (debug)
glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
if (forward)
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
if (profile != 0)
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, profile);
glfwWindowHint(GLFW_OPENGL_PROFILE, profile);
if (strategy)
glfwOpenWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy);
glfwWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy);
// We assume here that we stand a better chance of success by leaving all
// possible details of pixel format selection to GLFW
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Version", NULL);
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Version", NULL);
if (!window)
exit(EXIT_FAILURE);
// Report GLFW version
glfwGetVersion(&major, &minor, &revision);
printf("GLFW header version: %u.%u.%u\n",
GLFW_VERSION_MAJOR,
GLFW_VERSION_MINOR,
GLFW_VERSION_REVISION);
printf("GLFW library version: %u.%u.%u\n", major, minor, revision);
if (major != GLFW_VERSION_MAJOR ||
minor != GLFW_VERSION_MINOR ||
revision != GLFW_VERSION_REVISION)
{
printf("*** WARNING: GLFW version mismatch! ***\n");
}
printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
glfwMakeContextCurrent(window);
// Report client API version

View File

@@ -55,7 +55,7 @@ static void key_callback(GLFWwindow window, int key, int action)
glfwIconifyWindow(window);
break;
case GLFW_KEY_ESCAPE:
glfwCloseWindow(window);
glfwDestroyWindow(window);
break;
}
}
@@ -100,10 +100,10 @@ int main(int argc, char** argv)
if (mode == GLFW_FULLSCREEN)
{
GLFWvidmode mode;
glfwGetDesktopMode(&mode);
width = mode.width;
height = mode.height;
GLFWvidmode desktop_mode;
glfwGetDesktopMode(&desktop_mode);
width = desktop_mode.width;
height = desktop_mode.height;
}
else
{
@@ -111,7 +111,7 @@ int main(int argc, char** argv)
height = 0;
}
window = glfwOpenWindow(width, height, mode, "Iconify", NULL);
window = glfwCreateWindow(width, height, mode, "Iconify", NULL);
if (!window)
{
glfwTerminate();
@@ -120,16 +120,16 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(size_callback);
glEnable(GL_SCISSOR_TEST);
while (glfwIsWindow(window))
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
{
int width, height;
if (iconified != glfwGetWindowParam(window, GLFW_ICONIFIED) ||
active != glfwGetWindowParam(window, GLFW_ACTIVE))
{
@@ -152,7 +152,7 @@ int main(int argc, char** argv)
glClearColor(1, 1, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwSwapBuffers(window);
glfwPollEvents();
}

View File

@@ -44,7 +44,6 @@ typedef struct Joystick
} Joystick;
static Joystick joysticks[GLFW_JOYSTICK_LAST - GLFW_JOYSTICK_1 + 1];
static int joystick_count = 0;
static void window_size_callback(GLFWwindow window, int width, int height)
@@ -138,7 +137,7 @@ static void refresh_joysticks(void)
j->axes = realloc(j->axes, j->axis_count * sizeof(float));
}
glfwGetJoystickPos(GLFW_JOYSTICK_1 + i, j->axes, j->axis_count);
glfwGetJoystickAxes(GLFW_JOYSTICK_1 + i, j->axes, j->axis_count);
button_count = glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_BUTTONS);
if (button_count != j->button_count)
@@ -187,7 +186,7 @@ int main(void)
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Joystick Test", NULL);
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Joystick Test", NULL);
if (!window)
{
glfwTerminate();
@@ -197,16 +196,18 @@ int main(void)
}
glfwSetWindowSizeCallback(window_size_callback);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
while (glfwIsWindow(window))
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
{
glClear(GL_COLOR_BUFFER_BIT);
refresh_joysticks();
draw_joysticks();
glfwSwapBuffers();
glfwSwapBuffers(window);
glfwPollEvents();
}

View File

@@ -53,11 +53,11 @@ static const char* format_mode(GLFWvidmode* mode)
{
static char buffer[512];
snprintf(buffer, sizeof(buffer),
"%i x %i x %i (%i %i %i)",
mode->width, mode->height,
mode->redBits + mode->greenBits + mode->blueBits,
mode->redBits, mode->greenBits, mode->blueBits);
sprintf(buffer,
"%i x %i x %i (%i %i %i)",
mode->width, mode->height,
mode->redBits + mode->greenBits + mode->blueBits,
mode->redBits, mode->greenBits, mode->blueBits);
buffer[sizeof(buffer) - 1] = '\0';
return buffer;
@@ -68,7 +68,7 @@ static void error_callback(int error, const char* description)
fprintf(stderr, "Error: %s\n", description);
}
static void window_size_callback(GLFWwindow window, int width, int height)
static void window_size_callback(GLFWwindow in_window, int width, int height)
{
printf("Window resized to %ix%i\n", width, height);
@@ -85,34 +85,16 @@ static void key_callback(GLFWwindow dummy, int key, int action)
{
if (key == GLFW_KEY_ESCAPE)
{
glfwCloseWindow(window);
glfwDestroyWindow(window);
window = NULL;
}
}
static GLFWvidmode* get_video_modes(size_t* found)
{
size_t count = 0;
GLFWvidmode* modes = NULL;
for (;;)
{
count += 256;
modes = realloc(modes, sizeof(GLFWvidmode) * count);
*found = glfwGetVideoModes(modes, count);
if (*found < count)
break;
}
return modes;
}
static void list_modes(void)
{
size_t count, i;
int count, i;
GLFWvidmode desktop_mode;
GLFWvidmode* modes = get_video_modes(&count);
GLFWvidmode* modes = glfwGetVideoModes(&count);
glfwGetDesktopMode(&desktop_mode);
printf("Desktop mode: %s\n", format_mode(&desktop_mode));
@@ -128,15 +110,12 @@ static void list_modes(void)
putchar('\n');
}
free(modes);
}
static void test_modes(void)
{
int width, height;
size_t i, count;
GLFWvidmode* modes = get_video_modes(&count);
int i, count;
GLFWvidmode* modes = glfwGetVideoModes(&count);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
@@ -145,16 +124,17 @@ static void test_modes(void)
for (i = 0; i < count; i++)
{
GLFWvidmode* mode = modes + i;
GLFWvidmode current;
glfwOpenWindowHint(GLFW_RED_BITS, mode->redBits);
glfwOpenWindowHint(GLFW_GREEN_BITS, mode->greenBits);
glfwOpenWindowHint(GLFW_BLUE_BITS, mode->blueBits);
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
printf("Testing mode %u: %s", (unsigned int) i, format_mode(mode));
window = glfwOpenWindow(mode->width, mode->height,
GLFW_FULLSCREEN, "Video Mode Test",
NULL);
window = glfwCreateWindow(mode->width, mode->height,
GLFW_FULLSCREEN, "Video Mode Test",
NULL);
if (!window)
{
printf("Failed to enter mode %u: %s\n",
@@ -163,13 +143,15 @@ static void test_modes(void)
continue;
}
glfwSetTime(0.0);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetTime(0.0);
while (glfwGetTime() < 5.0)
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwSwapBuffers(window);
glfwPollEvents();
if (!window)
@@ -179,36 +161,34 @@ static void test_modes(void)
}
}
if (glfwGetWindowParam(window, GLFW_RED_BITS) != mode->redBits ||
glfwGetWindowParam(window, GLFW_GREEN_BITS) != mode->greenBits ||
glfwGetWindowParam(window, GLFW_BLUE_BITS) != mode->blueBits)
glGetIntegerv(GL_RED_BITS, &current.redBits);
glGetIntegerv(GL_GREEN_BITS, &current.greenBits);
glGetIntegerv(GL_BLUE_BITS, &current.blueBits);
glfwGetWindowSize(window, &current.width, &current.height);
if (current.redBits != mode->redBits ||
current.greenBits != mode->greenBits ||
current.blueBits != mode->blueBits)
{
printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n",
glfwGetWindowParam(window, GLFW_RED_BITS),
glfwGetWindowParam(window, GLFW_GREEN_BITS),
glfwGetWindowParam(window, GLFW_BLUE_BITS),
mode->redBits,
mode->greenBits,
mode->blueBits);
current.redBits, current.greenBits, current.blueBits,
mode->redBits, mode->greenBits, mode->blueBits);
}
glfwGetWindowSize(window, &width, &height);
if (width != mode->width || height != mode->height)
if (current.width != mode->width || current.height != mode->height)
{
printf("*** Size mismatch: %ix%i instead of %ix%i\n",
width, height,
current.width, current.height,
mode->width, mode->height);
}
printf("Closing window\n");
glfwCloseWindow(window);
glfwDestroyWindow(window);
glfwPollEvents();
window = NULL;
}
free(modes);
}
int main(int argc, char** argv)

View File

@@ -78,7 +78,7 @@ static void key_callback(GLFWwindow window, int key, int action)
{
if (action == GLFW_PRESS)
{
glfwCloseWindow(window);
glfwDestroyWindow(window);
open_window();
}
@@ -94,17 +94,19 @@ static void window_size_callback(GLFWwindow window, int width, int height)
static GLboolean open_window(void)
{
window_handle = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Peter Detector", NULL);
window_handle = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Peter Detector", NULL);
if (!window_handle)
return GL_FALSE;
glfwMakeContextCurrent(window_handle);
glfwSwapInterval(1);
glfwGetCursorPos(window_handle, &cursor_x, &cursor_y);
printf("Cursor position: %i %i\n", cursor_x, cursor_y);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetKeyCallback(key_callback);
glfwSwapInterval(1);
return GL_TRUE;
}
@@ -127,11 +129,11 @@ int main(void)
glClearColor(0.f, 0.f, 0.f, 0.f);
while (glfwIsWindow(window_handle))
while (!glfwGetWindowParam(window_handle, GLFW_CLOSE_REQUESTED))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwSwapBuffers(window_handle);
glfwWaitEvents();
}

View File

@@ -92,17 +92,19 @@ static GLboolean open_window(int width, int height, int mode)
base = glfwGetTime();
window_handle = glfwOpenWindow(width, height, mode, "Window Re-opener", NULL);
window_handle = glfwCreateWindow(width, height, mode, "Window Re-opener", NULL);
if (!window_handle)
{
fprintf(stderr, "Failed to open %s mode GLFW window: %s\n", get_mode_name(mode), glfwErrorString(glfwGetError()));
return GL_FALSE;
}
glfwMakeContextCurrent(window_handle);
glfwSwapInterval(1);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetKeyCallback(key_callback);
glfwSwapInterval(1);
printf("Opening %s mode window took %0.3f seconds\n",
get_mode_name(mode),
@@ -115,7 +117,7 @@ static void close_window(void)
{
double base = glfwGetTime();
glfwCloseWindow(window_handle);
glfwDestroyWindow(window_handle);
window_handle = NULL;
printf("Closing window took %0.3f seconds\n", glfwGetTime() - base);
@@ -147,7 +149,7 @@ int main(int argc, char** argv)
glRectf(-0.5f, -0.5f, 1.f, 1.f);
glPopMatrix();
glfwSwapBuffers();
glfwSwapBuffers(window_handle);
glfwPollEvents();
if (closed)

View File

@@ -36,23 +36,44 @@
#define WIDTH 400
#define HEIGHT 400
static GLFWwindow windows[2];
static void key_callback(GLFWwindow window, int key, int action)
{
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
glfwCloseWindow(window);
glfwDestroyWindow(window);
}
static int window_close_callback(GLFWwindow window)
{
int i;
for (i = 0; i < 2; i++)
{
if (windows[i] == window)
{
windows[i] = NULL;
break;
}
}
return GL_TRUE;
}
static GLFWwindow open_window(const char* title, GLFWwindow share)
{
GLFWwindow window;
window = glfwOpenWindow(WIDTH, HEIGHT, GLFW_WINDOWED, title, share);
window = glfwCreateWindow(WIDTH, HEIGHT, GLFW_WINDOWED, title, share);
if (!window)
return NULL;
glfwSetKeyCallback(key_callback);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetKeyCallback(key_callback);
return window;
}
@@ -112,7 +133,6 @@ static void draw_quad(GLuint texture)
int main(int argc, char** argv)
{
GLFWwindow windows[2];
GLuint texture;
int x, y;
@@ -150,15 +170,16 @@ int main(int argc, char** argv)
glfwGetWindowPos(windows[0], &x, &y);
glfwSetWindowPos(windows[1], x + WIDTH + 50, y);
while (glfwIsWindow(windows[0]) && glfwIsWindow(windows[1]))
while (windows[0] && windows[1])
{
glfwMakeContextCurrent(windows[0]);
draw_quad(texture);
glfwSwapBuffers();
glfwMakeContextCurrent(windows[1]);
draw_quad(texture);
glfwSwapBuffers();
glfwSwapBuffers(windows[0]);
glfwSwapBuffers(windows[1]);
glfwWaitEvents();
}

View File

@@ -36,15 +36,16 @@
static int swap_interval;
static void set_swap_interval(int value)
static void set_swap_interval(GLFWwindow window, int interval)
{
char title[256];
swap_interval = value;
swap_interval = interval;
glfwSwapInterval(swap_interval);
sprintf(title, "Tearing detector (interval %i)", swap_interval);
glfwSetWindowTitle(glfwGetCurrentContext(), title);
glfwSetWindowTitle(window, title);
}
static void window_size_callback(GLFWwindow window, int width, int height)
@@ -55,7 +56,7 @@ static void window_size_callback(GLFWwindow window, int width, int height)
static void key_callback(GLFWwindow window, int key, int action)
{
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
set_swap_interval(!swap_interval);
set_swap_interval(window, 1 - swap_interval);
}
int main(void)
@@ -69,7 +70,7 @@ int main(void)
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "", NULL);
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "", NULL);
if (!window)
{
glfwTerminate();
@@ -78,7 +79,8 @@ int main(void)
exit(EXIT_FAILURE);
}
set_swap_interval(1);
glfwMakeContextCurrent(window);
set_swap_interval(window, swap_interval);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetKeyCallback(key_callback);
@@ -87,14 +89,14 @@ int main(void)
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
glMatrixMode(GL_MODELVIEW);
while (glfwIsWindow(window) == GL_TRUE)
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
{
glClear(GL_COLOR_BUFFER_BIT);
position = cosf(glfwGetTime() * 4.f) * 0.75f;
glRectf(position - 0.25f, -1.f, position + 0.25f, 1.f);
glfwSwapBuffers();
glfwSwapBuffers(window);
glfwPollEvents();
}

View File

@@ -47,21 +47,22 @@ int main(void)
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "English 日本語 русский язык 官話", NULL);
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "English 日本語 русский язык 官話", NULL);
if (!window)
{
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetWindowSizeCallback(window_size_callback);
while (glfwIsWindow(window) == GL_TRUE)
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwSwapBuffers(window);
glfwWaitEvents();
}

View File

@@ -55,7 +55,7 @@ int main(void)
for (i = 0; i < 4; i++)
{
windows[i] = glfwOpenWindow(200, 200, GLFW_WINDOWED, titles[i], NULL);
windows[i] = glfwCreateWindow(200, 200, GLFW_WINDOWED, titles[i], NULL);
if (!windows[i])
{
fprintf(stderr, "Failed to open GLFW window: %s\n",
@@ -64,12 +64,13 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300);
glfwMakeContextCurrent(windows[i]);
glClearColor((GLclampf) (i & 1),
(GLclampf) (i >> 1),
i ? 0.0 : 1.0,
0.0);
i ? 0.f : 1.f,
0.f);
glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300);
}
while (running)
@@ -78,16 +79,13 @@ int main(void)
{
glfwMakeContextCurrent(windows[i]);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwSwapBuffers(windows[i]);
if (glfwGetWindowParam(windows[i], GLFW_CLOSE_REQUESTED))
running = GL_FALSE;
}
glfwPollEvents();
for (i = 0; i < 4; i++)
{
if (!glfwIsWindow(windows[i]))
running = GL_FALSE;
}
}
glfwTerminate();