Initial import of 2.7 Lite.

This commit is contained in:
Camilla Berglund
2010-09-07 17:34:51 +02:00
parent efef33c791
commit 3249f812d6
97 changed files with 25983 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
link_libraries(libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include ${OPENGL_INCLUDE_DIR})
add_executable(defaults defaults.c)
add_executable(events events.c)
add_executable(joysticks joysticks.c)
add_executable(peter peter.c)
add_executable(reopen reopen.c)
add_executable(version version.c)
if(APPLE)
# Set fancy names for bundles
add_executable(Accuracy MACOSX_BUNDLE accuracy.c)
add_executable(FSAA MACOSX_BUNDLE fsaa.c)
add_executable(Tearing MACOSX_BUNDLE tearing.c)
else()
# Set boring names for executables
add_executable(accuracy WIN32 accuracy.c)
add_executable(tearing WIN32 tearing.c)
add_executable(fsaa WIN32 fsaa.c)
endif(APPLE)
if(MSVC)
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
set_target_properties(accuracy defaults events fsaa peter reopen tearing version PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup")
endif(MSVC)
if(CYGWIN)
# Set cross-compile and subsystem compile and link flags
set_target_properties(accuracy defaults events fsaa joysticks peter reopen tearing version PROPERTIES COMPILE_FLAGS "-mno-cygwin")
set_target_properties(accuracy fsaa tearing PROPERTIES LINK_FLAGS "-mno-cygwin -mwindows")
set_target_properties(events defaults joysticks peter reopen version PROPERTIES LINK_FLAGS "-mno-cygwin -mconsole")
endif(CYGWIN)
+103
View File
@@ -0,0 +1,103 @@
//========================================================================
// Mouse cursor accuracy test
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This test came about as the result of bug #1867804
//
// No sign of said bug has so far been detected
//
//========================================================================
#include <GL/glfw.h>
#include <stdio.h>
#include <stdlib.h>
static int cursor_x = 0, cursor_y = 0;
static int window_width = 640, window_height = 480;
static void GLFWCALL window_size_callback(int width, int height)
{
window_width = width;
window_height = height;
glViewport(0, 0, window_width, window_height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.f, window_width, 0.f, window_height);
}
static void GLFWCALL mouse_position_callback(int x, int y)
{
cursor_x = x;
cursor_y = y;
}
int main(void)
{
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(EXIT_FAILURE);
}
if (!glfwOpenWindow(window_width, window_height, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
{
glfwTerminate();
fprintf(stderr, "Failed to open GLFW window\n");
exit(EXIT_FAILURE);
}
glfwSetWindowTitle("Cursor Inaccuracy Detector");
glfwSetMousePosCallback(mouse_position_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
glClearColor(0, 0, 0, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
while (glfwGetWindowParam(GLFW_OPENED))
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.f, 1.f, 1.f);
glBegin(GL_LINES);
glVertex2f(0.f, (GLfloat) window_height - cursor_y);
glVertex2f((GLfloat) window_width, (GLfloat) window_height - cursor_y);
glVertex2f((GLfloat) cursor_x, 0.f);
glVertex2f((GLfloat) cursor_x, (GLfloat) window_height);
glEnd();
glfwSwapBuffers();
}
glfwTerminate();
exit(EXIT_SUCCESS);
}
+98
View File
@@ -0,0 +1,98 @@
//========================================================================
// Default window/context test
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This test creates a windowed mode window with all parameters set to
// default values and then reports the actual parameters of the created
// window and context
//
//========================================================================
#include <GL/glfw.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int param;
char* name;
} Param;
static Param parameters[] =
{
{ GLFW_ACCELERATED, "accelerated" },
{ 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" },
};
int main(void)
{
int i, width, height;
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(1);
}
if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
{
glfwTerminate();
fprintf(stderr, "Failed to open GLFW default window\n");
exit(1);
}
glfwGetWindowSize(&width, &height);
printf("window size: %ix%i\n", width, height);
for (i = 0; (size_t) i < sizeof(parameters) / sizeof(parameters[0]); i++)
{
printf("%s: %i\n", parameters[i].name, glfwGetWindowParam(parameters[i].param));
}
glfwCloseWindow();
glfwTerminate();
exit(0);
}
+309
View File
@@ -0,0 +1,309 @@
//========================================================================
// Event linter (event spewer)
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This test hooks every available callback and outputs their arguments
//
// Log messages go to stdout, error messages to stderr
//
// Every event also gets a (sequential) number to aid discussion of logs
//
//========================================================================
#include <GL/glfw.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <locale.h>
static GLboolean keyrepeat = 0;
static GLboolean systemkeys = 1;
static unsigned int counter = 0;
static const char* get_key_name(int key)
{
switch (key)
{
case GLFW_KEY_UNKNOWN: return "unknown";
case GLFW_KEY_SPACE: return "space";
case GLFW_KEY_ESC: return "escape";
case GLFW_KEY_F1: return "F1";
case GLFW_KEY_F2: return "F2";
case GLFW_KEY_F3: return "F3";
case GLFW_KEY_F4: return "F4";
case GLFW_KEY_F5: return "F5";
case GLFW_KEY_F6: return "F6";
case GLFW_KEY_F7: return "F7";
case GLFW_KEY_F8: return "F8";
case GLFW_KEY_F9: return "F9";
case GLFW_KEY_F10: return "F10";
case GLFW_KEY_F11: return "F11";
case GLFW_KEY_F12: return "F12";
case GLFW_KEY_F13: return "F13";
case GLFW_KEY_F14: return "F14";
case GLFW_KEY_F15: return "F15";
case GLFW_KEY_F16: return "F16";
case GLFW_KEY_F17: return "F17";
case GLFW_KEY_F18: return "F18";
case GLFW_KEY_F19: return "F19";
case GLFW_KEY_F20: return "F20";
case GLFW_KEY_F21: return "F21";
case GLFW_KEY_F22: return "F22";
case GLFW_KEY_F23: return "F23";
case GLFW_KEY_F24: return "F24";
case GLFW_KEY_F25: return "F25";
case GLFW_KEY_UP: return "up";
case GLFW_KEY_DOWN: return "down";
case GLFW_KEY_LEFT: return "left";
case GLFW_KEY_RIGHT: return "right";
case GLFW_KEY_LSHIFT: return "left shift";
case GLFW_KEY_RSHIFT: return "right shift";
case GLFW_KEY_LCTRL: return "left control";
case GLFW_KEY_RCTRL: return "right control";
case GLFW_KEY_LALT: return "left alt";
case GLFW_KEY_RALT: return "right alt";
case GLFW_KEY_TAB: return "tab";
case GLFW_KEY_ENTER: return "enter";
case GLFW_KEY_BACKSPACE: return "backspace";
case GLFW_KEY_INSERT: return "insert";
case GLFW_KEY_DEL: return "delete";
case GLFW_KEY_PAGEUP: return "page up";
case GLFW_KEY_PAGEDOWN: return "page down";
case GLFW_KEY_HOME: return "home";
case GLFW_KEY_END: return "end";
case GLFW_KEY_KP_0: return "keypad 0";
case GLFW_KEY_KP_1: return "keypad 1";
case GLFW_KEY_KP_2: return "keypad 2";
case GLFW_KEY_KP_3: return "keypad 3";
case GLFW_KEY_KP_4: return "keypad 4";
case GLFW_KEY_KP_5: return "keypad 5";
case GLFW_KEY_KP_6: return "keypad 6";
case GLFW_KEY_KP_7: return "keypad 7";
case GLFW_KEY_KP_8: return "keypad 8";
case GLFW_KEY_KP_9: return "keypad 9";
case GLFW_KEY_KP_DIVIDE: return "keypad divide";
case GLFW_KEY_KP_MULTIPLY: return "keypad multiply";
case GLFW_KEY_KP_SUBTRACT: return "keypad subtract";
case GLFW_KEY_KP_ADD: return "keypad add";
case GLFW_KEY_KP_DECIMAL: return "keypad decimal";
case GLFW_KEY_KP_EQUAL: return "keypad equal";
case GLFW_KEY_KP_ENTER: return "keypad enter";
case GLFW_KEY_KP_NUM_LOCK: return "keypad num lock";
case GLFW_KEY_CAPS_LOCK: return "caps lock";
case GLFW_KEY_SCROLL_LOCK: return "scroll lock";
case GLFW_KEY_PAUSE: return "pause";
case GLFW_KEY_LSUPER: return "left super";
case GLFW_KEY_RSUPER: return "right super";
case GLFW_KEY_MENU: return "menu";
}
return NULL;
}
static const char* get_action_name(int action)
{
switch (action)
{
case GLFW_PRESS:
return "was pressed";
case GLFW_RELEASE:
return "was released";
}
return "caused unknown action";
}
static const char* get_button_name(int button)
{
switch (button)
{
case GLFW_MOUSE_BUTTON_LEFT:
return "left";
case GLFW_MOUSE_BUTTON_RIGHT:
return "right";
case GLFW_MOUSE_BUTTON_MIDDLE:
return "middle";
}
return NULL;
}
static const char* get_character_string(int character)
{
static char result[6 + 1];
int length = wctomb(result, character);
if (length == -1)
length = 0;
result[length] = '\0';
return result;
}
static void GLFWCALL window_size_callback(int width, int height)
{
printf("%08x at %0.3f: Window size: %i %i\n",
counter++,
glfwGetTime(),
width,
height);
glViewport(0, 0, width, height);
}
static int GLFWCALL window_close_callback(void)
{
printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime());
return 1;
}
static void GLFWCALL window_refresh_callback(void)
{
printf("%08x at %0.3f: Window refresh\n", counter++, glfwGetTime());
}
static void GLFWCALL mouse_button_callback(int button, int action)
{
const char* name = get_button_name(button);
printf("%08x at %0.3f: Mouse button %i", counter++, glfwGetTime(), button);
if (name)
printf(" (%s) was %s\n", name, get_action_name(action));
else
printf(" was %s\n", get_action_name(action));
}
static void GLFWCALL mouse_position_callback(int x, int y)
{
printf("%08x at %0.3f: Mouse position: %i %i\n", counter++, glfwGetTime(), x, y);
}
static void GLFWCALL mouse_wheel_callback(int position)
{
printf("%08x at %0.3f: Mouse wheel: %i\n", counter++, glfwGetTime(), position);
}
static void GLFWCALL key_callback(int key, int action)
{
const char* name = get_key_name(key);
printf("%08x at %0.3f: Key 0x%04x", counter++, glfwGetTime(), key);
if (name)
printf(" (%s) was %s\n", name, get_action_name(action));
else if (isgraph(key))
printf(" (%c) was %s\n", key, get_action_name(action));
else
printf(" was %s\n", get_action_name(action));
if (action != GLFW_PRESS)
return;
switch (key)
{
case 'R':
{
keyrepeat = !keyrepeat;
if (keyrepeat)
glfwEnable(GLFW_KEY_REPEAT);
else
glfwDisable(GLFW_KEY_REPEAT);
printf("(( key repeat %s ))\n", keyrepeat ? "enabled" : "disabled");
break;
}
case 'S':
{
systemkeys = !systemkeys;
if( systemkeys )
glfwEnable(GLFW_SYSTEM_KEYS);
else
glfwDisable(GLFW_SYSTEM_KEYS);
printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
break;
}
}
}
static void GLFWCALL char_callback(int character, int action)
{
printf("%08x at %0.3f: Character 0x%04x", counter++, glfwGetTime(), character);
printf(" (%s) %s\n", get_character_string(character), get_action_name(action));
}
int main(void)
{
setlocale(LC_ALL, "");
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(1);
}
printf("Library initialized\n");
if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
{
glfwTerminate();
fprintf(stderr, "Failed to create GLFW window");
exit(1);
}
printf("Window opened\n");
glfwSetWindowTitle("Event Linter");
glfwSwapInterval(1);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetWindowRefreshCallback(window_refresh_callback);
glfwSetMouseButtonCallback(mouse_button_callback);
glfwSetMousePosCallback(mouse_position_callback);
glfwSetMouseWheelCallback(mouse_wheel_callback);
glfwSetKeyCallback(key_callback);
glfwSetCharCallback(char_callback);
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 (glfwGetWindowParam(GLFW_OPENED) == GL_TRUE)
{
glfwWaitEvents();
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
}
glfwTerminate();
exit(0);
}
+105
View File
@@ -0,0 +1,105 @@
//========================================================================
// Fullscreen multisampling anti-aliasing test
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This test renders two high contrast, slowly rotating quads, one aliased
// and one (hopefully) anti-aliased, thus allowing for visual verification
// of whether FSAA is indeed enabled
//
//========================================================================
#include <GL/glfw.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef GL_ARB_multisample
#define GL_MULTISAMPLE_ARB 0x809D
#endif
static void GLFWCALL window_size_callback(int width, int height)
{
glViewport(0, 0, width, height);
}
int main(void)
{
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(EXIT_FAILURE);
}
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
if (!glfwOpenWindow(400, 400, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
{
glfwTerminate();
fprintf(stderr, "Failed to open GLFW window\n");
exit(EXIT_FAILURE);
}
glfwSetWindowTitle("Aliasing Detector");
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
int samples = glfwGetWindowParam(GLFW_FSAA_SAMPLES);
if (samples)
printf("Context reports FSAA is supported with %i samples\n", samples);
else
printf("Context reports FSAA is unsupported\n");
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.f, 1.f, 0.f, 1.f);
while (glfwGetWindowParam(GLFW_OPENED))
{
GLfloat time = (GLfloat) glfwGetTime();
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.5f, 0.f, 0.f);
glRotatef(time, 0.f, 0.f, 1.f);
glEnable(GL_MULTISAMPLE_ARB);
glColor3f(1.f, 1.f, 1.f);
glRectf(-0.25f, -0.25f, 0.25f, 0.25f);
glLoadIdentity();
glTranslatef(-0.5f, 0.f, 0.f);
glRotatef(time, 0.f, 0.f, 1.f);
glDisable(GL_MULTISAMPLE_ARB);
glColor3f(1.f, 1.f, 1.f);
glRectf(-0.25f, -0.25f, 0.25f, 0.25f);
glfwSwapBuffers();
}
glfwTerminate();
exit(EXIT_SUCCESS);
}
+253
View File
@@ -0,0 +1,253 @@
/*****************************************************************************
* 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "getopt.h"
/* 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
*/
+63
View File
@@ -0,0 +1,63 @@
/*****************************************************************************
* 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
*/
+158
View File
@@ -0,0 +1,158 @@
//========================================================================
// Iconify/restore test program
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This program is used to test the iconify/restore functionality for
// both fullscreen and windowed mode windows
//
//========================================================================
#include <GL/glfw.h>
#include <stdio.h>
#include <stdlib.h>
#include "getopt.h"
static void usage(void)
{
printf("iconify [-h] [-f]\n");
}
static void GLFWCALL key_callback(int key, int action)
{
printf("%0.2f Key %s\n",
glfwGetTime(),
action == GLFW_PRESS ? "pressed" : "released");
if (action != GLFW_PRESS)
return;
switch (key)
{
case GLFW_KEY_SPACE:
glfwIconifyWindow();
break;
case GLFW_KEY_ESC:
glfwCloseWindow();
break;
}
}
static void GLFWCALL size_callback(int width, int height)
{
glViewport(0, 0, width, height);
}
int main(int argc, char** argv)
{
int width, height, ch;
int mode = GLFW_WINDOW;
GLboolean active = -1, iconified = -1;
while ((ch = getopt(argc, argv, "fh")) != -1)
{
switch (ch)
{
case 'h':
usage();
exit(EXIT_SUCCESS);
case 'f':
mode = GLFW_FULLSCREEN;
break;
default:
usage();
exit(EXIT_FAILURE);
}
}
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(EXIT_FAILURE);
}
if (mode == GLFW_FULLSCREEN)
{
GLFWvidmode mode;
glfwGetDesktopMode(&mode);
width = mode.Width;
height = mode.Height;
}
else
{
width = 0;
height = 0;
}
if (!glfwOpenWindow(width, height, 0, 0, 0, 0, 0, 0, mode))
{
glfwTerminate();
fprintf(stderr, "Failed to open GLFW window\n");
exit(EXIT_FAILURE);
}
glfwSetWindowTitle("Iconify");
glfwSwapInterval(1);
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(size_callback);
glEnable(GL_SCISSOR_TEST);
while (glfwGetWindowParam(GLFW_OPENED))
{
int width, height;
if (iconified != glfwGetWindowParam(GLFW_ICONIFIED) ||
active != glfwGetWindowParam(GLFW_ACTIVE))
{
iconified = glfwGetWindowParam(GLFW_ICONIFIED);
active = glfwGetWindowParam(GLFW_ACTIVE);
printf("%0.2f %s %s\n",
glfwGetTime(),
iconified ? "Iconified" : "Restored",
active ? "Active" : "Inactive");
}
glfwGetWindowSize(&width, &height);
glScissor(0, 0, width, height);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glScissor(0, 0, 640, 480);
glClearColor(1, 1, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
}
glfwTerminate();
exit(EXIT_SUCCESS);
}
+136
View File
@@ -0,0 +1,136 @@
/*========================================================================
* This is a small test application for GLFW.
* joystick input test.
*========================================================================*/
#include <GL/glfw.h>
#include <stdio.h>
#include <math.h>
#define MAX_AXES 10
#define MAX_BUTTONS 30
struct JoystickState
{
int present;
int num_axes;
int num_buttons;
float axes[MAX_AXES];
unsigned char buttons[MAX_BUTTONS];
};
static struct JoystickState states[GLFW_JOYSTICK_LAST + 1];
int running;
int keyrepeat = 0;
int systemkeys = 1;
/*========================================================================
* Retrieve joystick states
*========================================================================*/
static void updateJoysticksState(void)
{
int joy;
for (joy = GLFW_JOYSTICK_1; joy < GLFW_JOYSTICK_LAST + 1; joy++)
{
printf("Updating information for joystick %d\n", joy);
states[joy].present = glfwGetJoystickParam(joy, GLFW_PRESENT);
if (states[joy].present == GL_TRUE)
{
states[joy].num_axes = glfwGetJoystickPos(joy, states[joy].axes, MAX_AXES);
states[joy].num_buttons = glfwGetJoystickButtons(joy, states[joy].buttons, MAX_BUTTONS);
}
}
}
/*========================================================================
* Print out the state of all joysticks on the standard output
*========================================================================*/
static void displayJoysticksState(void)
{
int joy;
int i;
for (joy = GLFW_JOYSTICK_1; joy < GLFW_JOYSTICK_LAST + 1; joy++)
{
printf("Joystick %d: %s\n", joy, (states[joy].present == GL_TRUE ? "present" : "not connected"));
if (states[joy].present == GL_TRUE)
{
if (states[joy].num_axes > 0)
{
printf(" axes: %.3f", states[joy].axes[0]);
for (i = 1; i < states[joy].num_axes; i++)
printf(", %.3f", states[joy].axes[i]);
printf("\n");
}
else
printf(" axes: none\n");
if (states[joy].num_buttons > 0)
{
printf(" buttons: 00 => %c", ((states[joy].buttons[0] == GLFW_PRESS) ? 'P' : 'R'));
for (i = 1; i < states[joy].num_buttons; i++)
printf(", %02d => %c", i, ((states[joy].buttons[i] == GLFW_PRESS) ? 'P' : 'R'));
printf("\n");
}
else
printf(" buttons: none\n");
}
}
}
int main(void)
{
double start;
double t;
double update;
/* Initialise GLFW */
glfwInit();
printf("The program will work for 20 seconds and display every seconds the state of the joysticks\n");
printf("Your computer is going to be very slow as the program is doing an active loop .....\n");
start = glfwGetTime();
update = start;
/* print the initial state of all joysticks */
updateJoysticksState();
printf("\n");
displayJoysticksState();
running = GL_TRUE;
/* Main loop */
while (running)
{
/* Get time */
t = glfwGetTime();
/* Display the state of all connected joysticks every secons */
if ((t - update) > 1.0)
{
update = t;
printf("\n");
updateJoysticksState();
printf("\n");
displayJoysticksState();
}
/* Check if the window was closed */
if ((t - start) > 20.0)
running = GL_FALSE;
}
/* Close OpenGL window and terminate GLFW */
glfwTerminate();
return 0;
}
+137
View File
@@ -0,0 +1,137 @@
//========================================================================
// Mouse cursor bug test
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This test came about as the result of bugs #1262764, #1726540 and
// #1726592, all reported by the user peterpp, hence the name
//
// The utility of this test outside of these bugs is uncertain
//
//========================================================================
#include <GL/glfw.h>
#include <stdio.h>
#include <stdlib.h>
static GLboolean cursor_enabled = GL_TRUE;
static GLboolean open_window(void);
static void toggle_mouse_cursor(void)
{
if (cursor_enabled)
glfwDisable(GLFW_MOUSE_CURSOR);
else
glfwEnable(GLFW_MOUSE_CURSOR);
cursor_enabled = !cursor_enabled;
}
static void GLFWCALL mouse_position_callback(int x, int y)
{
printf("Mouse moved to: %i %i\n", x, y);
}
static void GLFWCALL key_callback(int key, int action)
{
switch (key)
{
case GLFW_KEY_SPACE:
{
if (action == GLFW_PRESS)
toggle_mouse_cursor();
break;
}
case 'R':
{
if (action == GLFW_PRESS)
{
glfwCloseWindow();
open_window();
}
break;
}
}
}
static void GLFWCALL window_size_callback(int width, int height)
{
glViewport(0, 0, width, height);
}
static GLboolean open_window(void)
{
int x, y;
if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
return GL_FALSE;
glfwSetWindowTitle("Peter Detector");
glfwGetMousePos(&x, &y);
printf("Mouse position: %i %i\n", x, y);
glfwDisable(GLFW_AUTO_POLL_EVENTS);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetMousePosCallback(mouse_position_callback);
glfwSetKeyCallback(key_callback);
glfwSwapInterval(1);
return GL_TRUE;
}
int main(void)
{
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(1);
}
if (!open_window())
{
glfwTerminate();
fprintf(stderr, "Failed to open GLFW window\n");
exit(1);
}
glClearColor(0.f, 0.f, 0.f, 0.f);
while (glfwGetWindowParam(GLFW_OPENED))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwWaitEvents();
}
glfwTerminate();
exit(0);
}
+170
View File
@@ -0,0 +1,170 @@
//========================================================================
// Window re-opener (open/close stress test)
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This test came about as the result of bug #1262773
//
// It closes and re-opens the GLFW window every five seconds, alternating
// between windowed and fullscreen mode
//
// It also times and logs opening and closing actions and attempts to separate
// user initiated window closing from its own
//
//========================================================================
#include <GL/glfw.h>
#include <stdio.h>
#include <stdlib.h>
static GLboolean closed = GL_FALSE;
static const char* get_mode_name(int mode)
{
switch (mode)
{
case GLFW_WINDOW:
return "windowed";
case GLFW_FULLSCREEN:
return "fullscreen";
default:
return "unknown";
}
}
static void GLFWCALL window_size_callback(int width, int height)
{
glViewport(0, 0, width, height);
}
static int GLFWCALL window_close_callback(void)
{
printf("Close callback triggered\n");
closed = GL_TRUE;
return 0;
}
static void GLFWCALL key_callback(int key, int action)
{
if (action != GLFW_PRESS)
return;
switch (key)
{
case 'Q':
case GLFW_KEY_ESC:
closed = GL_TRUE;
break;
}
}
static int open_window(int width, int height, int mode)
{
double base = glfwGetTime();
if (!glfwOpenWindow(width, height, 0, 0, 0, 0, 16, 0, mode))
{
fprintf(stderr, "Failed to create %s mode GLFW window\n", get_mode_name(mode));
return 0;
}
glfwSetWindowTitle("Window Re-opener");
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),
glfwGetTime() - base);
return 1;
}
static void close_window(void)
{
double base = glfwGetTime();
glfwCloseWindow();
printf("Closing window took %0.3f seconds\n", glfwGetTime() - base);
}
int main(int argc, char** argv)
{
int count = 0;
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(1);
}
for (;;)
{
if (!open_window(640, 480, (count & 1) ? GLFW_FULLSCREEN : GLFW_WINDOW))
{
glfwTerminate();
exit(1);
}
glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.f, 0.f, 0.f, 0.f);
glColor3f(1.f, 1.f, 1.f);
glfwSetTime(0.0);
while (glfwGetTime() < 5.0)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef((GLfloat) glfwGetTime() * 100.f, 0.f, 0.f, 1.f);
glRectf(-0.5f, -0.5f, 1.f, 1.f);
glPopMatrix();
glfwSwapBuffers();
if (closed)
close_window();
if (!glfwGetWindowParam(GLFW_OPENED))
{
printf("User closed window\n");
glfwTerminate();
exit(0);
}
}
printf("Closing window\n");
close_window();
count++;
}
}
+84
View File
@@ -0,0 +1,84 @@
//========================================================================
// Vsync enabling test
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This test renders a high contrast, horizontally moving bar, allowing for
// visual verification of whether the set swap interval is indeed obeyed
//
//========================================================================
#include <GL/glfw.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
static void GLFWCALL window_size_callback(int width, int height)
{
glViewport(0, 0, width, height);
}
int main(void)
{
float position;
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(1);
}
if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
{
glfwTerminate();
fprintf(stderr, "Failed to open GLFW window\n");
exit(1);
}
glfwSetWindowTitle("Tearing Detector");
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
glClearColor(0.f, 0.f, 0.f, 0.f);
glColor3f(1.f, 1.f, 1.f);
glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
glMatrixMode(GL_MODELVIEW);
while (glfwGetWindowParam(GLFW_OPENED) == GL_TRUE)
{
glClear(GL_COLOR_BUFFER_BIT);
position = cosf(glfwGetTime() * 4.f) * 0.75f;
glRectf(position - 0.25f, -1.f, position + 0.25f, 1.f);
glfwSwapBuffers();
}
glfwTerminate();
exit(0);
}
+253
View File
@@ -0,0 +1,253 @@
//========================================================================
// Version information dumper
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This test is a pale imitation of glxinfo(1), except not really
//
// It dumps GLFW and OpenGL version information
//
//========================================================================
#include <GL/glfw.h>
#ifndef GL_VERSION_3_2
#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001
#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
#define GL_CONTEXT_PROFILE_MASK 0x9126
#define GL_NUM_EXTENSIONS 0x821D
#define GL_CONTEXT_FLAGS 0x821E
#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x0001
#endif
typedef const GLubyte * (APIENTRY *PFNGLGETSTRINGI) (GLenum, GLuint);
#ifndef GL_VERSION_2_0
#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
#endif
#ifdef _MSC_VER
#define strcasecmp(x, y) _stricmp(x, y)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "getopt.h"
static void usage(void)
{
printf("version [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE]\n");
printf("available profiles: core compat\n");
}
static const char* get_profile_name(GLint mask)
{
if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
return "compatibility";
if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
return "core";
return "unknown";
}
static void list_extensions(int major, int minor)
{
int i;
GLint count;
const GLubyte* extensions;
printf("OpenGL context supported extensions:\n");
if (major > 2)
{
PFNGLGETSTRINGI glGetStringi = (PFNGLGETSTRINGI) glfwGetProcAddress("glGetStringi");
if (!glGetStringi)
{
fprintf(stderr, "Failed to retrieve glGetStringi entry point");
exit(EXIT_FAILURE);
}
glGetIntegerv(GL_NUM_EXTENSIONS, &count);
for (i = 0; i < count; i++)
puts((const char*) glGetStringi(GL_EXTENSIONS, i));
}
else
{
extensions = glGetString(GL_EXTENSIONS);
while (*extensions != '\0')
{
if (*extensions == ' ')
putchar('\n');
else
putchar(*extensions);
extensions++;
}
}
putchar('\n');
}
int main(int argc, char** argv)
{
int ch, profile = 0, major = 1, minor = 1, revision;
GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE;
GLint flags, mask;
while ((ch = getopt(argc, argv, "dfhlm:n:p:")) != -1)
{
switch (ch)
{
case 'd':
debug = GL_TRUE;
break;
case 'f':
forward = GL_TRUE;
break;
case 'h':
usage();
exit(0);
case 'l':
list = GL_TRUE;
break;
case 'm':
major = atoi(optarg);
break;
case 'n':
minor = atoi(optarg);
break;
case 'p':
if (strcasecmp(optarg, "core") == 0)
profile = GLFW_OPENGL_CORE_PROFILE;
else if (strcasecmp(optarg, "compat") == 0)
profile = GLFW_OPENGL_COMPAT_PROFILE;
else
{
usage();
exit(EXIT_FAILURE);
}
break;
default:
usage();
exit(EXIT_FAILURE);
}
}
argc -= optind;
argv += optind;
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(EXIT_FAILURE);
}
if (major != 1 || minor != 1)
{
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, minor);
}
if (debug)
glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
if (forward)
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
if (profile != 0)
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, profile);
// We assume here that we stand a better chance of success by leaving all
// possible details of pixel format selection to GLFW
if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
{
glfwTerminate();
fprintf(stderr, "Failed to open GLFW window\n");
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");
// Report OpenGL version
printf("OpenGL context version string: \"%s\"\n", glGetString(GL_VERSION));
glfwGetGLVersion(&major, &minor, &revision);
printf("OpenGL context version parsed by GLFW: %u.%u.%u\n", major, minor, revision);
// Report OpenGL context properties
if (major >= 3)
{
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
printf("OpenGL context flags:");
if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
puts(" forward-compatible");
else
puts(" none");
}
if (major > 3 || (major == 3 && minor >= 2))
{
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
printf("OpenGL profile mask: 0x%08x (%s)\n", mask, get_profile_name(mask));
}
printf("OpenGL context renderer string: \"%s\"\n", glGetString(GL_RENDERER));
printf("OpenGL context vendor string: \"%s\"\n", glGetString(GL_VENDOR));
if (major > 1)
{
printf("OpenGL context shading language version: \"%s\"\n",
glGetString(GL_SHADING_LANGUAGE_VERSION));
}
// Report OpenGL extensions
if (list)
list_extensions(major, minor);
glfwTerminate();
exit(EXIT_SUCCESS);
}