mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-23 02:38:52 -05:00
Merge fix.
This commit is contained in:
commit
7eea9b2384
|
@ -8,8 +8,7 @@ set(GLFW_VERSION_MINOR "0")
|
||||||
set(GLFW_VERSION_PATCH "0")
|
set(GLFW_VERSION_PATCH "0")
|
||||||
set(GLFW_VERSION_EXTRA "")
|
set(GLFW_VERSION_EXTRA "")
|
||||||
set(GLFW_VERSION "${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}")
|
set(GLFW_VERSION "${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}")
|
||||||
set(GLFW_VERSION_FULL
|
set(GLFW_VERSION_FULL "${GLFW_VERSION}.${GLFW_VERSION_PATCH}${GLFW_VERSION_EXTRA}")
|
||||||
"${GLFW_VERSION}.${GLFW_VERSION_PATCH}${GLFW_VERSION_EXTRA}")
|
|
||||||
|
|
||||||
include(CheckFunctionExists)
|
include(CheckFunctionExists)
|
||||||
include(CheckSymbolExists)
|
include(CheckSymbolExists)
|
||||||
|
@ -159,8 +158,7 @@ install(FILES COPYING.txt readme.html
|
||||||
# Uninstall operation
|
# Uninstall operation
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
configure_file(${GLFW_SOURCE_DIR}/cmake_uninstall.cmake.in
|
configure_file(${GLFW_SOURCE_DIR}/cmake_uninstall.cmake.in
|
||||||
${GLFW_BINARY_DIR}/cmake_uninstall.cmake
|
${GLFW_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY)
|
||||||
IMMEDIATE @ONLY)
|
|
||||||
|
|
||||||
add_custom_target(uninstall
|
add_custom_target(uninstall
|
||||||
${CMAKE_COMMAND} -P
|
${CMAKE_COMMAND} -P
|
||||||
|
|
|
@ -585,7 +585,7 @@ int main( void )
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowSizeCallback( window, reshape );
|
glfwSetWindowSizeCallback( reshape );
|
||||||
glfwEnable( window, GLFW_STICKY_KEYS );
|
glfwEnable( window, GLFW_STICKY_KEYS );
|
||||||
glfwSwapInterval( 1 );
|
glfwSwapInterval( 1 );
|
||||||
glfwSetTime( 0.0 );
|
glfwSetTime( 0.0 );
|
||||||
|
|
|
@ -346,8 +346,8 @@ int main(int argc, char *argv[])
|
||||||
init(argc, argv);
|
init(argc, argv);
|
||||||
|
|
||||||
// Set callback functions
|
// Set callback functions
|
||||||
glfwSetWindowSizeCallback( window, reshape );
|
glfwSetWindowSizeCallback( reshape );
|
||||||
glfwSetKeyCallback( window, key );
|
glfwSetKeyCallback( key );
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while( running )
|
while( running )
|
||||||
|
|
|
@ -597,8 +597,8 @@ int main(int argc, char** argv)
|
||||||
free(fragment_shader_src);
|
free(fragment_shader_src);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
glfwSetWindowCloseCallback(window, window_close_callback);
|
glfwSetWindowCloseCallback(window_close_callback);
|
||||||
glfwSetKeyCallback(window, key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
/* Register events callback */
|
/* Register events callback */
|
||||||
|
|
||||||
if (GL_TRUE != init_opengl())
|
if (GL_TRUE != init_opengl())
|
||||||
|
|
|
@ -1,122 +0,0 @@
|
||||||
//========================================================================
|
|
||||||
// This is an example program for the GLFW library
|
|
||||||
//
|
|
||||||
// It shows texture loading with mipmap generation and rendering with
|
|
||||||
// trilienar texture filtering
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <GL/glfw.h>
|
|
||||||
|
|
||||||
int main( void )
|
|
||||||
{
|
|
||||||
int width, height, x;
|
|
||||||
double time;
|
|
||||||
GLboolean running;
|
|
||||||
GLuint textureID;
|
|
||||||
char* texturePath = "mipmaps.tga";
|
|
||||||
|
|
||||||
// Initialise GLFW
|
|
||||||
if( !glfwInit() )
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Failed to initialize GLFW\n" );
|
|
||||||
exit( EXIT_FAILURE );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open OpenGL window
|
|
||||||
if( !glfwOpenWindow( 640, 480, 0,0,0,0, 0,0, GLFW_WINDOW ) )
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
|
||||||
glfwTerminate();
|
|
||||||
exit( EXIT_FAILURE );
|
|
||||||
}
|
|
||||||
|
|
||||||
glfwSetWindowTitle( "Trilinear interpolation" );
|
|
||||||
|
|
||||||
// Enable sticky keys
|
|
||||||
glfwEnable( GLFW_STICKY_KEYS );
|
|
||||||
|
|
||||||
// Enable vertical sync (on cards that support it)
|
|
||||||
glfwSwapInterval( 1 );
|
|
||||||
|
|
||||||
// Generate and bind our texture ID
|
|
||||||
glGenTextures( 1, &textureID );
|
|
||||||
glBindTexture( GL_TEXTURE_2D, textureID );
|
|
||||||
|
|
||||||
// Load texture from file into video memory, including mipmap levels
|
|
||||||
if( !glfwLoadTexture2D( texturePath, GLFW_BUILD_MIPMAPS_BIT ) )
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Failed to load texture %s\n", texturePath );
|
|
||||||
glfwTerminate();
|
|
||||||
exit( EXIT_FAILURE );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use trilinear interpolation (GL_LINEAR_MIPMAP_LINEAR)
|
|
||||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
|
||||||
GL_LINEAR_MIPMAP_LINEAR );
|
|
||||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
|
||||||
GL_LINEAR );
|
|
||||||
|
|
||||||
// Enable plain 2D texturing
|
|
||||||
glEnable( GL_TEXTURE_2D );
|
|
||||||
|
|
||||||
running = GL_TRUE;
|
|
||||||
while( running )
|
|
||||||
{
|
|
||||||
// Get time and mouse position
|
|
||||||
time = glfwGetTime();
|
|
||||||
glfwGetMousePos( &x, NULL );
|
|
||||||
|
|
||||||
// Get window size (may be different than the requested size)
|
|
||||||
glfwGetWindowSize( &width, &height );
|
|
||||||
height = height > 0 ? height : 1;
|
|
||||||
|
|
||||||
// Set viewport
|
|
||||||
glViewport( 0, 0, width, height );
|
|
||||||
|
|
||||||
// Clear color buffer
|
|
||||||
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);
|
|
||||||
glClear( GL_COLOR_BUFFER_BIT );
|
|
||||||
|
|
||||||
// Select and setup the projection matrix
|
|
||||||
glMatrixMode( GL_PROJECTION );
|
|
||||||
glLoadIdentity();
|
|
||||||
gluPerspective( 65.0f, (GLfloat)width / (GLfloat)height, 1.0f,
|
|
||||||
50.0f );
|
|
||||||
|
|
||||||
// Select and setup the modelview matrix
|
|
||||||
glMatrixMode( GL_MODELVIEW );
|
|
||||||
glLoadIdentity();
|
|
||||||
gluLookAt( 0.0f, 3.0f, -20.0f, // Eye-position
|
|
||||||
0.0f, -4.0f, -11.0f, // View-point
|
|
||||||
0.0f, 1.0f, 0.0f ); // Up-vector
|
|
||||||
|
|
||||||
// Draw a textured quad
|
|
||||||
glRotatef( 0.05f * (GLfloat)x + (GLfloat)time * 5.0f, 0.0f, 1.0f, 0.0f );
|
|
||||||
glBegin( GL_QUADS );
|
|
||||||
glTexCoord2f( -20.0f, 20.0f );
|
|
||||||
glVertex3f( -50.0f, 0.0f, -50.0f );
|
|
||||||
glTexCoord2f( 20.0f, 20.0f );
|
|
||||||
glVertex3f( 50.0f, 0.0f, -50.0f );
|
|
||||||
glTexCoord2f( 20.0f, -20.0f );
|
|
||||||
glVertex3f( 50.0f, 0.0f, 50.0f );
|
|
||||||
glTexCoord2f( -20.0f, -20.0f );
|
|
||||||
glVertex3f( -50.0f, 0.0f, 50.0f );
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
// Swap buffers
|
|
||||||
glfwSwapBuffers();
|
|
||||||
|
|
||||||
// Check if the ESC key was pressed or the window was closed
|
|
||||||
running = !glfwGetKey( GLFW_KEY_ESC ) &&
|
|
||||||
glfwGetWindowParam( GLFW_OPENED );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close OpenGL window and terminate GLFW
|
|
||||||
glfwTerminate();
|
|
||||||
|
|
||||||
exit( EXIT_SUCCESS );
|
|
||||||
}
|
|
||||||
|
|
Binary file not shown.
|
@ -50,48 +50,49 @@ static int do_redraw = 1;
|
||||||
#define TORUS_MAJOR_RES 32
|
#define TORUS_MAJOR_RES 32
|
||||||
#define TORUS_MINOR_RES 32
|
#define TORUS_MINOR_RES 32
|
||||||
|
|
||||||
static void drawTorus( void )
|
static void drawTorus(void)
|
||||||
{
|
{
|
||||||
static GLuint torus_list = 0;
|
static GLuint torus_list = 0;
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
double s, t, x, y, z, nx, ny, nz, scale, twopi;
|
double s, t, x, y, z, nx, ny, nz, scale, twopi;
|
||||||
|
|
||||||
if( !torus_list )
|
if (!torus_list)
|
||||||
{
|
{
|
||||||
// Start recording displaylist
|
// Start recording displaylist
|
||||||
torus_list = glGenLists( 1 );
|
torus_list = glGenLists(1);
|
||||||
glNewList( torus_list, GL_COMPILE_AND_EXECUTE );
|
glNewList(torus_list, GL_COMPILE_AND_EXECUTE);
|
||||||
|
|
||||||
// Draw torus
|
// Draw torus
|
||||||
twopi = 2.0 * M_PI;
|
twopi = 2.0 * M_PI;
|
||||||
for( i = 0; i < TORUS_MINOR_RES; i++ )
|
for (i = 0; i < TORUS_MINOR_RES; i++)
|
||||||
{
|
{
|
||||||
glBegin( GL_QUAD_STRIP );
|
glBegin(GL_QUAD_STRIP);
|
||||||
for( j = 0; j <= TORUS_MAJOR_RES; j++ )
|
for (j = 0; j <= TORUS_MAJOR_RES; j++)
|
||||||
{
|
{
|
||||||
for( k = 1; k >= 0; k-- )
|
for (k = 1; k >= 0; k--)
|
||||||
{
|
{
|
||||||
s = (i + k) % TORUS_MINOR_RES + 0.5;
|
s = (i + k) % TORUS_MINOR_RES + 0.5;
|
||||||
t = j % TORUS_MAJOR_RES;
|
t = j % TORUS_MAJOR_RES;
|
||||||
|
|
||||||
// Calculate point on surface
|
// Calculate point on surface
|
||||||
x = (TORUS_MAJOR+TORUS_MINOR*cos(s*twopi/TORUS_MINOR_RES))*cos(t*twopi/TORUS_MAJOR_RES);
|
x = (TORUS_MAJOR + TORUS_MINOR * cos(s * twopi / TORUS_MINOR_RES)) * cos(t * twopi / TORUS_MAJOR_RES);
|
||||||
y = TORUS_MINOR * sin(s * twopi / TORUS_MINOR_RES);
|
y = TORUS_MINOR * sin(s * twopi / TORUS_MINOR_RES);
|
||||||
z = (TORUS_MAJOR+TORUS_MINOR*cos(s*twopi/TORUS_MINOR_RES))*sin(t*twopi/TORUS_MAJOR_RES);
|
z = (TORUS_MAJOR + TORUS_MINOR * cos(s * twopi / TORUS_MINOR_RES)) * sin(t * twopi / TORUS_MAJOR_RES);
|
||||||
|
|
||||||
// Calculate surface normal
|
// Calculate surface normal
|
||||||
nx = x - TORUS_MAJOR*cos(t*twopi/TORUS_MAJOR_RES);
|
nx = x - TORUS_MAJOR * cos(t * twopi / TORUS_MAJOR_RES);
|
||||||
ny = y;
|
ny = y;
|
||||||
nz = z - TORUS_MAJOR*sin(t*twopi/TORUS_MAJOR_RES);
|
nz = z - TORUS_MAJOR * sin(t * twopi / TORUS_MAJOR_RES);
|
||||||
scale = 1.0 / sqrt( nx*nx + ny*ny + nz*nz );
|
scale = 1.0 / sqrt(nx*nx + ny*ny + nz*nz);
|
||||||
nx *= scale;
|
nx *= scale;
|
||||||
ny *= scale;
|
ny *= scale;
|
||||||
nz *= scale;
|
nz *= scale;
|
||||||
|
|
||||||
glNormal3f( (float)nx, (float)ny, (float)nz );
|
glNormal3f((float) nx, (float) ny, (float) nz);
|
||||||
glVertex3f( (float)x, (float)y, (float)z );
|
glVertex3f((float) x, (float) y, (float) z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +102,7 @@ static void drawTorus( void )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Playback displaylist
|
// Playback displaylist
|
||||||
glCallList( torus_list );
|
glCallList(torus_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +111,7 @@ static void drawTorus( void )
|
||||||
// Draw the scene (a rotating torus)
|
// Draw the scene (a rotating torus)
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void drawScene( void )
|
static void drawScene(void)
|
||||||
{
|
{
|
||||||
const GLfloat model_diffuse[4] = {1.0f, 0.8f, 0.8f, 1.0f};
|
const GLfloat model_diffuse[4] = {1.0f, 0.8f, 0.8f, 1.0f};
|
||||||
const GLfloat model_specular[4] = {0.6f, 0.6f, 0.6f, 1.0f};
|
const GLfloat model_specular[4] = {0.6f, 0.6f, 0.6f, 1.0f};
|
||||||
|
@ -119,17 +120,17 @@ static void drawScene( void )
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
// Rotate the object
|
// Rotate the object
|
||||||
glRotatef( (GLfloat)rot_x*0.5f, 1.0f, 0.0f, 0.0f );
|
glRotatef((GLfloat) rot_x * 0.5f, 1.0f, 0.0f, 0.0f);
|
||||||
glRotatef( (GLfloat)rot_y*0.5f, 0.0f, 1.0f, 0.0f );
|
glRotatef((GLfloat) rot_y * 0.5f, 0.0f, 1.0f, 0.0f);
|
||||||
glRotatef( (GLfloat)rot_z*0.5f, 0.0f, 0.0f, 1.0f );
|
glRotatef((GLfloat) rot_z * 0.5f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
// Set model color (used for orthogonal views, lighting disabled)
|
// Set model color (used for orthogonal views, lighting disabled)
|
||||||
glColor4fv( model_diffuse );
|
glColor4fv(model_diffuse);
|
||||||
|
|
||||||
// Set model material (used for perspective view, lighting enabled)
|
// Set model material (used for perspective view, lighting enabled)
|
||||||
glMaterialfv( GL_FRONT, GL_DIFFUSE, model_diffuse );
|
glMaterialfv(GL_FRONT, GL_DIFFUSE, model_diffuse);
|
||||||
glMaterialfv( GL_FRONT, GL_SPECULAR, model_specular );
|
glMaterialfv(GL_FRONT, GL_SPECULAR, model_specular);
|
||||||
glMaterialf( GL_FRONT, GL_SHININESS, model_shininess );
|
glMaterialf(GL_FRONT, GL_SHININESS, model_shininess);
|
||||||
|
|
||||||
// Draw torus
|
// Draw torus
|
||||||
drawTorus();
|
drawTorus();
|
||||||
|
@ -142,55 +143,55 @@ static void drawScene( void )
|
||||||
// Draw a 2D grid (used for orthogonal views)
|
// Draw a 2D grid (used for orthogonal views)
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void drawGrid( float scale, int steps )
|
static void drawGrid(float scale, int steps)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float x, y;
|
float x, y;
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
// Set background to some dark bluish grey
|
// Set background to some dark bluish grey
|
||||||
glClearColor( 0.05f, 0.05f, 0.2f, 0.0f);
|
glClearColor(0.05f, 0.05f, 0.2f, 0.0f);
|
||||||
glClear( GL_COLOR_BUFFER_BIT );
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
// Setup modelview matrix (flat XY view)
|
// Setup modelview matrix (flat XY view)
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt( 0.0, 0.0, 1.0,
|
gluLookAt(0.0, 0.0, 1.0,
|
||||||
0.0, 0.0, 0.0,
|
0.0, 0.0, 0.0,
|
||||||
0.0, 1.0, 0.0 );
|
0.0, 1.0, 0.0);
|
||||||
|
|
||||||
// We don't want to update the Z-buffer
|
// We don't want to update the Z-buffer
|
||||||
glDepthMask( GL_FALSE );
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
// Set grid color
|
// Set grid color
|
||||||
glColor3f( 0.0f, 0.5f, 0.5f );
|
glColor3f(0.0f, 0.5f, 0.5f);
|
||||||
|
|
||||||
glBegin( GL_LINES );
|
glBegin(GL_LINES);
|
||||||
|
|
||||||
// Horizontal lines
|
// Horizontal lines
|
||||||
x = scale * 0.5f * (float)(steps-1);
|
x = scale * 0.5f * (float) (steps - 1);
|
||||||
y = -scale * 0.5f * (float)(steps-1);
|
y = -scale * 0.5f * (float) (steps - 1);
|
||||||
for( i = 0; i < steps; i ++ )
|
for (i = 0; i < steps; i++)
|
||||||
{
|
{
|
||||||
glVertex3f( -x, y, 0.0f );
|
glVertex3f(-x, y, 0.0f);
|
||||||
glVertex3f( x, y, 0.0f );
|
glVertex3f(x, y, 0.0f);
|
||||||
y += scale;
|
y += scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vertical lines
|
// Vertical lines
|
||||||
x = -scale * 0.5f * (float)(steps-1);
|
x = -scale * 0.5f * (float) (steps - 1);
|
||||||
y = scale * 0.5f * (float)(steps-1);
|
y = scale * 0.5f * (float) (steps - 1);
|
||||||
for( i = 0; i < steps; i ++ )
|
for (i = 0; i < steps; i++)
|
||||||
{
|
{
|
||||||
glVertex3f( x, -y, 0.0f );
|
glVertex3f(x, -y, 0.0f);
|
||||||
glVertex3f( x, y, 0.0f );
|
glVertex3f(x, y, 0.0f);
|
||||||
x += scale;
|
x += scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
// Enable Z-buffer writing again
|
// Enable Z-buffer writing again
|
||||||
glDepthMask( GL_TRUE );
|
glDepthMask(GL_TRUE);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
@ -200,7 +201,7 @@ static void drawGrid( float scale, int steps )
|
||||||
// Draw all views
|
// Draw all views
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void drawAllViews( void )
|
static void drawAllViews(void)
|
||||||
{
|
{
|
||||||
const GLfloat light_position[4] = {0.0f, 8.0f, 8.0f, 1.0f};
|
const GLfloat light_position[4] = {0.0f, 8.0f, 8.0f, 1.0f};
|
||||||
const GLfloat light_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
const GLfloat light_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
|
@ -209,145 +210,142 @@ static void drawAllViews( void )
|
||||||
double aspect;
|
double aspect;
|
||||||
|
|
||||||
// Calculate aspect of window
|
// Calculate aspect of window
|
||||||
if( height > 0 )
|
if (height > 0)
|
||||||
{
|
aspect = (double) width / (double) height;
|
||||||
aspect = (double)width / (double)height;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
aspect = 1.0;
|
aspect = 1.0;
|
||||||
}
|
|
||||||
|
|
||||||
// Clear screen
|
// Clear screen
|
||||||
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// Enable scissor test
|
// Enable scissor test
|
||||||
glEnable( GL_SCISSOR_TEST );
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
// Enable depth test
|
// Enable depth test
|
||||||
glEnable( GL_DEPTH_TEST );
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc( GL_LEQUAL );
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
|
||||||
|
|
||||||
// ** ORTHOGONAL VIEWS **
|
// ** ORTHOGONAL VIEWS **
|
||||||
|
|
||||||
// For orthogonal views, use wireframe rendering
|
// For orthogonal views, use wireframe rendering
|
||||||
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
|
|
||||||
// Enable line anti-aliasing
|
// Enable line anti-aliasing
|
||||||
glEnable( GL_LINE_SMOOTH );
|
glEnable(GL_LINE_SMOOTH);
|
||||||
glEnable( GL_BLEND );
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
// Setup orthogonal projection matrix
|
// Setup orthogonal projection matrix
|
||||||
glMatrixMode( GL_PROJECTION );
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho( -3.0*aspect, 3.0*aspect, -3.0, 3.0, 1.0, 50.0 );
|
glOrtho(-3.0 * aspect, 3.0 * aspect, -3.0, 3.0, 1.0, 50.0);
|
||||||
|
|
||||||
// Upper left view (TOP VIEW)
|
// Upper left view (TOP VIEW)
|
||||||
glViewport( 0, height/2, width/2, height/2 );
|
glViewport(0, height / 2, width / 2, height / 2);
|
||||||
glScissor( 0, height/2, width/2, height/2 );
|
glScissor(0, height / 2, width / 2, height / 2);
|
||||||
glMatrixMode( GL_MODELVIEW );
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt( 0.0f, 10.0f, 1e-3f, // Eye-position (above)
|
gluLookAt(0.0f, 10.0f, 1e-3f, // Eye-position (above)
|
||||||
0.0f, 0.0f, 0.0f, // View-point
|
0.0f, 0.0f, 0.0f, // View-point
|
||||||
0.0f, 1.0f, 0.0f ); // Up-vector
|
0.0f, 1.0f, 0.0f); // Up-vector
|
||||||
drawGrid( 0.5, 12 );
|
drawGrid(0.5, 12);
|
||||||
drawScene();
|
drawScene();
|
||||||
|
|
||||||
// Lower left view (FRONT VIEW)
|
// Lower left view (FRONT VIEW)
|
||||||
glViewport( 0, 0, width/2, height/2 );
|
glViewport(0, 0, width / 2, height / 2);
|
||||||
glScissor( 0, 0, width/2, height/2 );
|
glScissor(0, 0, width / 2, height / 2);
|
||||||
glMatrixMode( GL_MODELVIEW );
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt( 0.0f, 0.0f, 10.0f, // Eye-position (in front of)
|
gluLookAt(0.0f, 0.0f, 10.0f, // Eye-position (in front of)
|
||||||
0.0f, 0.0f, 0.0f, // View-point
|
0.0f, 0.0f, 0.0f, // View-point
|
||||||
0.0f, 1.0f, 0.0f ); // Up-vector
|
0.0f, 1.0f, 0.0f); // Up-vector
|
||||||
drawGrid( 0.5, 12 );
|
drawGrid(0.5, 12);
|
||||||
drawScene();
|
drawScene();
|
||||||
|
|
||||||
// Lower right view (SIDE VIEW)
|
// Lower right view (SIDE VIEW)
|
||||||
glViewport( width/2, 0, width/2, height/2 );
|
glViewport(width / 2, 0, width / 2, height / 2);
|
||||||
glScissor( width/2, 0, width/2, height/2 );
|
glScissor(width / 2, 0, width / 2, height / 2);
|
||||||
glMatrixMode( GL_MODELVIEW );
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt( 10.0f, 0.0f, 0.0f, // Eye-position (to the right)
|
gluLookAt(10.0f, 0.0f, 0.0f, // Eye-position (to the right)
|
||||||
0.0f, 0.0f, 0.0f, // View-point
|
0.0f, 0.0f, 0.0f, // View-point
|
||||||
0.0f, 1.0f, 0.0f ); // Up-vector
|
0.0f, 1.0f, 0.0f); // Up-vector
|
||||||
drawGrid( 0.5, 12 );
|
drawGrid(0.5, 12);
|
||||||
drawScene();
|
drawScene();
|
||||||
|
|
||||||
// Disable line anti-aliasing
|
// Disable line anti-aliasing
|
||||||
glDisable( GL_LINE_SMOOTH );
|
glDisable(GL_LINE_SMOOTH);
|
||||||
glDisable( GL_BLEND );
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
|
||||||
// ** PERSPECTIVE VIEW **
|
// ** PERSPECTIVE VIEW **
|
||||||
|
|
||||||
// For perspective view, use solid rendering
|
// For perspective view, use solid rendering
|
||||||
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
|
||||||
// Enable face culling (faster rendering)
|
// Enable face culling (faster rendering)
|
||||||
glEnable( GL_CULL_FACE );
|
glEnable(GL_CULL_FACE);
|
||||||
glCullFace( GL_BACK );
|
glCullFace(GL_BACK);
|
||||||
glFrontFace( GL_CW );
|
glFrontFace(GL_CW);
|
||||||
|
|
||||||
// Setup perspective projection matrix
|
// Setup perspective projection matrix
|
||||||
glMatrixMode( GL_PROJECTION );
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective( 65.0f, aspect, 1.0f, 50.0f );
|
gluPerspective(65.0f, aspect, 1.0f, 50.0f);
|
||||||
|
|
||||||
// Upper right view (PERSPECTIVE VIEW)
|
// Upper right view (PERSPECTIVE VIEW)
|
||||||
glViewport( width/2, height/2, width/2, height/2 );
|
glViewport(width / 2, height / 2, width / 2, height / 2);
|
||||||
glScissor( width/2, height/2, width/2, height/2 );
|
glScissor(width / 2, height / 2, width / 2, height / 2);
|
||||||
glMatrixMode( GL_MODELVIEW );
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt( 3.0f, 1.5f, 3.0f, // Eye-position
|
gluLookAt(3.0f, 1.5f, 3.0f, // Eye-position
|
||||||
0.0f, 0.0f, 0.0f, // View-point
|
0.0f, 0.0f, 0.0f, // View-point
|
||||||
0.0f, 1.0f, 0.0f ); // Up-vector
|
0.0f, 1.0f, 0.0f); // Up-vector
|
||||||
|
|
||||||
// Configure and enable light source 1
|
// Configure and enable light source 1
|
||||||
glLightfv( GL_LIGHT1, GL_POSITION, light_position );
|
glLightfv(GL_LIGHT1, GL_POSITION, light_position);
|
||||||
glLightfv( GL_LIGHT1, GL_AMBIENT, light_ambient );
|
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
||||||
glLightfv( GL_LIGHT1, GL_DIFFUSE, light_diffuse );
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
||||||
glLightfv( GL_LIGHT1, GL_SPECULAR, light_specular );
|
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
||||||
glEnable( GL_LIGHT1 );
|
glEnable(GL_LIGHT1);
|
||||||
glEnable( GL_LIGHTING );
|
glEnable(GL_LIGHTING);
|
||||||
|
|
||||||
// Draw scene
|
// Draw scene
|
||||||
drawScene();
|
drawScene();
|
||||||
|
|
||||||
// Disable lighting
|
// Disable lighting
|
||||||
glDisable( GL_LIGHTING );
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
// Disable face culling
|
// Disable face culling
|
||||||
glDisable( GL_CULL_FACE );
|
glDisable(GL_CULL_FACE);
|
||||||
|
|
||||||
// Disable depth test
|
// Disable depth test
|
||||||
glDisable( GL_DEPTH_TEST );
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
// Disable scissor test
|
// Disable scissor test
|
||||||
glDisable( GL_SCISSOR_TEST );
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
|
|
||||||
// Draw a border around the active view
|
// Draw a border around the active view
|
||||||
if( active_view > 0 && active_view != 2 )
|
if (active_view > 0 && active_view != 2)
|
||||||
{
|
{
|
||||||
glViewport( 0, 0, width, height );
|
glViewport(0, 0, width, height);
|
||||||
glMatrixMode( GL_PROJECTION );
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho( 0.0, 2.0, 0.0, 2.0, 0.0, 1.0 );
|
glOrtho(0.0, 2.0, 0.0, 2.0, 0.0, 1.0);
|
||||||
glMatrixMode( GL_MODELVIEW );
|
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glColor3f( 1.0f, 1.0f, 0.6f );
|
glTranslatef((GLfloat) ((active_view - 1) & 1), (GLfloat) (1 - (active_view - 1) / 2), 0.0f);
|
||||||
glTranslatef( (GLfloat) ((active_view - 1) & 1), (GLfloat) (1 - (active_view - 1) / 2), 0.0f );
|
|
||||||
glBegin( GL_LINE_STRIP );
|
glColor3f(1.0f, 1.0f, 0.6f);
|
||||||
glVertex2i( 0, 0 );
|
|
||||||
glVertex2i( 1, 0 );
|
glBegin(GL_LINE_STRIP);
|
||||||
glVertex2i( 1, 1 );
|
glVertex2i(0, 0);
|
||||||
glVertex2i( 0, 1 );
|
glVertex2i(1, 0);
|
||||||
glVertex2i( 0, 0 );
|
glVertex2i(1, 1);
|
||||||
|
glVertex2i(0, 1);
|
||||||
|
glVertex2i(0, 0);
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -357,7 +355,7 @@ static void drawAllViews( void )
|
||||||
// Window size callback function
|
// Window size callback function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void windowSizeFun( GLFWwindow window, int w, int h )
|
static void windowSizeFun(GLFWwindow window, int w, int h)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h > 0 ? h : 1;
|
height = h > 0 ? h : 1;
|
||||||
|
@ -369,7 +367,7 @@ static void windowSizeFun( GLFWwindow window, int w, int h )
|
||||||
// Window refresh callback function
|
// Window refresh callback function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void windowRefreshFun( GLFWwindow window )
|
static void windowRefreshFun(GLFWwindow window)
|
||||||
{
|
{
|
||||||
do_redraw = 1;
|
do_redraw = 1;
|
||||||
}
|
}
|
||||||
|
@ -379,10 +377,10 @@ static void windowRefreshFun( GLFWwindow window )
|
||||||
// Mouse position callback function
|
// Mouse position callback function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void mousePosFun( GLFWwindow window, int x, int y )
|
static void mousePosFun(GLFWwindow window, int x, int y)
|
||||||
{
|
{
|
||||||
// Depending on which view was selected, rotate around different axes
|
// Depending on which view was selected, rotate around different axes
|
||||||
switch( active_view )
|
switch (active_view)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
rot_x += y - ypos;
|
rot_x += y - ypos;
|
||||||
|
@ -414,25 +412,18 @@ static void mousePosFun( GLFWwindow window, int x, int y )
|
||||||
// Mouse button callback function
|
// Mouse button callback function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void mouseButtonFun( GLFWwindow window, int button, int action )
|
static void mouseButtonFun(GLFWwindow window, int button, int action)
|
||||||
{
|
{
|
||||||
// Button clicked?
|
if ((button == GLFW_MOUSE_BUTTON_LEFT) && action == GLFW_PRESS)
|
||||||
if( ( button == GLFW_MOUSE_BUTTON_LEFT ) && action == GLFW_PRESS )
|
|
||||||
{
|
{
|
||||||
// Detect which of the four views was clicked
|
// Detect which of the four views was clicked
|
||||||
active_view = 1;
|
active_view = 1;
|
||||||
if( xpos >= width/2 )
|
if (xpos >= width / 2)
|
||||||
{
|
|
||||||
active_view += 1;
|
active_view += 1;
|
||||||
}
|
if (ypos >= height / 2)
|
||||||
if( ypos >= height/2 )
|
|
||||||
{
|
|
||||||
active_view += 2;
|
active_view += 2;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if (button == GLFW_MOUSE_BUTTON_LEFT)
|
||||||
// Button released?
|
|
||||||
else if( button == GLFW_MOUSE_BUTTON_LEFT )
|
|
||||||
{
|
{
|
||||||
// Deselect any previously selected view
|
// Deselect any previously selected view
|
||||||
active_view = 0;
|
active_view = 0;
|
||||||
|
@ -443,51 +434,50 @@ static void mouseButtonFun( GLFWwindow window, int button, int action )
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// main()
|
// main
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
int main( void )
|
int main(void)
|
||||||
{
|
{
|
||||||
GLFWwindow window;
|
GLFWwindow window;
|
||||||
|
|
||||||
// Initialise GLFW
|
// Initialise GLFW
|
||||||
if( !glfwInit() )
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Failed to initialize GLFW\n" );
|
fprintf(stderr, "Failed to initialize GLFW\n");
|
||||||
exit( EXIT_FAILURE );
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwOpenWindowHint(GLFW_DEPTH_BITS, 16);
|
glfwOpenWindowHint(GLFW_DEPTH_BITS, 16);
|
||||||
|
|
||||||
// Open OpenGL window
|
// Open OpenGL window
|
||||||
window = glfwOpenWindow( 500, 500, GLFW_WINDOWED, "Split view demo", NULL );
|
window = glfwOpenWindow(500, 500, GLFW_WINDOWED, "Split view demo", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
fprintf(stderr, "Failed to open GLFW window\n");
|
||||||
glfwTerminate();
|
exit(EXIT_FAILURE);
|
||||||
exit( EXIT_FAILURE );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable vsync
|
// Enable vsync
|
||||||
glfwSwapInterval( 1 );
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
// Enable sticky keys
|
// Enable sticky keys
|
||||||
glfwEnable( window, GLFW_STICKY_KEYS );
|
glfwEnable(window, GLFW_STICKY_KEYS);
|
||||||
|
|
||||||
// Enable mouse cursor (only needed for fullscreen mode)
|
// Enable mouse cursor (only needed for fullscreen mode)
|
||||||
glfwEnable( window, GLFW_MOUSE_CURSOR );
|
glfwEnable(window, GLFW_MOUSE_CURSOR);
|
||||||
|
|
||||||
// Set callback functions
|
// Set callback functions
|
||||||
glfwSetWindowSizeCallback( window, windowSizeFun );
|
glfwSetWindowSizeCallback(windowSizeFun);
|
||||||
glfwSetWindowRefreshCallback( window, windowRefreshFun );
|
glfwSetWindowRefreshCallback(windowRefreshFun);
|
||||||
glfwSetMousePosCallback( window, mousePosFun );
|
glfwSetMousePosCallback(mousePosFun);
|
||||||
glfwSetMouseButtonCallback( window, mouseButtonFun );
|
glfwSetMouseButtonCallback(mouseButtonFun);
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Only redraw if we need to
|
// Only redraw if we need to
|
||||||
if( do_redraw )
|
if (do_redraw)
|
||||||
{
|
{
|
||||||
// Draw all views
|
// Draw all views
|
||||||
drawAllViews();
|
drawAllViews();
|
||||||
|
@ -502,12 +492,12 @@ int main( void )
|
||||||
glfwWaitEvents();
|
glfwWaitEvents();
|
||||||
|
|
||||||
} // Check if the ESC key was pressed or the window was closed
|
} // Check if the ESC key was pressed or the window was closed
|
||||||
while( glfwIsWindow(window) &&
|
while (glfwIsWindow(window) &&
|
||||||
glfwGetKey(window, GLFW_KEY_ESC) != GLFW_PRESS );
|
glfwGetKey(window, GLFW_KEY_ESC) != GLFW_PRESS);
|
||||||
|
|
||||||
// Close OpenGL window and terminate GLFW
|
// Close OpenGL window and terminate GLFW
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
exit( EXIT_SUCCESS );
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,77 +6,75 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <GL/glfw3.h>
|
#include <GL/glfw3.h>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
int main( void )
|
|
||||||
{
|
{
|
||||||
int width, height, x;
|
int width, height, x;
|
||||||
double t;
|
|
||||||
GLFWwindow window;
|
GLFWwindow window;
|
||||||
|
|
||||||
// Initialise GLFW
|
// Initialise GLFW
|
||||||
if( !glfwInit() )
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Failed to initialize GLFW\n" );
|
fprintf(stderr, "Failed to initialize GLFW\n");
|
||||||
exit( EXIT_FAILURE );
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open a window and create its OpenGL context
|
// Open a window and create its OpenGL context
|
||||||
window = glfwOpenWindow( 640, 480, GLFW_WINDOWED, "Spinning Triangle", NULL );
|
window = glfwOpenWindow(640, 480, GLFW_WINDOWED, "Spinning Triangle", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
fprintf(stderr, "Failed to open GLFW window\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
glfwTerminate();
|
|
||||||
exit( EXIT_FAILURE );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we can capture the escape key being pressed below
|
// Ensure we can capture the escape key being pressed below
|
||||||
glfwEnable( window, GLFW_STICKY_KEYS );
|
glfwEnable(window, GLFW_STICKY_KEYS);
|
||||||
|
|
||||||
// Enable vertical sync (on cards that support it)
|
// Enable vertical sync (on cards that support it)
|
||||||
glfwSwapInterval( 1 );
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
t = glfwGetTime();
|
double t = glfwGetTime();
|
||||||
glfwGetMousePos( window, &x, NULL );
|
glfwGetMousePos(window, &x, NULL);
|
||||||
|
|
||||||
// Get window size (may be different than the requested size)
|
// Get window size (may be different than the requested size)
|
||||||
glfwGetWindowSize( window, &width, &height );
|
glfwGetWindowSize(window, &width, &height);
|
||||||
|
|
||||||
// Special case: avoid division by zero below
|
// Special case: avoid division by zero below
|
||||||
height = height > 0 ? height : 1;
|
height = height > 0 ? height : 1;
|
||||||
|
|
||||||
glViewport( 0, 0, width, height );
|
glViewport(0, 0, width, height);
|
||||||
|
|
||||||
// Clear color buffer to black
|
// Clear color buffer to black
|
||||||
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
glClear( GL_COLOR_BUFFER_BIT );
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
// Select and setup the projection matrix
|
// Select and setup the projection matrix
|
||||||
glMatrixMode( GL_PROJECTION );
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective( 65.0f, (GLfloat)width/(GLfloat)height, 1.0f, 100.0f );
|
gluPerspective(65.f, (GLfloat) width / (GLfloat) height, 1.f, 100.f);
|
||||||
|
|
||||||
// Select and setup the modelview matrix
|
// Select and setup the modelview matrix
|
||||||
glMatrixMode( GL_MODELVIEW );
|
glMatrixMode( GL_MODELVIEW );
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt( 0.0f, 1.0f, 0.0f, // Eye-position
|
gluLookAt(0.f, 1.f, 0.f, // Eye-position
|
||||||
0.0f, 20.0f, 0.0f, // View-point
|
0.f, 20.f, 0.f, // View-point
|
||||||
0.0f, 0.0f, 1.0f ); // Up-vector
|
0.f, 0.f, 1.f); // Up-vector
|
||||||
|
|
||||||
// Draw a rotating colorful triangle
|
// Draw a rotating colorful triangle
|
||||||
glTranslatef( 0.0f, 14.0f, 0.0f );
|
glTranslatef(0.f, 14.f, 0.f);
|
||||||
glRotatef( 0.3f*(GLfloat)x + (GLfloat)t*100.0f, 0.0f, 0.0f, 1.0f );
|
glRotatef(0.3f * (GLfloat) x + (GLfloat) t * 100.f, 0.f, 0.f, 1.f);
|
||||||
glBegin( GL_TRIANGLES );
|
|
||||||
glColor3f( 1.0f, 0.0f, 0.0f );
|
glBegin(GL_TRIANGLES);
|
||||||
glVertex3f( -5.0f, 0.0f, -4.0f );
|
glColor3f(1.f, 0.f, 0.f);
|
||||||
glColor3f( 0.0f, 1.0f, 0.0f );
|
glVertex3f(-5.f, 0.f, -4.f);
|
||||||
glVertex3f( 5.0f, 0.0f, -4.0f );
|
glColor3f(0.f, 1.f, 0.f);
|
||||||
glColor3f( 0.0f, 0.0f, 1.0f );
|
glVertex3f(5.f, 0.f, -4.f);
|
||||||
glVertex3f( 0.0f, 0.0f, 6.0f );
|
glColor3f(0.f, 0.f, 1.f);
|
||||||
|
glVertex3f(0.f, 0.f, 6.f);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
// Swap buffers
|
// Swap buffers
|
||||||
|
@ -84,12 +82,12 @@ int main( void )
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
} // Check if the ESC key was pressed or the window was closed
|
} // Check if the ESC key was pressed or the window was closed
|
||||||
while( glfwIsWindow(window) &&
|
while (glfwIsWindow(window) &&
|
||||||
glfwGetKey( window, GLFW_KEY_ESC ) != GLFW_PRESS );
|
glfwGetKey(window, GLFW_KEY_ESC) != GLFW_PRESS);
|
||||||
|
|
||||||
// Close OpenGL window and terminate GLFW
|
// Close OpenGL window and terminate GLFW
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
exit( EXIT_SUCCESS );
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
524
examples/wave.c
524
examples/wave.c
|
@ -5,6 +5,7 @@
|
||||||
* Modified for GLFW by Sylvain Hellegouarch - sh@programmationworld.com
|
* Modified for GLFW by Sylvain Hellegouarch - sh@programmationworld.com
|
||||||
* Modified for variable frame rate by Marcus Geelnard
|
* Modified for variable frame rate by Marcus Geelnard
|
||||||
* 2003-Jan-31: Minor cleanups and speedups / MG
|
* 2003-Jan-31: Minor cleanups and speedups / MG
|
||||||
|
* 2010-10-24: Formatting and cleanup - Camilla Berglund
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -16,33 +17,32 @@
|
||||||
#define M_PI 3.1415926535897932384626433832795
|
#define M_PI 3.1415926535897932384626433832795
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Maximum delta T to allow for differential calculations */
|
// Maximum delta T to allow for differential calculations
|
||||||
#define MAX_DELTA_T 0.01
|
#define MAX_DELTA_T 0.01
|
||||||
|
|
||||||
/* Animation speed (10.0 looks good) */
|
// Animation speed (10.0 looks good)
|
||||||
#define ANIMATION_SPEED 10.0
|
#define ANIMATION_SPEED 10.0
|
||||||
|
|
||||||
|
GLfloat alpha = 210.f, beta = -70.f;
|
||||||
|
GLfloat zoom = 2.f;
|
||||||
|
|
||||||
GLfloat alpha = 210.0f, beta = -70.0f;
|
GLboolean running = GL_TRUE;
|
||||||
GLfloat zoom = 2.0f;
|
|
||||||
|
|
||||||
int running = 1;
|
|
||||||
|
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
GLfloat x,y,z;
|
GLfloat x, y, z;
|
||||||
GLfloat r,g,b;
|
GLfloat r, g, b;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define GRIDW 50
|
#define GRIDW 50
|
||||||
#define GRIDH 50
|
#define GRIDH 50
|
||||||
#define VERTEXNUM (GRIDW*GRIDH)
|
#define VERTEXNUM (GRIDW*GRIDH)
|
||||||
|
|
||||||
#define QUADW (GRIDW-1)
|
#define QUADW (GRIDW - 1)
|
||||||
#define QUADH (GRIDH-1)
|
#define QUADH (GRIDH - 1)
|
||||||
#define QUADNUM (QUADW*QUADH)
|
#define QUADNUM (QUADW*QUADH)
|
||||||
|
|
||||||
GLuint quad[4*QUADNUM];
|
GLuint quad[4 * QUADNUM];
|
||||||
struct Vertex vertex[VERTEXNUM];
|
struct Vertex vertex[VERTEXNUM];
|
||||||
|
|
||||||
/* The grid will look like this:
|
/* The grid will look like this:
|
||||||
|
@ -56,47 +56,46 @@ struct Vertex vertex[VERTEXNUM];
|
||||||
* 0 1 2
|
* 0 1 2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void initVertices( void )
|
//========================================================================
|
||||||
|
// Initialize grid geometry
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void init_vertices(void)
|
||||||
{
|
{
|
||||||
int x,y,p;
|
int x, y, p;
|
||||||
|
|
||||||
/* place the vertices in a grid */
|
// Place the vertices in a grid
|
||||||
for(y=0;y<GRIDH;y++)
|
for (y = 0; y < GRIDH; y++)
|
||||||
for(x=0;x<GRIDW;x++)
|
|
||||||
{
|
{
|
||||||
p = y*GRIDW + x;
|
for (x = 0; x < GRIDW; x++)
|
||||||
|
{
|
||||||
|
p = y * GRIDW + x;
|
||||||
|
|
||||||
//vertex[p].x = (-GRIDW/2)+x+sin(2.0*M_PI*(double)y/(double)GRIDH);
|
vertex[p].x = (GLfloat) (x - GRIDW / 2) / (GLfloat) (GRIDW / 2);
|
||||||
//vertex[p].y = (-GRIDH/2)+y+cos(2.0*M_PI*(double)x/(double)GRIDW);
|
vertex[p].y = (GLfloat) (y - GRIDH / 2) / (GLfloat) (GRIDH / 2);
|
||||||
vertex[p].x = (GLfloat)(x-GRIDW/2)/(GLfloat)(GRIDW/2);
|
vertex[p].z = 0;
|
||||||
vertex[p].y = (GLfloat)(y-GRIDH/2)/(GLfloat)(GRIDH/2);
|
|
||||||
vertex[p].z = 0;//sin(d*M_PI);
|
|
||||||
//vertex[p].r = (GLfloat)x/(GLfloat)GRIDW;
|
|
||||||
//vertex[p].g = (GLfloat)y/(GLfloat)GRIDH;
|
|
||||||
//vertex[p].b = 1.0-((GLfloat)x/(GLfloat)GRIDW+(GLfloat)y/(GLfloat)GRIDH)/2.0;
|
|
||||||
if((x%4<2)^(y%4<2))
|
|
||||||
{
|
|
||||||
vertex[p].r = 0.0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vertex[p].r=1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
vertex[p].g = (GLfloat)y/(GLfloat)GRIDH;
|
if ((x % 4 < 2) ^ (y % 4 < 2))
|
||||||
vertex[p].b = 1.f-((GLfloat)x/(GLfloat)GRIDW+(GLfloat)y/(GLfloat)GRIDH)/2.f;
|
vertex[p].r = 0.0;
|
||||||
|
else
|
||||||
|
vertex[p].r = 1.0;
|
||||||
|
|
||||||
|
vertex[p].g = (GLfloat) y / (GLfloat) GRIDH;
|
||||||
|
vertex[p].b = 1.f - ((GLfloat) x / (GLfloat) GRIDW + (GLfloat) y / (GLfloat) GRIDH) / 2.f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(y=0;y<QUADH;y++)
|
for (y = 0; y < QUADH; y++)
|
||||||
for(x=0;x<QUADW;x++)
|
|
||||||
{
|
{
|
||||||
p = 4*(y*QUADW + x);
|
for (x = 0; x < QUADW; x++)
|
||||||
|
{
|
||||||
|
p = 4 * (y * QUADW + x);
|
||||||
|
|
||||||
/* first quad */
|
quad[p + 0] = y * GRIDW + x; // Some point
|
||||||
quad[p+0] = y *GRIDW+x; /* some point */
|
quad[p + 1] = y * GRIDW + x + 1; // Neighbor at the right side
|
||||||
quad[p+1] = y *GRIDW+x+1; /* neighbor at the right side */
|
quad[p + 2] = (y + 1) * GRIDW + x + 1; // Upper right neighbor
|
||||||
quad[p+2] = (y+1)*GRIDW+x+1; /* upper right neighbor */
|
quad[p + 3] = (y + 1) * GRIDW + x; // Upper neighbor
|
||||||
quad[p+3] = (y+1)*GRIDW+x; /* upper neighbor */
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,298 +104,287 @@ double p[GRIDW][GRIDH];
|
||||||
double vx[GRIDW][GRIDH], vy[GRIDW][GRIDH];
|
double vx[GRIDW][GRIDH], vy[GRIDW][GRIDH];
|
||||||
double ax[GRIDW][GRIDH], ay[GRIDW][GRIDH];
|
double ax[GRIDW][GRIDH], ay[GRIDW][GRIDH];
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Initialize grid
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void init_grid(void)
|
||||||
void initSurface( void )
|
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
double dx, dy, d;
|
double dx, dy, d;
|
||||||
|
|
||||||
for(y = 0; y<GRIDH; y++)
|
for (y = 0; y < GRIDH; y++)
|
||||||
{
|
|
||||||
for(x = 0; x<GRIDW; x++)
|
|
||||||
{
|
{
|
||||||
dx = (double)(x-GRIDW/2);
|
for (x = 0; x < GRIDW; x++)
|
||||||
dy = (double)(y-GRIDH/2);
|
{
|
||||||
d = sqrt( dx*dx + dy*dy );
|
dx = (double) (x - GRIDW / 2);
|
||||||
if(d < 0.1 * (double)(GRIDW/2))
|
dy = (double) (y - GRIDH / 2);
|
||||||
{
|
d = sqrt(dx * dx + dy * dy);
|
||||||
d = d * 10.0;
|
if (d < 0.1 * (double) (GRIDW / 2))
|
||||||
p[x][y] = -cos(d * (M_PI / (double)(GRIDW * 4))) * 100.0;
|
{
|
||||||
}
|
d = d * 10.0;
|
||||||
else
|
p[x][y] = -cos(d * (M_PI / (double)(GRIDW * 4))) * 100.0;
|
||||||
{
|
}
|
||||||
p[x][y] = 0.0;
|
else
|
||||||
}
|
p[x][y] = 0.0;
|
||||||
vx[x][y] = 0.0;
|
|
||||||
vy[x][y] = 0.0;
|
vx[x][y] = 0.0;
|
||||||
|
vy[x][y] = 0.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Draw view */
|
//========================================================================
|
||||||
void draw_screen( void )
|
// Draw scene
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void draw_scene(void)
|
||||||
{
|
{
|
||||||
/* Clear the color and depth buffers. */
|
// Clear the color and depth buffers
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
/* We don't want to modify the projection matrix. */
|
// We don't want to modify the projection matrix
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
/* Move back. */
|
// Move back
|
||||||
glTranslatef(0.0, 0.0, -zoom);
|
glTranslatef(0.0, 0.0, -zoom);
|
||||||
/* Rotate the view */
|
// Rotate the view
|
||||||
glRotatef(beta, 1.0, 0.0, 0.0);
|
glRotatef(beta, 1.0, 0.0, 0.0);
|
||||||
glRotatef(alpha, 0.0, 0.0, 1.0);
|
glRotatef(alpha, 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
//glDrawArrays(GL_POINTS,0,VERTEXNUM); /* Points only */
|
glDrawElements(GL_QUADS, 4 * QUADNUM, GL_UNSIGNED_INT, quad);
|
||||||
glDrawElements(GL_QUADS, 4*QUADNUM, GL_UNSIGNED_INT, quad);
|
|
||||||
//glDrawElements(GL_LINES, QUADNUM, GL_UNSIGNED_INT, quad);
|
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Initialize OpenGL */
|
//========================================================================
|
||||||
void setup_opengl( void )
|
// Initialize Miscellaneous OpenGL state
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void init_opengl(void)
|
||||||
{
|
{
|
||||||
/* Our shading model--Gouraud (smooth). */
|
// Use Gouraud (smooth) shading
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
|
|
||||||
/* Culling. */
|
// Switch on the z-buffer
|
||||||
//glCullFace(GL_BACK);
|
glEnable(GL_DEPTH_TEST);
|
||||||
//glFrontFace(GL_CCW);
|
|
||||||
//glEnable(GL_CULL_FACE);
|
|
||||||
|
|
||||||
/* Switch on the z-buffer. */
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
|
glVertexPointer(3, GL_FLOAT, sizeof(struct Vertex), vertex);
|
||||||
|
glColorPointer(3, GL_FLOAT, sizeof(struct Vertex), &vertex[0].r); // Pointer to the first color
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glPointSize(2.0);
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
|
||||||
glVertexPointer(3/*3 components per vertex (x,y,z)*/, GL_FLOAT, sizeof(struct Vertex), vertex);
|
|
||||||
glColorPointer(3/*3 components per vertex (r,g,b)*/, GL_FLOAT, sizeof(struct Vertex), &vertex[0].r); //Pointer to the first color
|
|
||||||
glPointSize(2.0);
|
|
||||||
|
|
||||||
/* Background color is black. */
|
// Background color is black
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Modify the height of each vertex according to the pressure. */
|
//========================================================================
|
||||||
void adjustGrid( void )
|
// Modify the height of each vertex according to the pressure
|
||||||
{
|
//========================================================================
|
||||||
int pos;
|
|
||||||
int x, y;
|
|
||||||
|
|
||||||
for(y = 0; y<GRIDH; y++)
|
void adjust_grid(void)
|
||||||
{
|
{
|
||||||
for(x = 0; x<GRIDW; x++)
|
int pos;
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
for (y = 0; y < GRIDH; y++)
|
||||||
{
|
{
|
||||||
pos = y*GRIDW + x;
|
for (x = 0; x < GRIDW; x++)
|
||||||
vertex[pos].z = (float) (p[x][y]*(1.0/50.0));
|
{
|
||||||
|
pos = y * GRIDW + x;
|
||||||
|
vertex[pos].z = (float) (p[x][y] * (1.0 / 50.0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Calculate wave propagation */
|
//========================================================================
|
||||||
void calc( void )
|
// Calculate wave propagation
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void calc_grid(void)
|
||||||
{
|
{
|
||||||
int x, y, x2, y2;
|
int x, y, x2, y2;
|
||||||
double time_step = dt * ANIMATION_SPEED;
|
double time_step = dt * ANIMATION_SPEED;
|
||||||
|
|
||||||
/* compute accelerations */
|
// Compute accelerations
|
||||||
for(x = 0; x < GRIDW; x++)
|
for (x = 0; x < GRIDW; x++)
|
||||||
{
|
|
||||||
x2 = (x + 1) % GRIDW;
|
|
||||||
for(y = 0; y < GRIDH; y++)
|
|
||||||
{
|
{
|
||||||
ax[x][y] = p[x][y] - p[x2][y];
|
x2 = (x + 1) % GRIDW;
|
||||||
|
for(y = 0; y < GRIDH; y++)
|
||||||
|
ax[x][y] = p[x][y] - p[x2][y];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for(y = 0; y < GRIDH;y++)
|
for (y = 0; y < GRIDH; y++)
|
||||||
{
|
|
||||||
y2 = (y + 1) % GRIDH;
|
|
||||||
for(x = 0; x < GRIDW; x++)
|
|
||||||
{
|
{
|
||||||
ay[x][y] = p[x][y] - p[x][y2];
|
y2 = (y + 1) % GRIDH;
|
||||||
|
for(x = 0; x < GRIDW; x++)
|
||||||
|
ay[x][y] = p[x][y] - p[x][y2];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* compute speeds */
|
// Compute speeds
|
||||||
for(x = 0; x < GRIDW; x++)
|
for (x = 0; x < GRIDW; x++)
|
||||||
{
|
|
||||||
for(y = 0; y < GRIDH; y++)
|
|
||||||
{
|
{
|
||||||
vx[x][y] = vx[x][y] + ax[x][y] * time_step;
|
for (y = 0; y < GRIDH; y++)
|
||||||
vy[x][y] = vy[x][y] + ay[x][y] * time_step;
|
{
|
||||||
|
vx[x][y] = vx[x][y] + ax[x][y] * time_step;
|
||||||
|
vy[x][y] = vy[x][y] + ay[x][y] * time_step;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* compute pressure */
|
// Compute pressure
|
||||||
for(x = 1; x < GRIDW; x++)
|
for (x = 1; x < GRIDW; x++)
|
||||||
{
|
|
||||||
x2 = x - 1;
|
|
||||||
for(y = 1; y < GRIDH; y++)
|
|
||||||
{
|
{
|
||||||
y2 = y - 1;
|
x2 = x - 1;
|
||||||
p[x][y] = p[x][y] + (vx[x2][y] - vx[x][y] + vy[x][y2] - vy[x][y]) * time_step;
|
for (y = 1; y < GRIDH; y++)
|
||||||
|
{
|
||||||
|
y2 = y - 1;
|
||||||
|
p[x][y] = p[x][y] + (vx[x2][y] - vx[x][y] + vy[x][y2] - vy[x][y]) * time_step;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Handle key strokes */
|
//========================================================================
|
||||||
void handle_key_down(GLFWwindow window, int key, int action)
|
// Handle key strokes
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void key_callback(GLFWwindow window, int key, int action)
|
||||||
{
|
{
|
||||||
if( action != GLFW_PRESS )
|
if (action != GLFW_PRESS)
|
||||||
{
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(key) {
|
switch (key)
|
||||||
case GLFW_KEY_ESC:
|
{
|
||||||
running = 0;
|
case GLFW_KEY_ESC:
|
||||||
break;
|
running = 0;
|
||||||
case GLFW_KEY_SPACE:
|
break;
|
||||||
initSurface();
|
case GLFW_KEY_SPACE:
|
||||||
break;
|
init_grid();
|
||||||
case GLFW_KEY_LEFT:
|
break;
|
||||||
alpha+=5;
|
case GLFW_KEY_LEFT:
|
||||||
break;
|
alpha += 5;
|
||||||
case GLFW_KEY_RIGHT:
|
break;
|
||||||
alpha-=5;
|
case GLFW_KEY_RIGHT:
|
||||||
break;
|
alpha -= 5;
|
||||||
case GLFW_KEY_UP:
|
break;
|
||||||
beta-=5;
|
case GLFW_KEY_UP:
|
||||||
break;
|
beta -= 5;
|
||||||
case GLFW_KEY_DOWN:
|
break;
|
||||||
beta+=5;
|
case GLFW_KEY_DOWN:
|
||||||
break;
|
beta += 5;
|
||||||
case GLFW_KEY_PAGEUP:
|
break;
|
||||||
if(zoom>1) zoom-=1;
|
case GLFW_KEY_PAGEUP:
|
||||||
break;
|
if (zoom > 1)
|
||||||
case GLFW_KEY_PAGEDOWN:
|
zoom -= 1;
|
||||||
zoom+=1;
|
break;
|
||||||
break;
|
case GLFW_KEY_PAGEDOWN:
|
||||||
default:
|
zoom += 1;
|
||||||
break;
|
break;
|
||||||
}
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Callback function for window resize events */
|
//========================================================================
|
||||||
void handle_resize( GLFWwindow window, int width, int height )
|
// Callback function for window resize events
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void window_resize_callback(GLFWwindow window, int width, int height)
|
||||||
{
|
{
|
||||||
float ratio = 1.0f;
|
float ratio = 1.f;
|
||||||
|
|
||||||
if( height > 0 )
|
if (height > 0)
|
||||||
{
|
ratio = (float) width / (float) height;
|
||||||
ratio = (float) width / (float) height;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Setup viewport (Place where the stuff will appear in the main window). */
|
// Setup viewport
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
|
|
||||||
/*
|
// Change to the projection matrix and set our viewing volume
|
||||||
* Change to the projection matrix and set
|
glMatrixMode(GL_PROJECTION);
|
||||||
* our viewing volume.
|
glLoadIdentity();
|
||||||
*/
|
gluPerspective(60.0, ratio, 1.0, 1024.0);
|
||||||
glMatrixMode(GL_PROJECTION);
|
|
||||||
glLoadIdentity();
|
|
||||||
gluPerspective(60.0, ratio, 1.0, 1024.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Program entry point */
|
//========================================================================
|
||||||
|
// main
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
/* Dimensions of our window. */
|
GLFWwindow window;
|
||||||
int width, height;
|
double t, dt_total, t_old;
|
||||||
/* Style of our window. */
|
|
||||||
int mode;
|
|
||||||
/* Frame time */
|
|
||||||
double t, t_old, dt_total;
|
|
||||||
GLFWwindow window;
|
|
||||||
|
|
||||||
/* Initialize GLFW */
|
if (!glfwInit())
|
||||||
if(glfwInit() == GL_FALSE)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "GLFW initialization failed\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Desired window properties */
|
|
||||||
width = 640;
|
|
||||||
height = 480;
|
|
||||||
mode = GLFW_WINDOWED;
|
|
||||||
|
|
||||||
glfwOpenWindowHint(GLFW_DEPTH_BITS, 16);
|
|
||||||
|
|
||||||
/* Open window */
|
|
||||||
window = glfwOpenWindow(width, height, mode, "Wave Simulation", NULL);
|
|
||||||
if (!window)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Could not open window\n");
|
|
||||||
glfwTerminate();
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
glfwSwapInterval( 1 );
|
|
||||||
|
|
||||||
/* Keyboard handler */
|
|
||||||
glfwSetKeyCallback( window, handle_key_down );
|
|
||||||
glfwEnable( window, GLFW_KEY_REPEAT );
|
|
||||||
|
|
||||||
/* Window resize handler */
|
|
||||||
glfwSetWindowSizeCallback( window, handle_resize );
|
|
||||||
|
|
||||||
/* Initialize OpenGL */
|
|
||||||
setup_opengl();
|
|
||||||
|
|
||||||
/* Initialize simulation */
|
|
||||||
initVertices();
|
|
||||||
initSurface();
|
|
||||||
adjustGrid();
|
|
||||||
|
|
||||||
/* Initialize timer */
|
|
||||||
t_old = glfwGetTime() - 0.01;
|
|
||||||
|
|
||||||
/* Main loop */
|
|
||||||
while(running)
|
|
||||||
{
|
|
||||||
/* Timing */
|
|
||||||
t = glfwGetTime();
|
|
||||||
dt_total = t - t_old;
|
|
||||||
t_old = t;
|
|
||||||
|
|
||||||
/* Safety - iterate if dt_total is too large */
|
|
||||||
while( dt_total > 0.0f )
|
|
||||||
{
|
{
|
||||||
/* Select iteration time step */
|
fprintf(stderr, "GLFW initialization failed\n");
|
||||||
dt = dt_total > MAX_DELTA_T ? MAX_DELTA_T : dt_total;
|
exit(EXIT_FAILURE);
|
||||||
dt_total -= dt;
|
|
||||||
|
|
||||||
/* Calculate wave propagation */
|
|
||||||
calc();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compute height of each vertex */
|
window = glfwOpenWindow(640, 480, GLFW_WINDOWED, "Wave Simulation", NULL);
|
||||||
adjustGrid();
|
if (!window)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Could not open window\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/* Draw wave grid to OpenGL display */
|
glfwSwapInterval(1);
|
||||||
draw_screen();
|
|
||||||
|
|
||||||
glfwPollEvents();
|
// Keyboard handler
|
||||||
|
glfwSetKeyCallback(key_callback);
|
||||||
|
glfwEnable(window, GLFW_KEY_REPEAT);
|
||||||
|
|
||||||
/* Still running? */
|
// Window resize handler
|
||||||
running = running && glfwIsWindow( window );
|
glfwSetWindowSizeCallback(window_resize_callback);
|
||||||
}
|
|
||||||
|
|
||||||
glfwTerminate();
|
// Initialize OpenGL
|
||||||
|
init_opengl();
|
||||||
|
|
||||||
return 0;
|
// Initialize simulation
|
||||||
|
init_vertices();
|
||||||
|
init_grid();
|
||||||
|
adjust_grid();
|
||||||
|
|
||||||
|
// Initialize timer
|
||||||
|
t_old = glfwGetTime() - 0.01;
|
||||||
|
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
t = glfwGetTime();
|
||||||
|
dt_total = t - t_old;
|
||||||
|
t_old = t;
|
||||||
|
|
||||||
|
// Safety - iterate if dt_total is too large
|
||||||
|
while (dt_total > 0.f)
|
||||||
|
{
|
||||||
|
// Select iteration time step
|
||||||
|
dt = dt_total > MAX_DELTA_T ? MAX_DELTA_T : dt_total;
|
||||||
|
dt_total -= dt;
|
||||||
|
|
||||||
|
// Calculate wave propagation
|
||||||
|
calc_grid();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute height of each vertex
|
||||||
|
adjust_grid();
|
||||||
|
|
||||||
|
// Draw wave grid to OpenGL display
|
||||||
|
draw_scene();
|
||||||
|
|
||||||
|
glfwPollEvents();
|
||||||
|
|
||||||
|
// Still running?
|
||||||
|
running = running && glfwIsWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -442,11 +442,11 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow window);
|
||||||
GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param);
|
GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param);
|
||||||
GLFWAPI void glfwSetWindowUserPointer(GLFWwindow window, void* pointer);
|
GLFWAPI void glfwSetWindowUserPointer(GLFWwindow window, void* pointer);
|
||||||
GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window);
|
GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window);
|
||||||
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun);
|
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun);
|
||||||
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun);
|
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindowclosefun cbfun);
|
||||||
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun);
|
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindowrefreshfun cbfun);
|
||||||
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cbfun);
|
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindowfocusfun cbfun);
|
||||||
GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow window, GLFWwindowiconifyfun cbfun);
|
GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindowiconifyfun cbfun);
|
||||||
|
|
||||||
/* Event handling */
|
/* Event handling */
|
||||||
GLFWAPI void glfwPollEvents(void);
|
GLFWAPI void glfwPollEvents(void);
|
||||||
|
@ -458,11 +458,11 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button);
|
||||||
GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos);
|
GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos);
|
||||||
GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos);
|
GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos);
|
||||||
GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* x, int* y);
|
GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* x, int* y);
|
||||||
GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun);
|
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun);
|
||||||
GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun);
|
GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun);
|
||||||
GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cbfun);
|
GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun);
|
||||||
GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun);
|
GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun);
|
||||||
GLFWAPI void glfwSetScrollCallback(GLFWwindow window, GLFWscrollfun cbfun);
|
GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun);
|
||||||
|
|
||||||
/* Joystick input */
|
/* Joystick input */
|
||||||
GLFWAPI int glfwGetJoystickParam(int joy, int param);
|
GLFWAPI int glfwGetJoystickParam(int joy, int param);
|
||||||
|
|
|
@ -1,42 +1,37 @@
|
||||||
|
|
||||||
configure_file(
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake
|
${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY)
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY)
|
|
||||||
|
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${GLFW_SOURCE_DIR}/src
|
${GLFW_SOURCE_DIR}/src
|
||||||
${GLFW_BINARY_DIR}/src
|
${GLFW_BINARY_DIR}/src
|
||||||
${GLFW_INCLUDE_DIR})
|
${GLFW_INCLUDE_DIR})
|
||||||
|
|
||||||
set(cocoa_SOURCES
|
set(cocoa_SOURCES cocoa_enable.m
|
||||||
cocoa_enable.m
|
cocoa_fullscreen.m
|
||||||
cocoa_fullscreen.m
|
cocoa_gamma.m
|
||||||
cocoa_gamma.m
|
cocoa_glext.m
|
||||||
cocoa_glext.m
|
cocoa_init.m
|
||||||
cocoa_init.m
|
cocoa_joystick.m
|
||||||
cocoa_joystick.m
|
cocoa_time.m
|
||||||
cocoa_time.m
|
cocoa_window.m)
|
||||||
cocoa_window.m)
|
|
||||||
|
|
||||||
# For some reason, CMake doesn't know about .m
|
# For some reason, CMake doesn't know about .m
|
||||||
set_source_files_properties(${cocoa_SOURCES} PROPERTIES LANGUAGE C)
|
set_source_files_properties(${cocoa_SOURCES} PROPERTIES LANGUAGE C)
|
||||||
|
|
||||||
set(libglfw_SOURCES
|
set(libglfw_SOURCES ${common_SOURCES} ${cocoa_SOURCES})
|
||||||
${common_SOURCES}
|
|
||||||
${cocoa_SOURCES})
|
|
||||||
|
|
||||||
add_library(libglfwStatic STATIC ${libglfw_SOURCES})
|
add_library(libglfwStatic STATIC ${libglfw_SOURCES})
|
||||||
add_library(libglfwShared SHARED ${libglfw_SOURCES})
|
add_library(libglfwShared SHARED ${libglfw_SOURCES})
|
||||||
target_link_libraries(libglfwShared ${GLFW_LIBRARIES})
|
target_link_libraries(libglfwShared ${GLFW_LIBRARIES})
|
||||||
set_target_properties(libglfwStatic libglfwShared PROPERTIES
|
set_target_properties(libglfwStatic libglfwShared PROPERTIES
|
||||||
CLEAN_DIRECT_OUTPUT 1
|
CLEAN_DIRECT_OUTPUT 1
|
||||||
OUTPUT_NAME glfw
|
OUTPUT_NAME glfw)
|
||||||
)
|
|
||||||
|
|
||||||
# Append -fno-common to the compile flags to work around a bug in the Apple GCC
|
# Append -fno-common to the compile flags to work around a bug in the Apple GCC
|
||||||
get_target_property(CFLAGS libglfwShared COMPILE_FLAGS)
|
get_target_property(CFLAGS libglfwShared COMPILE_FLAGS)
|
||||||
if(NOT CFLAGS)
|
if(NOT CFLAGS)
|
||||||
set(CFLAGS "")
|
set(CFLAGS "")
|
||||||
endif(NOT CFLAGS)
|
endif(NOT CFLAGS)
|
||||||
set_target_properties(libglfwShared PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common")
|
set_target_properties(libglfwShared PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common")
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,8 @@
|
||||||
window->width = contentRect.size.width;
|
window->width = contentRect.size.width;
|
||||||
window->height = contentRect.size.height;
|
window->height = contentRect.size.height;
|
||||||
|
|
||||||
if (window->windowSizeCallback)
|
if (_glfwLibrary.windowSizeCallback)
|
||||||
window->windowSizeCallback(window, window->width, window->height);
|
_glfwLibrary.windowSizeCallback(window, window->width, window->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidMove:(NSNotification *)notification
|
- (void)windowDidMove:(NSNotification *)notification
|
||||||
|
@ -95,16 +95,16 @@
|
||||||
{
|
{
|
||||||
window->iconified = GL_TRUE;
|
window->iconified = GL_TRUE;
|
||||||
|
|
||||||
if (window->windowIconifyCallback)
|
if (_glfwLibrary.windowIconifyCallback)
|
||||||
window->windowIconifyCallback(window, window->iconified);
|
_glfwLibrary.windowIconifyCallback(window, window->iconified);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidDeminiaturize:(NSNotification *)notification
|
- (void)windowDidDeminiaturize:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
window->iconified = GL_FALSE;
|
window->iconified = GL_FALSE;
|
||||||
|
|
||||||
if (window->windowIconifyCallback)
|
if (_glfwLibrary.windowIconifyCallback)
|
||||||
window->windowIconifyCallback(window, window->iconified);
|
_glfwLibrary.windowIconifyCallback(window, window->iconified);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidBecomeKey:(NSNotification *)notification
|
- (void)windowDidBecomeKey:(NSNotification *)notification
|
||||||
|
@ -362,8 +362,8 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
window->mousePosY = [[window->NS.window contentView] bounds].size.height - p.y;
|
window->mousePosY = [[window->NS.window contentView] bounds].size.height - p.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window->mousePosCallback)
|
if (_glfwLibrary.mousePosCallback)
|
||||||
window->mousePosCallback(window, window->mousePosX, window->mousePosY);
|
_glfwLibrary.mousePosCallback(window, window->mousePosX, window->mousePosY);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)rightMouseDown:(NSEvent *)event
|
- (void)rightMouseDown:(NSEvent *)event
|
||||||
|
|
|
@ -54,11 +54,11 @@ static void enableMouseCursor(_GLFWwindow* window)
|
||||||
window->mousePosX = centerPosX;
|
window->mousePosX = centerPosX;
|
||||||
window->mousePosY = centerPosY;
|
window->mousePosY = centerPosY;
|
||||||
|
|
||||||
if (window->mousePosCallback)
|
if (_glfwLibrary.mousePosCallback)
|
||||||
{
|
{
|
||||||
window->mousePosCallback(window,
|
_glfwLibrary.mousePosCallback(window,
|
||||||
window->mousePosX,
|
window->mousePosX,
|
||||||
window->mousePosY);
|
window->mousePosY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ GLFWAPI void glfwSetGammaFormula(float gamma, float blacklevel, float gain)
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Return the currently set gamma ramp
|
// Return the cached currently set gamma ramp
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwGetGammaRamp(GLFWgammaramp* ramp)
|
GLFWAPI void glfwGetGammaRamp(GLFWgammaramp* ramp)
|
||||||
|
|
32
src/input.c
32
src/input.c
|
@ -171,7 +171,7 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* x, int* y)
|
||||||
// Set callback function for keyboard input
|
// Set callback function for keyboard input
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun)
|
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
@ -179,7 +179,7 @@ GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->keyCallback = cbfun;
|
_glfwLibrary.keyCallback = cbfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun)
|
||||||
// Set callback function for character input
|
// Set callback function for character input
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun)
|
GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
@ -195,7 +195,7 @@ GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->charCallback = cbfun;
|
_glfwLibrary.charCallback = cbfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun)
|
||||||
// Set callback function for mouse clicks
|
// Set callback function for mouse clicks
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cbfun)
|
GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
@ -211,7 +211,7 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cb
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->mouseButtonCallback = cbfun;
|
_glfwLibrary.mouseButtonCallback = cbfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cb
|
||||||
// Set callback function for mouse moves
|
// Set callback function for mouse moves
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun)
|
GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
@ -228,12 +228,17 @@ GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set callback function
|
// Set callback function
|
||||||
window->mousePosCallback = cbfun;
|
_glfwLibrary.mousePosCallback = cbfun;
|
||||||
|
|
||||||
// Call the callback function to let the application know the current
|
// Call the callback function to let the application know the current
|
||||||
// mouse position
|
// mouse position
|
||||||
if (cbfun)
|
if (cbfun)
|
||||||
cbfun(window, window->mousePosX, window->mousePosY);
|
{
|
||||||
|
_GLFWwindow* window;
|
||||||
|
|
||||||
|
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
||||||
|
cbfun(window, window->mousePosX, window->mousePosY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -241,7 +246,7 @@ GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun)
|
||||||
// Set callback function for scroll events
|
// Set callback function for scroll events
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetScrollCallback(GLFWwindow window, GLFWscrollfun cbfun)
|
GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
@ -250,11 +255,6 @@ GLFWAPI void glfwSetScrollCallback(GLFWwindow window, GLFWscrollfun cbfun)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set callback function
|
// Set callback function
|
||||||
window->scrollCallback = cbfun;
|
_glfwLibrary.scrollCallback = cbfun;
|
||||||
|
|
||||||
// Call the callback function to let the application know the current
|
|
||||||
// scroll offset
|
|
||||||
if (cbfun)
|
|
||||||
cbfun(window, window->scrollX, window->scrollY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,18 +152,6 @@ struct _GLFWwindow
|
||||||
{
|
{
|
||||||
struct _GLFWwindow* next;
|
struct _GLFWwindow* next;
|
||||||
|
|
||||||
// User callback functions
|
|
||||||
GLFWwindowsizefun windowSizeCallback;
|
|
||||||
GLFWwindowclosefun windowCloseCallback;
|
|
||||||
GLFWwindowrefreshfun windowRefreshCallback;
|
|
||||||
GLFWwindowfocusfun windowFocusCallback;
|
|
||||||
GLFWwindowiconifyfun windowIconifyCallback;
|
|
||||||
GLFWmousebuttonfun mouseButtonCallback;
|
|
||||||
GLFWmouseposfun mousePosCallback;
|
|
||||||
GLFWscrollfun scrollCallback;
|
|
||||||
GLFWkeyfun keyCallback;
|
|
||||||
GLFWcharfun charCallback;
|
|
||||||
|
|
||||||
// Window settings and state
|
// Window settings and state
|
||||||
GLboolean iconified; // GL_TRUE if this window is iconified
|
GLboolean iconified; // GL_TRUE if this window is iconified
|
||||||
GLboolean closeRequested; // GL_TRUE if this window should be closed
|
GLboolean closeRequested; // GL_TRUE if this window should be closed
|
||||||
|
@ -223,6 +211,17 @@ struct _GLFWlibrary
|
||||||
_GLFWwindow* activeWindow;
|
_GLFWwindow* activeWindow;
|
||||||
_GLFWwindow* cursorLockWindow;
|
_GLFWwindow* cursorLockWindow;
|
||||||
|
|
||||||
|
GLFWwindowsizefun windowSizeCallback;
|
||||||
|
GLFWwindowclosefun windowCloseCallback;
|
||||||
|
GLFWwindowrefreshfun windowRefreshCallback;
|
||||||
|
GLFWwindowfocusfun windowFocusCallback;
|
||||||
|
GLFWwindowiconifyfun windowIconifyCallback;
|
||||||
|
GLFWmousebuttonfun mouseButtonCallback;
|
||||||
|
GLFWmouseposfun mousePosCallback;
|
||||||
|
GLFWscrollfun scrollCallback;
|
||||||
|
GLFWkeyfun keyCallback;
|
||||||
|
GLFWcharfun charCallback;
|
||||||
|
|
||||||
GLFWgammaramp currentRamp;
|
GLFWgammaramp currentRamp;
|
||||||
GLFWgammaramp originalRamp;
|
GLFWgammaramp originalRamp;
|
||||||
int originalRampSize;
|
int originalRampSize;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
if(CYGWIN)
|
if(CYGWIN)
|
||||||
configure_file(
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY)
|
${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY)
|
||||||
|
|
||||||
# These lines are intended to remove the --export-all-symbols
|
# These lines are intended to remove the --export-all-symbols
|
||||||
# flag added in the Modules/Platform/CYGWIN.cmake file of the
|
# flag added in the Modules/Platform/CYGWIN.cmake file of the
|
||||||
|
@ -19,36 +19,36 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${GLFW_BINARY_DIR}/src
|
${GLFW_BINARY_DIR}/src
|
||||||
${GLFW_INCLUDE_DIR})
|
${GLFW_INCLUDE_DIR})
|
||||||
|
|
||||||
set(libglfw_SOURCES
|
set(libglfw_SOURCES ${common_SOURCES}
|
||||||
${common_SOURCES}
|
win32_enable.c
|
||||||
win32_enable.c
|
win32_fullscreen.c
|
||||||
win32_fullscreen.c
|
win32_gamma.c
|
||||||
win32_gamma.c
|
win32_glext.c
|
||||||
win32_glext.c
|
win32_init.c
|
||||||
win32_init.c
|
win32_joystick.c
|
||||||
win32_joystick.c
|
win32_time.c
|
||||||
win32_time.c
|
win32_window.c
|
||||||
win32_window.c
|
win32_dllmain.c)
|
||||||
win32_dllmain.c)
|
|
||||||
|
|
||||||
add_library(libglfwStatic STATIC ${libglfw_SOURCES})
|
add_library(libglfwStatic STATIC ${libglfw_SOURCES})
|
||||||
add_library(libglfwShared SHARED ${libglfw_SOURCES})
|
add_library(libglfwShared SHARED ${libglfw_SOURCES})
|
||||||
|
|
||||||
target_link_libraries(libglfwShared ${OPENGL_gl_LIBRARY})
|
target_link_libraries(libglfwShared ${OPENGL_gl_LIBRARY})
|
||||||
set_target_properties(libglfwShared PROPERTIES
|
set_target_properties(libglfwShared PROPERTIES
|
||||||
DEFINE_SYMBOL GLFW_BUILD_DLL
|
DEFINE_SYMBOL GLFW_BUILD_DLL
|
||||||
PREFIX ""
|
PREFIX ""
|
||||||
IMPORT_PREFIX ""
|
IMPORT_PREFIX ""
|
||||||
IMPORT_SUFFIX "dll.lib")
|
IMPORT_SUFFIX "dll.lib")
|
||||||
|
|
||||||
set_target_properties(libglfwStatic libglfwShared PROPERTIES
|
set_target_properties(libglfwStatic libglfwShared PROPERTIES
|
||||||
CLEAN_DIRECT_OUTPUT 1
|
CLEAN_DIRECT_OUTPUT 1
|
||||||
OUTPUT_NAME glfw)
|
OUTPUT_NAME glfw)
|
||||||
|
|
||||||
if(CYGWIN)
|
if(CYGWIN)
|
||||||
# Build for the regular Win32 environment (not Cygwin)
|
# Build for the regular Win32 environment (not Cygwin)
|
||||||
set_target_properties(libglfwStatic libglfwShared PROPERTIES COMPILE_FLAGS "-mwin32 -mno-cygwin")
|
set_target_properties(libglfwStatic libglfwShared PROPERTIES
|
||||||
set_target_properties(libglfwStatic libglfwShared PROPERTIES LINK_FLAGS "-mwin32 -mno-cygwin")
|
COMPILE_FLAGS "-mwin32 -mno-cygwin"
|
||||||
|
LINK_FLAGS "-mwin32 -mno-cygwin")
|
||||||
endif(CYGWIN)
|
endif(CYGWIN)
|
||||||
|
|
||||||
install(TARGETS libglfwStatic libglfwShared DESTINATION lib)
|
install(TARGETS libglfwStatic libglfwShared DESTINATION lib)
|
||||||
|
|
|
@ -270,7 +270,6 @@ typedef struct _GLFWlibraryWin32
|
||||||
ATOM classAtom; // Window class atom
|
ATOM classAtom; // Window class atom
|
||||||
HHOOK keyboardHook; // Keyboard hook handle
|
HHOOK keyboardHook; // Keyboard hook handle
|
||||||
DWORD foregroundLockTimeout;
|
DWORD foregroundLockTimeout;
|
||||||
HDC desktopDC;
|
|
||||||
|
|
||||||
// Default monitor
|
// Default monitor
|
||||||
struct {
|
struct {
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL framework
|
// GLFW - An OpenGL framework
|
||||||
// Platform: Win32/WGL
|
// Platform: Win32/WGL
|
||||||
// API version: 2.7
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
// Copyright (c) 2002-2006 Marcus Geelnard
|
// Copyright (c) 2010 Camilla Berglund <elmindreda@elmindreda.org>
|
||||||
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
|
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied
|
// This software is provided 'as-is', without any express or implied
|
||||||
// warranty. In no event will the authors be held liable for any damages
|
// warranty. In no event will the authors be held liable for any damages
|
||||||
|
@ -33,35 +32,26 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
|
||||||
//************************************************************************
|
//////////////////////////////////////////////////////////////////////////
|
||||||
//**** GLFW internal functions ****
|
////// GLFW platform API //////
|
||||||
//************************************************************************
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Save the gamma ramp to our internal copy
|
// Retrieve the currently set gamma ramp
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSaveGammaRamp(int ramp)
|
void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
|
||||||
{
|
{
|
||||||
if (!_glfwLibrary.gammaSize)
|
_glfw_GetDeviceGammaRamp(GetDC(GetDesktopWindow()), (WORD*) ramp);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_glfw_GetDeviceGammaRamp(_glfwLibrary.Win32.desktopDC,
|
|
||||||
_glfwLibrary.gammaRamp[ramp]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Restore the gamma ramp to our internal copy of the gamma ramp
|
// Push the specified gamma ramp to the monitor
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformRestoreGammaRamp(int ramp)
|
void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp)
|
||||||
{
|
{
|
||||||
if (!_glfwLibrary.gammaSize)
|
_glfw_SetDeviceGammaRamp(GetDC(GetDesktopWindow()), (WORD*) ramp);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_glfw_SetDeviceGammaRamp(_glfwLibrary.Win32.desktopDC,
|
|
||||||
_glfwLibrary.gammaRamp[ramp]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,18 +160,9 @@ int _glfwPlatformInit(void)
|
||||||
|
|
||||||
_glfwLibrary.Win32.instance = GetModuleHandle(NULL);
|
_glfwLibrary.Win32.instance = GetModuleHandle(NULL);
|
||||||
|
|
||||||
// Initialise the internal gamma ramp
|
|
||||||
_glfwLibrary.gammaSize = 256;
|
|
||||||
_glfwLibrary.gammaRamp[GLFW_GAMMA_ORIG] =
|
|
||||||
malloc(256 * sizeof(unsigned short) * 3);
|
|
||||||
_glfwLibrary.gammaRamp[GLFW_GAMMA_CURR] =
|
|
||||||
malloc(256 * sizeof(unsigned short) * 3);
|
|
||||||
|
|
||||||
// Get the desktop DC
|
|
||||||
_glfwLibrary.Win32.desktopDC = GetDC(GetDesktopWindow());
|
|
||||||
|
|
||||||
// Save the original gamma ramp
|
// Save the original gamma ramp
|
||||||
_glfwPlatformSaveGammaRamp(GLFW_GAMMA_ORIG);
|
_glfwLibrary.originalRampSize = 256;
|
||||||
|
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
||||||
|
|
||||||
_glfwInitTimer();
|
_glfwInitTimer();
|
||||||
|
|
||||||
|
@ -186,11 +177,7 @@ int _glfwPlatformInit(void)
|
||||||
int _glfwPlatformTerminate(void)
|
int _glfwPlatformTerminate(void)
|
||||||
{
|
{
|
||||||
// Restore the original gamma ramp
|
// Restore the original gamma ramp
|
||||||
_glfwPlatformRestoreGammaRamp(GLFW_GAMMA_ORIG);
|
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp);
|
||||||
|
|
||||||
// Free the gamma ramps
|
|
||||||
free(_glfwLibrary.gammaRamp[GLFW_GAMMA_ORIG]);
|
|
||||||
free(_glfwLibrary.gammaRamp[GLFW_GAMMA_CURR]);
|
|
||||||
|
|
||||||
if (_glfwLibrary.Win32.classAtom)
|
if (_glfwLibrary.Win32.classAtom)
|
||||||
{
|
{
|
||||||
|
|
|
@ -713,8 +713,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||||
{
|
{
|
||||||
window->iconified = iconified;
|
window->iconified = iconified;
|
||||||
|
|
||||||
if (window->windowIconifyCallback)
|
if (_glfwLibrary.windowIconifyCallback)
|
||||||
window->windowIconifyCallback(window, window->iconified);
|
_glfwLibrary.windowIconifyCallback(window, window->iconified);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -756,7 +756,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||||
{
|
{
|
||||||
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS);
|
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS);
|
||||||
|
|
||||||
if (window->charCallback)
|
if (_glfwLibrary.charCallback)
|
||||||
translateChar(window, (DWORD) wParam, (DWORD) lParam);
|
translateChar(window, (DWORD) wParam, (DWORD) lParam);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -879,11 +879,11 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||||
window->Win32.oldMouseY = newMouseY;
|
window->Win32.oldMouseY = newMouseY;
|
||||||
window->Win32.mouseMoved = GL_TRUE;
|
window->Win32.mouseMoved = GL_TRUE;
|
||||||
|
|
||||||
if (window->mousePosCallback)
|
if (_glfwLibrary.mousePosCallback)
|
||||||
{
|
{
|
||||||
window->mousePosCallback(window,
|
_glfwLibrary.mousePosCallback(window,
|
||||||
window->mousePosX,
|
window->mousePosX,
|
||||||
window->mousePosY);
|
window->mousePosY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -917,8 +917,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||||
ClipCursor(&ClipWindowRect);
|
ClipCursor(&ClipWindowRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window->windowSizeCallback)
|
if (_glfwLibrary.windowSizeCallback)
|
||||||
window->windowSizeCallback(window, window->width, window->height);
|
_glfwLibrary.windowSizeCallback(window, window->width, window->height);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -941,8 +941,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||||
// Was the window contents damaged?
|
// Was the window contents damaged?
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
{
|
||||||
if (window->windowRefreshCallback)
|
if (_glfwLibrary.windowRefreshCallback)
|
||||||
window->windowRefreshCallback(window);
|
_glfwLibrary.windowRefreshCallback(window);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
55
src/window.c
55
src/window.c
|
@ -55,8 +55,8 @@ static void closeFlaggedWindows(void)
|
||||||
|
|
||||||
for (window = _glfwLibrary.windowListHead; window; )
|
for (window = _glfwLibrary.windowListHead; window; )
|
||||||
{
|
{
|
||||||
if (window->closeRequested && window->windowCloseCallback)
|
if (window->closeRequested && _glfwLibrary.windowCloseCallback)
|
||||||
window->closeRequested = window->windowCloseCallback(window);
|
window->closeRequested = _glfwLibrary.windowCloseCallback(window);
|
||||||
|
|
||||||
if (window->closeRequested)
|
if (window->closeRequested)
|
||||||
{
|
{
|
||||||
|
@ -144,8 +144,8 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call user callback function
|
// Call user callback function
|
||||||
if (window->keyCallback && (window->keyRepeat || !keyrepeat))
|
if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat))
|
||||||
window->keyCallback(window, key, action);
|
_glfwLibrary.keyCallback(window, key, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,8 +159,8 @@ void _glfwInputChar(_GLFWwindow* window, int character)
|
||||||
if (!((character >= 32 && character <= 126) || character >= 160))
|
if (!((character >= 32 && character <= 126) || character >= 160))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (window->charCallback)
|
if (_glfwLibrary.charCallback)
|
||||||
window->charCallback(window, character);
|
_glfwLibrary.charCallback(window, character);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -173,8 +173,8 @@ void _glfwInputScroll(_GLFWwindow* window, int x, int y)
|
||||||
window->scrollX += x;
|
window->scrollX += x;
|
||||||
window->scrollY += y;
|
window->scrollY += y;
|
||||||
|
|
||||||
if (window->scrollCallback)
|
if (_glfwLibrary.scrollCallback)
|
||||||
window->scrollCallback(window, x, y);
|
_glfwLibrary.scrollCallback(window, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,8 +193,8 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
|
||||||
else
|
else
|
||||||
window->mouseButton[button] = (char) action;
|
window->mouseButton[button] = (char) action;
|
||||||
|
|
||||||
if (window->mouseButtonCallback)
|
if (_glfwLibrary.mouseButtonCallback)
|
||||||
window->mouseButtonCallback(window, button, action);
|
_glfwLibrary.mouseButtonCallback(window, button, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,8 +210,8 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated)
|
||||||
{
|
{
|
||||||
_glfwLibrary.activeWindow = window;
|
_glfwLibrary.activeWindow = window;
|
||||||
|
|
||||||
if (window->windowFocusCallback)
|
if (_glfwLibrary.windowFocusCallback)
|
||||||
window->windowFocusCallback(window, activated);
|
_glfwLibrary.windowFocusCallback(window, activated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -236,8 +236,8 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated)
|
||||||
|
|
||||||
_glfwLibrary.activeWindow = NULL;
|
_glfwLibrary.activeWindow = NULL;
|
||||||
|
|
||||||
if (window->windowFocusCallback)
|
if (_glfwLibrary.windowFocusCallback)
|
||||||
window->windowFocusCallback(window, activated);
|
_glfwLibrary.windowFocusCallback(window, activated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1076,7 +1076,7 @@ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window)
|
||||||
// Set callback function for window size changes
|
// Set callback function for window size changes
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun)
|
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
@ -1084,19 +1084,24 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfu
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->windowSizeCallback = cbfun;
|
_glfwLibrary.windowSizeCallback = cbfun;
|
||||||
|
|
||||||
// Call the callback function to let the application know the current
|
// Call the callback function to let the application know the current
|
||||||
// window size
|
// window size
|
||||||
if (cbfun)
|
if (cbfun)
|
||||||
cbfun(window, window->width, window->height);
|
{
|
||||||
|
_GLFWwindow* window;
|
||||||
|
|
||||||
|
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
||||||
|
cbfun(window, window->width, window->height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set callback function for window close events
|
// Set callback function for window close events
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun)
|
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindowclosefun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
@ -1104,7 +1109,7 @@ GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cb
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->windowCloseCallback = cbfun;
|
_glfwLibrary.windowCloseCallback = cbfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1112,7 +1117,7 @@ GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cb
|
||||||
// Set callback function for window refresh events
|
// Set callback function for window refresh events
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun)
|
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindowrefreshfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
@ -1120,7 +1125,7 @@ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfu
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->windowRefreshCallback = cbfun;
|
_glfwLibrary.windowRefreshCallback = cbfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1128,7 +1133,7 @@ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfu
|
||||||
// Set callback function for window focus events
|
// Set callback function for window focus events
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cbfun)
|
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindowfocusfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
@ -1136,7 +1141,7 @@ GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cb
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->windowFocusCallback = cbfun;
|
_glfwLibrary.windowFocusCallback = cbfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1144,7 +1149,7 @@ GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cb
|
||||||
// Set callback function for window iconification events
|
// Set callback function for window iconification events
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow window, GLFWwindowiconifyfun cbfun)
|
GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindowiconifyfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
@ -1152,7 +1157,7 @@ GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow window, GLFWwindowiconifyfu
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->windowIconifyCallback = cbfun;
|
_glfwLibrary.windowIconifyCallback = cbfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,29 @@
|
||||||
|
|
||||||
configure_file(
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake
|
${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY)
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY)
|
|
||||||
|
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${GLFW_SOURCE_DIR}/src
|
${GLFW_SOURCE_DIR}/src
|
||||||
${GLFW_BINARY_DIR}/src
|
${GLFW_BINARY_DIR}/src
|
||||||
${GLFW_INCLUDE_DIR})
|
${GLFW_INCLUDE_DIR})
|
||||||
|
|
||||||
set(libglfw_SOURCES
|
set(libglfw_SOURCES ${common_SOURCES}
|
||||||
${common_SOURCES}
|
x11_enable.c
|
||||||
x11_enable.c
|
x11_fullscreen.c
|
||||||
x11_fullscreen.c
|
x11_gamma.c
|
||||||
x11_gamma.c
|
x11_glext.c
|
||||||
x11_glext.c
|
x11_init.c
|
||||||
x11_init.c
|
x11_joystick.c
|
||||||
x11_joystick.c
|
x11_keysym2unicode.c
|
||||||
x11_keysym2unicode.c
|
x11_time.c
|
||||||
x11_time.c
|
x11_window.c)
|
||||||
x11_window.c)
|
|
||||||
|
|
||||||
add_library(libglfwStatic STATIC ${libglfw_SOURCES})
|
add_library(libglfwStatic STATIC ${libglfw_SOURCES})
|
||||||
add_library(libglfwShared SHARED ${libglfw_SOURCES})
|
add_library(libglfwShared SHARED ${libglfw_SOURCES})
|
||||||
target_link_libraries(libglfwShared ${GLFW_LIBRARIES})
|
target_link_libraries(libglfwShared ${GLFW_LIBRARIES})
|
||||||
set_target_properties(libglfwStatic libglfwShared PROPERTIES
|
set_target_properties(libglfwStatic libglfwShared PROPERTIES
|
||||||
CLEAN_DIRECT_OUTPUT 1
|
CLEAN_DIRECT_OUTPUT 1
|
||||||
OUTPUT_NAME glfw
|
OUTPUT_NAME glfw)
|
||||||
)
|
|
||||||
|
|
||||||
install(TARGETS libglfwStatic libglfwShared DESTINATION lib)
|
install(TARGETS libglfwStatic libglfwShared DESTINATION lib)
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig)
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig)
|
||||||
|
|
|
@ -33,12 +33,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
//************************************************************************
|
//////////////////////////////////////////////////////////////////////////
|
||||||
//**** GLFW internal functions ****
|
////// GLFW platform API //////
|
||||||
//************************************************************************
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Save the original gamma ramp so that we can restore it later
|
// Retrieve the currently set gamma ramp
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
|
void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
|
||||||
|
@ -55,6 +55,8 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
|
||||||
XRRCrtcGamma* gamma = XRRGetCrtcGamma(_glfwLibrary.X11.display,
|
XRRCrtcGamma* gamma = XRRGetCrtcGamma(_glfwLibrary.X11.display,
|
||||||
rr->crtcs[0]);
|
rr->crtcs[0]);
|
||||||
|
|
||||||
|
// TODO: Handle case of original ramp size having a size other than 256
|
||||||
|
|
||||||
memcpy(ramp->red, gamma->red, size);
|
memcpy(ramp->red, gamma->red, size);
|
||||||
memcpy(ramp->green, gamma->green, size);
|
memcpy(ramp->green, gamma->green, size);
|
||||||
memcpy(ramp->blue, gamma->blue, size);
|
memcpy(ramp->blue, gamma->blue, size);
|
||||||
|
@ -78,7 +80,7 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Make the specified gamma ramp current
|
// Push the specified gamma ramp to the monitor
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp)
|
void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp)
|
||||||
|
|
|
@ -176,7 +176,7 @@ static void initGammaRamp(void)
|
||||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||||
|
|
||||||
if (!_glfwLibrary.originalRampSize)
|
if (!_glfwLibrary.originalRampSize)
|
||||||
fprintf(stderr, "Gamma ramp setting unsupported\n");
|
fprintf(stderr, "No supported gamma ramp API found\n");
|
||||||
|
|
||||||
// Save the original gamma ramp
|
// Save the original gamma ramp
|
||||||
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
||||||
|
@ -310,14 +310,14 @@ const char* _glfwPlatformGetVersionString(void)
|
||||||
#elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT)
|
#elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT)
|
||||||
" glXGetProcAddressEXT"
|
" glXGetProcAddressEXT"
|
||||||
#elif defined(_GLFW_DLOPEN_LIBGL)
|
#elif defined(_GLFW_DLOPEN_LIBGL)
|
||||||
" dlopen(libGL)"
|
" dlsym(libGL)"
|
||||||
#else
|
#else
|
||||||
" (no OpenGL extension support)"
|
" (no OpenGL extension support)"
|
||||||
#endif
|
#endif
|
||||||
#if defined(_GLFW_USE_LINUX_JOYSTICKS)
|
#if defined(_GLFW_USE_LINUX_JOYSTICKS)
|
||||||
" Linux joystick API"
|
" Linux-joystick-API"
|
||||||
#else
|
#else
|
||||||
" (no joystick support)"
|
" no-joystick-support"
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -1197,11 +1197,11 @@ static void processSingleEvent(void)
|
||||||
window->X11.cursorPosY = event.xmotion.y;
|
window->X11.cursorPosY = event.xmotion.y;
|
||||||
window->X11.mouseMoved = GL_TRUE;
|
window->X11.mouseMoved = GL_TRUE;
|
||||||
|
|
||||||
if (window->mousePosCallback)
|
if (_glfwLibrary.mousePosCallback)
|
||||||
{
|
{
|
||||||
window->mousePosCallback(window,
|
_glfwLibrary.mousePosCallback(window,
|
||||||
window->mousePosX,
|
window->mousePosX,
|
||||||
window->mousePosY);
|
window->mousePosY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1224,11 +1224,11 @@ static void processSingleEvent(void)
|
||||||
|
|
||||||
window->width = event.xconfigure.width;
|
window->width = event.xconfigure.width;
|
||||||
window->height = event.xconfigure.height;
|
window->height = event.xconfigure.height;
|
||||||
if (window->windowSizeCallback)
|
if (_glfwLibrary.windowSizeCallback)
|
||||||
{
|
{
|
||||||
window->windowSizeCallback(window,
|
_glfwLibrary.windowSizeCallback(window,
|
||||||
window->width,
|
window->width,
|
||||||
window->height);
|
window->height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1288,8 +1288,8 @@ static void processSingleEvent(void)
|
||||||
|
|
||||||
window->iconified = GL_FALSE;
|
window->iconified = GL_FALSE;
|
||||||
|
|
||||||
if (window->windowIconifyCallback)
|
if (_glfwLibrary.windowIconifyCallback)
|
||||||
window->windowIconifyCallback(window, window->iconified);
|
_glfwLibrary.windowIconifyCallback(window, window->iconified);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1306,8 +1306,8 @@ static void processSingleEvent(void)
|
||||||
|
|
||||||
window->iconified = GL_TRUE;
|
window->iconified = GL_TRUE;
|
||||||
|
|
||||||
if (window->windowIconifyCallback)
|
if (_glfwLibrary.windowIconifyCallback)
|
||||||
window->windowIconifyCallback(window, window->iconified);
|
_glfwLibrary.windowIconifyCallback(window, window->iconified);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1358,8 +1358,8 @@ static void processSingleEvent(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window->windowRefreshCallback)
|
if (_glfwLibrary.windowRefreshCallback)
|
||||||
window->windowRefreshCallback(window);
|
_glfwLibrary.windowRefreshCallback(window);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,8 +74,8 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetMousePosCallback(window, mouse_position_callback);
|
glfwSetMousePosCallback(mouse_position_callback);
|
||||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
|
|
|
@ -303,16 +303,16 @@ int main(void)
|
||||||
|
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSetWindowCloseCallback(window, window_close_callback);
|
glfwSetWindowCloseCallback(window_close_callback);
|
||||||
glfwSetWindowRefreshCallback(window, window_refresh_callback);
|
glfwSetWindowRefreshCallback(window_refresh_callback);
|
||||||
glfwSetWindowFocusCallback(window, window_focus_callback);
|
glfwSetWindowFocusCallback(window_focus_callback);
|
||||||
glfwSetWindowIconifyCallback(window, window_iconify_callback);
|
glfwSetWindowIconifyCallback(window_iconify_callback);
|
||||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
glfwSetMouseButtonCallback(mouse_button_callback);
|
||||||
glfwSetMousePosCallback(window, mouse_position_callback);
|
glfwSetMousePosCallback(mouse_position_callback);
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
glfwSetScrollCallback(scroll_callback);
|
||||||
glfwSetKeyCallback(window, key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSetCharCallback(window, char_callback);
|
glfwSetCharCallback(char_callback);
|
||||||
|
|
||||||
printf("Key repeat should be %s\n", keyrepeat ? "enabled" : "disabled");
|
printf("Key repeat should be %s\n", keyrepeat ? "enabled" : "disabled");
|
||||||
printf("System keys should be %s\n", systemkeys ? "enabled" : "disabled");
|
printf("System keys should be %s\n", systemkeys ? "enabled" : "disabled");
|
||||||
|
|
|
@ -65,7 +65,7 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
samples = glfwGetWindowParam(window, GLFW_FSAA_SAMPLES);
|
samples = glfwGetWindowParam(window, GLFW_FSAA_SAMPLES);
|
||||||
|
|
|
@ -93,9 +93,9 @@ int main(void)
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
glfwEnable(window, GLFW_MOUSE_CURSOR);
|
glfwEnable(window, GLFW_MOUSE_CURSOR);
|
||||||
|
|
||||||
glfwSetWindowFocusCallback(window, window_focus_callback);
|
glfwSetWindowFocusCallback(window_focus_callback);
|
||||||
glfwSetKeyCallback(window, window_key_callback);
|
glfwSetKeyCallback(window_key_callback);
|
||||||
glfwSetWindowCloseCallback(window, window_close_callback);
|
glfwSetWindowCloseCallback(window_close_callback);
|
||||||
|
|
||||||
while (running && glfwIsWindow(window) == GL_TRUE)
|
while (running && glfwIsWindow(window) == GL_TRUE)
|
||||||
{
|
{
|
||||||
|
|
|
@ -149,8 +149,8 @@ int main(int argc, char** argv)
|
||||||
ggamma, ggain, gblacklevel);
|
ggamma, ggain, gblacklevel);
|
||||||
|
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
glfwSetKeyCallback(window, key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSetWindowSizeCallback(window, size_callback);
|
glfwSetWindowSizeCallback(size_callback);
|
||||||
|
|
||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
|
|
|
@ -119,8 +119,8 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
glfwSetKeyCallback(window, key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSetWindowSizeCallback(window, size_callback);
|
glfwSetWindowSizeCallback(size_callback);
|
||||||
|
|
||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
|
|
|
@ -96,9 +96,9 @@ static GLboolean open_window(void)
|
||||||
glfwGetMousePos(window_handle, &x, &y);
|
glfwGetMousePos(window_handle, &x, &y);
|
||||||
printf("Mouse position: %i %i\n", x, y);
|
printf("Mouse position: %i %i\n", x, y);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_handle, window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSetMousePosCallback(window_handle, mouse_position_callback);
|
glfwSetMousePosCallback(mouse_position_callback);
|
||||||
glfwSetKeyCallback(window_handle, key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
|
|
|
@ -91,9 +91,9 @@ static int open_window(int width, int height, int mode)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_handle, window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSetWindowCloseCallback(window_handle, window_close_callback);
|
glfwSetWindowCloseCallback(window_close_callback);
|
||||||
glfwSetKeyCallback(window_handle, key_callback);
|
glfwSetKeyCallback(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",
|
||||||
|
|
|
@ -49,7 +49,7 @@ static GLFWwindow open_window(const char* title, GLFWwindow share)
|
||||||
if (!window)
|
if (!window)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
glfwSetKeyCallback(window, key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
|
|
|
@ -59,7 +59,7 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
glfwSetWindowSizeCallback(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);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user