mirror of
https://github.com/glfw/glfw.git
synced 2024-11-29 13:32:01 +00:00
Merge branch 'master' into tls
Conflicts: src/x11_window.c
This commit is contained in:
commit
5e23620c7f
1152
examples/particles.c
1152
examples/particles.c
File diff suppressed because it is too large
Load Diff
@ -1,854 +0,0 @@
|
|||||||
//========================================================================
|
|
||||||
// This is a small test application for GLFW.
|
|
||||||
// This is an OpenGL port of the famous "PONG" game (the first computer
|
|
||||||
// game ever?). It is very simple, and could be improved alot. It was
|
|
||||||
// created in order to show off the gaming capabilities of GLFW.
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
#include <GL/glfw.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Constants
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
// Screen resolution
|
|
||||||
#define WIDTH 640
|
|
||||||
#define HEIGHT 480
|
|
||||||
|
|
||||||
// Player size (units)
|
|
||||||
#define PLAYER_XSIZE 0.05f
|
|
||||||
#define PLAYER_YSIZE 0.15f
|
|
||||||
|
|
||||||
// Ball size (units)
|
|
||||||
#define BALL_SIZE 0.02f
|
|
||||||
|
|
||||||
// Maximum player movement speed (units / second)
|
|
||||||
#define MAX_SPEED 1.5f
|
|
||||||
|
|
||||||
// Player movement acceleration (units / seconds^2)
|
|
||||||
#define ACCELERATION 4.0f
|
|
||||||
|
|
||||||
// Player movement deceleration (units / seconds^2)
|
|
||||||
#define DECELERATION 2.0f
|
|
||||||
|
|
||||||
// Ball movement speed (units / second)
|
|
||||||
#define BALL_SPEED 0.4f
|
|
||||||
|
|
||||||
// Menu options
|
|
||||||
#define MENU_NONE 0
|
|
||||||
#define MENU_PLAY 1
|
|
||||||
#define MENU_QUIT 2
|
|
||||||
|
|
||||||
// Game events
|
|
||||||
#define NOBODY_WINS 0
|
|
||||||
#define PLAYER1_WINS 1
|
|
||||||
#define PLAYER2_WINS 2
|
|
||||||
|
|
||||||
// Winner ID
|
|
||||||
#define NOBODY 0
|
|
||||||
#define PLAYER1 1
|
|
||||||
#define PLAYER2 2
|
|
||||||
|
|
||||||
// Camera positions
|
|
||||||
#define CAMERA_CLASSIC 0
|
|
||||||
#define CAMERA_ABOVE 1
|
|
||||||
#define CAMERA_SPECTATOR 2
|
|
||||||
#define CAMERA_DEFAULT CAMERA_CLASSIC
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Textures
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
#define TEX_TITLE 0
|
|
||||||
#define TEX_MENU 1
|
|
||||||
#define TEX_INSTR 2
|
|
||||||
#define TEX_WINNER1 3
|
|
||||||
#define TEX_WINNER2 4
|
|
||||||
#define TEX_FIELD 5
|
|
||||||
#define NUM_TEXTURES 6
|
|
||||||
|
|
||||||
// Texture names
|
|
||||||
char * tex_name[ NUM_TEXTURES ] = {
|
|
||||||
"pong3d_title.tga",
|
|
||||||
"pong3d_menu.tga",
|
|
||||||
"pong3d_instr.tga",
|
|
||||||
"pong3d_winner1.tga",
|
|
||||||
"pong3d_winner2.tga",
|
|
||||||
"pong3d_field.tga"
|
|
||||||
};
|
|
||||||
|
|
||||||
// OpenGL texture object IDs
|
|
||||||
GLuint tex_id[ NUM_TEXTURES ];
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Global variables
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
// Display information
|
|
||||||
int width, height;
|
|
||||||
|
|
||||||
// Frame information
|
|
||||||
double thistime, oldtime, dt, starttime;
|
|
||||||
|
|
||||||
// Camera information
|
|
||||||
int camerapos;
|
|
||||||
|
|
||||||
// Player information
|
|
||||||
struct {
|
|
||||||
double ypos; // -1.0 to +1.0
|
|
||||||
double yspeed; // -MAX_SPEED to +MAX_SPEED
|
|
||||||
} player1, player2;
|
|
||||||
|
|
||||||
// Ball information
|
|
||||||
struct {
|
|
||||||
double xpos, ypos;
|
|
||||||
double xspeed, yspeed;
|
|
||||||
} ball;
|
|
||||||
|
|
||||||
// And the winner is...
|
|
||||||
int winner;
|
|
||||||
|
|
||||||
// Lighting configuration
|
|
||||||
const GLfloat env_ambient[4] = {1.0f,1.0f,1.0f,1.0f};
|
|
||||||
const GLfloat light1_position[4] = {-3.0f,3.0f,2.0f,1.0f};
|
|
||||||
const GLfloat light1_diffuse[4] = {1.0f,1.0f,1.0f,0.0f};
|
|
||||||
const GLfloat light1_ambient[4] = {0.0f,0.0f,0.0f,0.0f};
|
|
||||||
|
|
||||||
// Object material properties
|
|
||||||
const GLfloat player1_diffuse[4] = {1.0f,0.3f,0.3f,1.0f};
|
|
||||||
const GLfloat player1_ambient[4] = {0.3f,0.1f,0.0f,1.0f};
|
|
||||||
const GLfloat player2_diffuse[4] = {0.3f,1.0f,0.3f,1.0f};
|
|
||||||
const GLfloat player2_ambient[4] = {0.1f,0.3f,0.1f,1.0f};
|
|
||||||
const GLfloat ball_diffuse[4] = {1.0f,1.0f,0.5f,1.0f};
|
|
||||||
const GLfloat ball_ambient[4] = {0.3f,0.3f,0.1f,1.0f};
|
|
||||||
const GLfloat border_diffuse[4] = {0.3f,0.3f,1.0f,1.0f};
|
|
||||||
const GLfloat border_ambient[4] = {0.1f,0.1f,0.3f,1.0f};
|
|
||||||
const GLfloat floor_diffuse[4] = {1.0f,1.0f,1.0f,1.0f};
|
|
||||||
const GLfloat floor_ambient[4] = {0.3f,0.3f,0.3f,1.0f};
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// LoadTextures() - Load textures from disk and upload to OpenGL card
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
GLboolean LoadTextures( void )
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
// Generate texture objects
|
|
||||||
glGenTextures( NUM_TEXTURES, tex_id );
|
|
||||||
|
|
||||||
// Load textures
|
|
||||||
for( i = 0; i < NUM_TEXTURES; i ++ )
|
|
||||||
{
|
|
||||||
// Select texture object
|
|
||||||
glBindTexture( GL_TEXTURE_2D, tex_id[ i ] );
|
|
||||||
|
|
||||||
// Set texture parameters
|
|
||||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
|
|
||||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
|
|
||||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
|
||||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
|
||||||
|
|
||||||
// Upload texture from file to texture memory
|
|
||||||
if( !glfwLoadTexture2D( tex_name[ i ], 0 ) )
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Failed to load texture %s\n", tex_name[ i ] );
|
|
||||||
return GL_FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return GL_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// DrawImage() - Draw a 2D image as a texture
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void DrawImage( int texnum, float x1, float x2, float y1, float y2 )
|
|
||||||
{
|
|
||||||
glEnable( GL_TEXTURE_2D );
|
|
||||||
glBindTexture( GL_TEXTURE_2D, tex_id[ texnum ] );
|
|
||||||
glBegin( GL_QUADS );
|
|
||||||
glTexCoord2f( 0.0f, 1.0f );
|
|
||||||
glVertex2f( x1, y1 );
|
|
||||||
glTexCoord2f( 1.0f, 1.0f );
|
|
||||||
glVertex2f( x2, y1 );
|
|
||||||
glTexCoord2f( 1.0f, 0.0f );
|
|
||||||
glVertex2f( x2, y2 );
|
|
||||||
glTexCoord2f( 0.0f, 0.0f );
|
|
||||||
glVertex2f( x1, y2 );
|
|
||||||
glEnd();
|
|
||||||
glDisable( GL_TEXTURE_2D );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// GameMenu() - Game menu (returns menu option)
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
int GameMenu( void )
|
|
||||||
{
|
|
||||||
int option;
|
|
||||||
|
|
||||||
// Enable sticky keys
|
|
||||||
glfwEnable( GLFW_STICKY_KEYS );
|
|
||||||
|
|
||||||
// Wait for a game menu key to be pressed
|
|
||||||
do
|
|
||||||
{
|
|
||||||
// Get window size
|
|
||||||
glfwGetWindowSize( &width, &height );
|
|
||||||
|
|
||||||
// Set viewport
|
|
||||||
glViewport( 0, 0, width, height );
|
|
||||||
|
|
||||||
// Clear display
|
|
||||||
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
|
|
||||||
glClear( GL_COLOR_BUFFER_BIT );
|
|
||||||
|
|
||||||
// Setup projection matrix
|
|
||||||
glMatrixMode( GL_PROJECTION );
|
|
||||||
glLoadIdentity();
|
|
||||||
glOrtho( 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f );
|
|
||||||
|
|
||||||
// Setup modelview matrix
|
|
||||||
glMatrixMode( GL_MODELVIEW );
|
|
||||||
glLoadIdentity();
|
|
||||||
|
|
||||||
// Display title
|
|
||||||
glColor3f( 1.0f, 1.0f, 1.0f );
|
|
||||||
DrawImage( TEX_TITLE, 0.1f, 0.9f, 0.0f, 0.3f );
|
|
||||||
|
|
||||||
// Display menu
|
|
||||||
glColor3f( 1.0f, 1.0f, 0.0f );
|
|
||||||
DrawImage( TEX_MENU, 0.38f, 0.62f, 0.35f, 0.5f );
|
|
||||||
|
|
||||||
// Display instructions
|
|
||||||
glColor3f( 0.0f, 1.0f, 1.0f );
|
|
||||||
DrawImage( TEX_INSTR, 0.32f, 0.68f, 0.65f, 0.85f );
|
|
||||||
|
|
||||||
// Swap buffers
|
|
||||||
glfwSwapBuffers();
|
|
||||||
|
|
||||||
// Check for keys
|
|
||||||
if( glfwGetKey( 'Q' ) || !glfwGetWindowParam( GLFW_OPENED ) )
|
|
||||||
{
|
|
||||||
option = MENU_QUIT;
|
|
||||||
}
|
|
||||||
else if( glfwGetKey( GLFW_KEY_F1 ) )
|
|
||||||
{
|
|
||||||
option = MENU_PLAY;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
option = MENU_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// To avoid horrible busy waiting, sleep for at least 20 ms
|
|
||||||
glfwSleep( 0.02 );
|
|
||||||
}
|
|
||||||
while( option == MENU_NONE );
|
|
||||||
|
|
||||||
// Disable sticky keys
|
|
||||||
glfwDisable( GLFW_STICKY_KEYS );
|
|
||||||
|
|
||||||
return option;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// NewGame() - Initialize a new game
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void NewGame( void )
|
|
||||||
{
|
|
||||||
// Frame information
|
|
||||||
starttime = thistime = glfwGetTime();
|
|
||||||
|
|
||||||
// Camera information
|
|
||||||
camerapos = CAMERA_DEFAULT;
|
|
||||||
|
|
||||||
// Player 1 information
|
|
||||||
player1.ypos = 0.0;
|
|
||||||
player1.yspeed = 0.0;
|
|
||||||
|
|
||||||
// Player 2 information
|
|
||||||
player2.ypos = 0.0;
|
|
||||||
player2.yspeed = 0.0;
|
|
||||||
|
|
||||||
// Ball information
|
|
||||||
ball.xpos = -1.0 + PLAYER_XSIZE;
|
|
||||||
ball.ypos = player1.ypos;
|
|
||||||
ball.xspeed = 1.0;
|
|
||||||
ball.yspeed = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// PlayerControl() - Player control
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void PlayerControl( void )
|
|
||||||
{
|
|
||||||
float joy1pos[ 2 ], joy2pos[ 2 ];
|
|
||||||
|
|
||||||
// Get joystick X & Y axis positions
|
|
||||||
glfwGetJoystickPos( GLFW_JOYSTICK_1, joy1pos, 2 );
|
|
||||||
glfwGetJoystickPos( GLFW_JOYSTICK_2, joy2pos, 2 );
|
|
||||||
|
|
||||||
// Player 1 control
|
|
||||||
if( glfwGetKey( 'A' ) || joy1pos[ 1 ] > 0.2f )
|
|
||||||
{
|
|
||||||
player1.yspeed += dt * ACCELERATION;
|
|
||||||
if( player1.yspeed > MAX_SPEED )
|
|
||||||
{
|
|
||||||
player1.yspeed = MAX_SPEED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( glfwGetKey( 'Z' ) || joy1pos[ 1 ] < -0.2f )
|
|
||||||
{
|
|
||||||
player1.yspeed -= dt * ACCELERATION;
|
|
||||||
if( player1.yspeed < -MAX_SPEED )
|
|
||||||
{
|
|
||||||
player1.yspeed = -MAX_SPEED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player1.yspeed /= exp( DECELERATION * dt );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Player 2 control
|
|
||||||
if( glfwGetKey( 'K' ) || joy2pos[ 1 ] > 0.2f )
|
|
||||||
{
|
|
||||||
player2.yspeed += dt * ACCELERATION;
|
|
||||||
if( player2.yspeed > MAX_SPEED )
|
|
||||||
{
|
|
||||||
player2.yspeed = MAX_SPEED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( glfwGetKey( 'M' ) || joy2pos[ 1 ] < -0.2f )
|
|
||||||
{
|
|
||||||
player2.yspeed -= dt * ACCELERATION;
|
|
||||||
if( player2.yspeed < -MAX_SPEED )
|
|
||||||
{
|
|
||||||
player2.yspeed = -MAX_SPEED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
player2.yspeed /= exp( DECELERATION * dt );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update player 1 position
|
|
||||||
player1.ypos += dt * player1.yspeed;
|
|
||||||
if( player1.ypos > 1.0 - PLAYER_YSIZE )
|
|
||||||
{
|
|
||||||
player1.ypos = 1.0 - PLAYER_YSIZE;
|
|
||||||
player1.yspeed = 0.0;
|
|
||||||
}
|
|
||||||
else if( player1.ypos < -1.0 + PLAYER_YSIZE )
|
|
||||||
{
|
|
||||||
player1.ypos = -1.0 + PLAYER_YSIZE;
|
|
||||||
player1.yspeed = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update player 2 position
|
|
||||||
player2.ypos += dt * player2.yspeed;
|
|
||||||
if( player2.ypos > 1.0 - PLAYER_YSIZE )
|
|
||||||
{
|
|
||||||
player2.ypos = 1.0 - PLAYER_YSIZE;
|
|
||||||
player2.yspeed = 0.0;
|
|
||||||
}
|
|
||||||
else if( player2.ypos < -1.0 + PLAYER_YSIZE )
|
|
||||||
{
|
|
||||||
player2.ypos = -1.0 + PLAYER_YSIZE;
|
|
||||||
player2.yspeed = 0.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// BallControl() - Ball control
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
int BallControl( void )
|
|
||||||
{
|
|
||||||
int event;
|
|
||||||
double ballspeed;
|
|
||||||
|
|
||||||
// Calculate new ball speed
|
|
||||||
ballspeed = BALL_SPEED * (1.0 + 0.02*(thistime-starttime));
|
|
||||||
ball.xspeed = ball.xspeed > 0 ? ballspeed : -ballspeed;
|
|
||||||
ball.yspeed = ball.yspeed > 0 ? ballspeed : -ballspeed;
|
|
||||||
ball.yspeed *= 0.74321;
|
|
||||||
|
|
||||||
// Update ball position
|
|
||||||
ball.xpos += dt * ball.xspeed;
|
|
||||||
ball.ypos += dt * ball.yspeed;
|
|
||||||
|
|
||||||
// Did the ball hit a top/bottom wall?
|
|
||||||
if( ball.ypos >= 1.0 )
|
|
||||||
{
|
|
||||||
ball.ypos = 2.0 - ball.ypos;
|
|
||||||
ball.yspeed = -ball.yspeed;
|
|
||||||
}
|
|
||||||
else if( ball.ypos <= -1.0 )
|
|
||||||
{
|
|
||||||
ball.ypos = -2.0 - ball.ypos;
|
|
||||||
ball.yspeed = -ball.yspeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Did the ball hit/miss a player?
|
|
||||||
event = NOBODY_WINS;
|
|
||||||
|
|
||||||
// Is the ball entering the player 1 goal?
|
|
||||||
if( ball.xpos < -1.0 + PLAYER_XSIZE )
|
|
||||||
{
|
|
||||||
// Did player 1 catch the ball?
|
|
||||||
if( ball.ypos > (player1.ypos-PLAYER_YSIZE) &&
|
|
||||||
ball.ypos < (player1.ypos+PLAYER_YSIZE) )
|
|
||||||
{
|
|
||||||
ball.xpos = -2.0 + 2.0*PLAYER_XSIZE - ball.xpos;
|
|
||||||
ball.xspeed = -ball.xspeed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
event = PLAYER2_WINS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is the ball entering the player 2 goal?
|
|
||||||
if( ball.xpos > 1.0 - PLAYER_XSIZE )
|
|
||||||
{
|
|
||||||
// Did player 2 catch the ball?
|
|
||||||
if( ball.ypos > (player2.ypos-PLAYER_YSIZE) &&
|
|
||||||
ball.ypos < (player2.ypos+PLAYER_YSIZE) )
|
|
||||||
{
|
|
||||||
ball.xpos = 2.0 - 2.0*PLAYER_XSIZE - ball.xpos;
|
|
||||||
ball.xspeed = -ball.xspeed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
event = PLAYER1_WINS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// DrawBox() - Draw a 3D box
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
#define TEX_SCALE 4.0f
|
|
||||||
|
|
||||||
|
|
||||||
void DrawBox( float x1, float y1, float z1, float x2, float y2, float z2 )
|
|
||||||
{
|
|
||||||
// Draw six sides of a cube
|
|
||||||
glBegin( GL_QUADS );
|
|
||||||
// Side 1 (down)
|
|
||||||
glNormal3f( 0.0f, 0.0f, -1.0f );
|
|
||||||
glTexCoord2f( 0.0f, 0.0f );
|
|
||||||
glVertex3f( x1,y2,z1 );
|
|
||||||
glTexCoord2f( TEX_SCALE, 0.0f );
|
|
||||||
glVertex3f( x2,y2,z1 );
|
|
||||||
glTexCoord2f( TEX_SCALE, TEX_SCALE );
|
|
||||||
glVertex3f( x2,y1,z1 );
|
|
||||||
glTexCoord2f( 0.0f, TEX_SCALE );
|
|
||||||
glVertex3f( x1,y1,z1 );
|
|
||||||
// Side 2 (up)
|
|
||||||
glNormal3f( 0.0f, 0.0f, 1.0f );
|
|
||||||
glTexCoord2f( 0.0f, 0.0f );
|
|
||||||
glVertex3f( x1,y1,z2 );
|
|
||||||
glTexCoord2f( TEX_SCALE, 0.0f );
|
|
||||||
glVertex3f( x2,y1,z2 );
|
|
||||||
glTexCoord2f( TEX_SCALE, TEX_SCALE );
|
|
||||||
glVertex3f( x2,y2,z2 );
|
|
||||||
glTexCoord2f( 0.0f, TEX_SCALE );
|
|
||||||
glVertex3f( x1,y2,z2 );
|
|
||||||
// Side 3 (backward)
|
|
||||||
glNormal3f( 0.0f, -1.0f, 0.0f );
|
|
||||||
glTexCoord2f( 0.0f, 0.0f );
|
|
||||||
glVertex3f( x1,y1,z1 );
|
|
||||||
glTexCoord2f( TEX_SCALE, 0.0f );
|
|
||||||
glVertex3f( x2,y1,z1 );
|
|
||||||
glTexCoord2f( TEX_SCALE, TEX_SCALE );
|
|
||||||
glVertex3f( x2,y1,z2 );
|
|
||||||
glTexCoord2f( 0.0f, TEX_SCALE );
|
|
||||||
glVertex3f( x1,y1,z2 );
|
|
||||||
// Side 4 (forward)
|
|
||||||
glNormal3f( 0.0f, 1.0f, 0.0f );
|
|
||||||
glTexCoord2f( 0.0f, 0.0f );
|
|
||||||
glVertex3f( x1,y2,z2 );
|
|
||||||
glTexCoord2f( TEX_SCALE, 0.0f );
|
|
||||||
glVertex3f( x2,y2,z2 );
|
|
||||||
glTexCoord2f( TEX_SCALE, TEX_SCALE );
|
|
||||||
glVertex3f( x2,y2,z1 );
|
|
||||||
glTexCoord2f( 0.0f, TEX_SCALE );
|
|
||||||
glVertex3f( x1,y2,z1 );
|
|
||||||
// Side 5 (left)
|
|
||||||
glNormal3f( -1.0f, 0.0f, 0.0f );
|
|
||||||
glTexCoord2f( 0.0f, 0.0f );
|
|
||||||
glVertex3f( x1,y1,z2 );
|
|
||||||
glTexCoord2f( TEX_SCALE, 0.0f );
|
|
||||||
glVertex3f( x1,y2,z2 );
|
|
||||||
glTexCoord2f( TEX_SCALE, TEX_SCALE );
|
|
||||||
glVertex3f( x1,y2,z1 );
|
|
||||||
glTexCoord2f( 0.0f, TEX_SCALE );
|
|
||||||
glVertex3f( x1,y1,z1 );
|
|
||||||
// Side 6 (right)
|
|
||||||
glNormal3f( 1.0f, 0.0f, 0.0f );
|
|
||||||
glTexCoord2f( 0.0f, 0.0f );
|
|
||||||
glVertex3f( x2,y1,z1 );
|
|
||||||
glTexCoord2f( TEX_SCALE, 0.0f );
|
|
||||||
glVertex3f( x2,y2,z1 );
|
|
||||||
glTexCoord2f( TEX_SCALE, TEX_SCALE );
|
|
||||||
glVertex3f( x2,y2,z2 );
|
|
||||||
glTexCoord2f( 0.0f, TEX_SCALE );
|
|
||||||
glVertex3f( x2,y1,z2 );
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// UpdateDisplay() - Draw graphics (all game related OpenGL stuff goes
|
|
||||||
// here)
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void UpdateDisplay( void )
|
|
||||||
{
|
|
||||||
// Get window size
|
|
||||||
glfwGetWindowSize( &width, &height );
|
|
||||||
|
|
||||||
// Set viewport
|
|
||||||
glViewport( 0, 0, width, height );
|
|
||||||
|
|
||||||
// Clear display
|
|
||||||
glClearColor( 0.02f, 0.02f, 0.02f, 0.0f );
|
|
||||||
glClearDepth( 1.0f );
|
|
||||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
|
||||||
|
|
||||||
// Setup projection matrix
|
|
||||||
glMatrixMode( GL_PROJECTION );
|
|
||||||
glLoadIdentity();
|
|
||||||
gluPerspective(
|
|
||||||
55.0f, // Angle of view
|
|
||||||
(GLfloat)width/(GLfloat)height, // Aspect
|
|
||||||
1.0f, // Near Z
|
|
||||||
100.0f // Far Z
|
|
||||||
);
|
|
||||||
|
|
||||||
// Setup modelview matrix
|
|
||||||
glMatrixMode( GL_MODELVIEW );
|
|
||||||
glLoadIdentity();
|
|
||||||
switch( camerapos )
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
case CAMERA_CLASSIC:
|
|
||||||
gluLookAt(
|
|
||||||
0.0f, 0.0f, 2.5f,
|
|
||||||
0.0f, 0.0f, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.0f
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case CAMERA_ABOVE:
|
|
||||||
gluLookAt(
|
|
||||||
0.0f, 0.0f, 2.5f,
|
|
||||||
(float)ball.xpos, (float)ball.ypos, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.0f
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case CAMERA_SPECTATOR:
|
|
||||||
gluLookAt(
|
|
||||||
0.0f, -2.0, 1.2f,
|
|
||||||
(float)ball.xpos, (float)ball.ypos, 0.0f,
|
|
||||||
0.0f, 0.0f, 1.0f
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable depth testing
|
|
||||||
glEnable( GL_DEPTH_TEST );
|
|
||||||
glDepthFunc( GL_LEQUAL );
|
|
||||||
|
|
||||||
// Enable lighting
|
|
||||||
glEnable( GL_LIGHTING );
|
|
||||||
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, env_ambient );
|
|
||||||
glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE );
|
|
||||||
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
|
|
||||||
glLightfv( GL_LIGHT1, GL_POSITION, light1_position );
|
|
||||||
glLightfv( GL_LIGHT1, GL_DIFFUSE, light1_diffuse );
|
|
||||||
glLightfv( GL_LIGHT1, GL_AMBIENT, light1_ambient );
|
|
||||||
glEnable( GL_LIGHT1 );
|
|
||||||
|
|
||||||
// Front face is counter-clock-wise
|
|
||||||
glFrontFace( GL_CCW );
|
|
||||||
|
|
||||||
// Enable face culling (not necessary, but speeds up rendering)
|
|
||||||
glCullFace( GL_BACK );
|
|
||||||
glEnable( GL_CULL_FACE );
|
|
||||||
|
|
||||||
// Draw Player 1
|
|
||||||
glMaterialfv( GL_FRONT, GL_DIFFUSE, player1_diffuse );
|
|
||||||
glMaterialfv( GL_FRONT, GL_AMBIENT, player1_ambient );
|
|
||||||
DrawBox( -1.f, (GLfloat)player1.ypos-PLAYER_YSIZE, 0.f,
|
|
||||||
-1.f+PLAYER_XSIZE, (GLfloat)player1.ypos+PLAYER_YSIZE, 0.1f );
|
|
||||||
|
|
||||||
// Draw Player 2
|
|
||||||
glMaterialfv( GL_FRONT, GL_DIFFUSE, player2_diffuse );
|
|
||||||
glMaterialfv( GL_FRONT, GL_AMBIENT, player2_ambient );
|
|
||||||
DrawBox( 1.f-PLAYER_XSIZE, (GLfloat)player2.ypos-PLAYER_YSIZE, 0.f,
|
|
||||||
1.f, (GLfloat)player2.ypos+PLAYER_YSIZE, 0.1f );
|
|
||||||
|
|
||||||
// Draw Ball
|
|
||||||
glMaterialfv( GL_FRONT, GL_DIFFUSE, ball_diffuse );
|
|
||||||
glMaterialfv( GL_FRONT, GL_AMBIENT, ball_ambient );
|
|
||||||
DrawBox( (GLfloat)ball.xpos-BALL_SIZE, (GLfloat)ball.ypos-BALL_SIZE, 0.f,
|
|
||||||
(GLfloat)ball.xpos+BALL_SIZE, (GLfloat)ball.ypos+BALL_SIZE, BALL_SIZE*2 );
|
|
||||||
|
|
||||||
// Top game field border
|
|
||||||
glMaterialfv( GL_FRONT, GL_DIFFUSE, border_diffuse );
|
|
||||||
glMaterialfv( GL_FRONT, GL_AMBIENT, border_ambient );
|
|
||||||
DrawBox( -1.1f, 1.0f, 0.0f, 1.1f, 1.1f, 0.1f );
|
|
||||||
// Bottom game field border
|
|
||||||
glColor3f( 0.0f, 0.0f, 0.7f );
|
|
||||||
DrawBox( -1.1f, -1.1f, 0.0f, 1.1f, -1.0f, 0.1f );
|
|
||||||
// Left game field border
|
|
||||||
DrawBox( -1.1f, -1.0f, 0.0f, -1.0f, 1.0f, 0.1f );
|
|
||||||
// Left game field border
|
|
||||||
DrawBox( 1.0f, -1.0f, 0.0f, 1.1f, 1.0f, 0.1f );
|
|
||||||
|
|
||||||
// Enable texturing
|
|
||||||
glEnable( GL_TEXTURE_2D );
|
|
||||||
glBindTexture( GL_TEXTURE_2D, tex_id[ TEX_FIELD ] );
|
|
||||||
|
|
||||||
// Game field floor
|
|
||||||
glMaterialfv( GL_FRONT, GL_DIFFUSE, floor_diffuse );
|
|
||||||
glMaterialfv( GL_FRONT, GL_AMBIENT, floor_ambient );
|
|
||||||
DrawBox( -1.01f, -1.01f, -0.01f, 1.01f, 1.01f, 0.0f );
|
|
||||||
|
|
||||||
// Disable texturing
|
|
||||||
glDisable( GL_TEXTURE_2D );
|
|
||||||
|
|
||||||
// Disable face culling
|
|
||||||
glDisable( GL_CULL_FACE );
|
|
||||||
|
|
||||||
// Disable lighting
|
|
||||||
glDisable( GL_LIGHTING );
|
|
||||||
|
|
||||||
// Disable depth testing
|
|
||||||
glDisable( GL_DEPTH_TEST );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// GameOver()
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void GameOver( void )
|
|
||||||
{
|
|
||||||
// Enable sticky keys
|
|
||||||
glfwEnable( GLFW_STICKY_KEYS );
|
|
||||||
|
|
||||||
// Until the user presses ESC or SPACE
|
|
||||||
while( !glfwGetKey( GLFW_KEY_ESC ) && !glfwGetKey( ' ' ) &&
|
|
||||||
glfwGetWindowParam( GLFW_OPENED ) )
|
|
||||||
{
|
|
||||||
// Draw display
|
|
||||||
UpdateDisplay();
|
|
||||||
|
|
||||||
// Setup projection matrix
|
|
||||||
glMatrixMode( GL_PROJECTION );
|
|
||||||
glLoadIdentity();
|
|
||||||
glOrtho( 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f );
|
|
||||||
|
|
||||||
// Setup modelview matrix
|
|
||||||
glMatrixMode( GL_MODELVIEW );
|
|
||||||
glLoadIdentity();
|
|
||||||
|
|
||||||
// Enable blending
|
|
||||||
glEnable( GL_BLEND );
|
|
||||||
|
|
||||||
// Dim background
|
|
||||||
glBlendFunc( GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA );
|
|
||||||
glColor4f( 0.3f, 0.3f, 0.3f, 0.3f );
|
|
||||||
glBegin( GL_QUADS );
|
|
||||||
glVertex2f( 0.0f, 0.0f );
|
|
||||||
glVertex2f( 1.0f, 0.0f );
|
|
||||||
glVertex2f( 1.0f, 1.0f );
|
|
||||||
glVertex2f( 0.0f, 1.0f );
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
// Display winner text
|
|
||||||
glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_COLOR );
|
|
||||||
if( winner == PLAYER1 )
|
|
||||||
{
|
|
||||||
glColor4f( 1.0f, 0.5f, 0.5f, 1.0f );
|
|
||||||
DrawImage( TEX_WINNER1, 0.35f, 0.65f, 0.46f, 0.54f );
|
|
||||||
}
|
|
||||||
else if( winner == PLAYER2 )
|
|
||||||
{
|
|
||||||
glColor4f( 0.5f, 1.0f, 0.5f, 1.0f );
|
|
||||||
DrawImage( TEX_WINNER2, 0.35f, 0.65f, 0.46f, 0.54f );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable blending
|
|
||||||
glDisable( GL_BLEND );
|
|
||||||
|
|
||||||
// Swap buffers
|
|
||||||
glfwSwapBuffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable sticky keys
|
|
||||||
glfwDisable( GLFW_STICKY_KEYS );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// GameLoop() - Game loop
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void GameLoop( void )
|
|
||||||
{
|
|
||||||
int playing, event;
|
|
||||||
|
|
||||||
// Initialize a new game
|
|
||||||
NewGame();
|
|
||||||
|
|
||||||
// Enable sticky keys
|
|
||||||
glfwEnable( GLFW_STICKY_KEYS );
|
|
||||||
|
|
||||||
// Loop until the game ends
|
|
||||||
playing = GL_TRUE;
|
|
||||||
while( playing && glfwGetWindowParam( GLFW_OPENED ) )
|
|
||||||
{
|
|
||||||
// Frame timer
|
|
||||||
oldtime = thistime;
|
|
||||||
thistime = glfwGetTime();
|
|
||||||
dt = thistime - oldtime;
|
|
||||||
|
|
||||||
// Get user input and update player positions
|
|
||||||
PlayerControl();
|
|
||||||
|
|
||||||
// Move the ball, and check if a player hits/misses the ball
|
|
||||||
event = BallControl();
|
|
||||||
|
|
||||||
// Did we have a winner?
|
|
||||||
switch( event )
|
|
||||||
{
|
|
||||||
case PLAYER1_WINS:
|
|
||||||
winner = PLAYER1;
|
|
||||||
playing = GL_FALSE;
|
|
||||||
break;
|
|
||||||
case PLAYER2_WINS:
|
|
||||||
winner = PLAYER2;
|
|
||||||
playing = GL_FALSE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Did the user press ESC?
|
|
||||||
if( glfwGetKey( GLFW_KEY_ESC ) )
|
|
||||||
{
|
|
||||||
playing = GL_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Did the user change camera view?
|
|
||||||
if( glfwGetKey( '1' ) )
|
|
||||||
{
|
|
||||||
camerapos = CAMERA_CLASSIC;
|
|
||||||
}
|
|
||||||
else if( glfwGetKey( '2' ) )
|
|
||||||
{
|
|
||||||
camerapos = CAMERA_ABOVE;
|
|
||||||
}
|
|
||||||
else if( glfwGetKey( '3' ) )
|
|
||||||
{
|
|
||||||
camerapos = CAMERA_SPECTATOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw display
|
|
||||||
UpdateDisplay();
|
|
||||||
|
|
||||||
// Swap buffers
|
|
||||||
glfwSwapBuffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable sticky keys
|
|
||||||
glfwDisable( GLFW_STICKY_KEYS );
|
|
||||||
|
|
||||||
// Show winner
|
|
||||||
GameOver();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// main() - Program entry point
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
int main( void )
|
|
||||||
{
|
|
||||||
int menuoption;
|
|
||||||
|
|
||||||
// Initialize GLFW
|
|
||||||
if( !glfwInit() )
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Failed to initialize GLFW\n" );
|
|
||||||
exit( EXIT_FAILURE );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open OpenGL window
|
|
||||||
if( !glfwCreateWindow( WIDTH, HEIGHT, 0,0,0,0, 16,0, GLFW_FULLSCREEN ) )
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
|
||||||
glfwTerminate();
|
|
||||||
exit( EXIT_FAILURE );
|
|
||||||
}
|
|
||||||
|
|
||||||
glfwSwapInterval( 1 );
|
|
||||||
|
|
||||||
// Load all textures
|
|
||||||
if( !LoadTextures() )
|
|
||||||
{
|
|
||||||
glfwTerminate();
|
|
||||||
exit( EXIT_FAILURE );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main loop
|
|
||||||
do
|
|
||||||
{
|
|
||||||
// Get menu option
|
|
||||||
menuoption = GameMenu();
|
|
||||||
|
|
||||||
// If the user wants to play, let him...
|
|
||||||
if( menuoption == MENU_PLAY )
|
|
||||||
{
|
|
||||||
GameLoop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while( menuoption != MENU_QUIT );
|
|
||||||
|
|
||||||
// Unload all textures
|
|
||||||
if( glfwGetWindowParam( GLFW_OPENED ) )
|
|
||||||
{
|
|
||||||
glDeleteTextures( NUM_TEXTURES, tex_id );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Terminate GLFW
|
|
||||||
glfwTerminate();
|
|
||||||
|
|
||||||
exit( EXIT_SUCCESS );
|
|
||||||
}
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -67,12 +67,6 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
#endif /* APIENTRY */
|
#endif /* APIENTRY */
|
||||||
|
|
||||||
/* TEMPORARY MinGW-w64 hacks.
|
|
||||||
*/
|
|
||||||
#if __MINGW64__
|
|
||||||
#define WINAPI
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* The following three defines are here solely to make some Windows-based
|
/* The following three defines are here solely to make some Windows-based
|
||||||
* <GL/gl.h> files happy. Theoretically we could include <windows.h>, but
|
* <GL/gl.h> files happy. Theoretically we could include <windows.h>, but
|
||||||
* it has the major drawback of severely polluting our namespace.
|
* it has the major drawback of severely polluting our namespace.
|
||||||
@ -533,11 +527,11 @@ GLFWAPI void glfwSetGammaRamp(const GLFWgammaramp* ramp);
|
|||||||
GLFWAPI void glfwWindowHint(int target, int hint);
|
GLFWAPI void glfwWindowHint(int target, int hint);
|
||||||
GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, int mode, const char* title, GLFWwindow share);
|
GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, int mode, const char* title, GLFWwindow share);
|
||||||
GLFWAPI void glfwDestroyWindow(GLFWwindow window);
|
GLFWAPI void glfwDestroyWindow(GLFWwindow window);
|
||||||
GLFWAPI void glfwSetWindowTitle(GLFWwindow, const char* title);
|
GLFWAPI void glfwSetWindowTitle(GLFWwindow window, const char* title);
|
||||||
GLFWAPI void glfwGetWindowSize(GLFWwindow, int* width, int* height);
|
GLFWAPI void glfwGetWindowSize(GLFWwindow window, int* width, int* height);
|
||||||
GLFWAPI void glfwSetWindowSize(GLFWwindow, int width, int height);
|
GLFWAPI void glfwSetWindowSize(GLFWwindow window, int width, int height);
|
||||||
GLFWAPI void glfwGetWindowPos(GLFWwindow, int* xpos, int* ypos);
|
GLFWAPI void glfwGetWindowPos(GLFWwindow window, int* xpos, int* ypos);
|
||||||
GLFWAPI void glfwSetWindowPos(GLFWwindow, int xpos, int ypos);
|
GLFWAPI void glfwSetWindowPos(GLFWwindow window, int xpos, int ypos);
|
||||||
GLFWAPI void glfwIconifyWindow(GLFWwindow window);
|
GLFWAPI void glfwIconifyWindow(GLFWwindow window);
|
||||||
GLFWAPI void glfwRestoreWindow(GLFWwindow window);
|
GLFWAPI void glfwRestoreWindow(GLFWwindow window);
|
||||||
GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param);
|
GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param);
|
||||||
@ -570,7 +564,7 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun);
|
|||||||
|
|
||||||
/* Joystick input */
|
/* Joystick input */
|
||||||
GLFWAPI int glfwGetJoystickParam(int joy, int param);
|
GLFWAPI int glfwGetJoystickParam(int joy, int param);
|
||||||
GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes);
|
GLFWAPI int glfwGetJoystickAxes(int joy, float* axes, int numaxes);
|
||||||
GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
|
GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
|
||||||
|
|
||||||
/* Clipboard */
|
/* Clipboard */
|
||||||
|
@ -300,6 +300,7 @@ version of GLFW.</p>
|
|||||||
<li>Renamed <code>GLFW_BUILD_DLL</code> to <code>_GLFW_BUILD_DLL</code></li>
|
<li>Renamed <code>GLFW_BUILD_DLL</code> to <code>_GLFW_BUILD_DLL</code></li>
|
||||||
<li>Renamed <code>version</code> test to <code>glfwinfo</code></li>
|
<li>Renamed <code>version</code> test to <code>glfwinfo</code></li>
|
||||||
<li>Renamed <code>GLFW_NO_GLU</code> to <code>GLFW_INCLUDE_GLU</code> and made it disabled by default</li>
|
<li>Renamed <code>GLFW_NO_GLU</code> to <code>GLFW_INCLUDE_GLU</code> and made it disabled by default</li>
|
||||||
|
<li>Renamed <code>glfwGetJoystickPos</code> to <code>glfwGetJoystickAxes</code> to match <code>glfwGetJoystickButtons</code></li>
|
||||||
<li>Renamed mouse position functions to cursor position equivalents</li>
|
<li>Renamed mouse position functions to cursor position equivalents</li>
|
||||||
<li>Replaced <code>glfwOpenWindow</code> and <code>glfwCloseWindow</code> with <code>glfwCreateWindow</code> and <code>glfwDestroyWindow</code></li>
|
<li>Replaced <code>glfwOpenWindow</code> and <code>glfwCloseWindow</code> with <code>glfwCreateWindow</code> and <code>glfwDestroyWindow</code></li>
|
||||||
<li>Replaced ad hoc build system with CMake</li>
|
<li>Replaced ad hoc build system with CMake</li>
|
||||||
@ -950,6 +951,8 @@ their skills. Special thanks go out to:</p>
|
|||||||
|
|
||||||
<li>Samuli Tuomola, for support, bug reports and testing</li>
|
<li>Samuli Tuomola, for support, bug reports and testing</li>
|
||||||
|
|
||||||
|
<li>Torsten Walluhn, for fixing various compilation issues on OS X</li>
|
||||||
|
|
||||||
<li>Frank Wille, for helping with the AmigaOS port and making GLFW
|
<li>Frank Wille, for helping with the AmigaOS port and making GLFW
|
||||||
compile under IRIX 5.3</li>
|
compile under IRIX 5.3</li>
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Cocoa/NSOpenGL
|
// Platform: Cocoa
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
@ -70,7 +70,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
|
|||||||
if (!object)
|
if (!object)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Cocoa/NSGL: Failed to retrieve object from pasteboard");
|
"Cocoa: Failed to retrieve object from pasteboard");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Cocoa/NSOpenGL
|
// Platform: Cocoa
|
||||||
// API Version: 3.0
|
// API Version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Cocoa/NSOpenGL
|
// Platform: Cocoa
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Cocoa/NSOpenGL
|
// Platform: Cocoa
|
||||||
// API Version: 3.0
|
// API Version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Cocoa/NSOpenGL
|
// Platform: Cocoa
|
||||||
// API Version: 3.0
|
// API Version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
@ -528,7 +528,7 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
|
|||||||
// Get joystick axis positions
|
// Get joystick axis positions
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
|
int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numaxes)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -556,12 +556,12 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
|
|||||||
long readScale = axes->maxReport - axes->minReport;
|
long readScale = axes->maxReport - axes->minReport;
|
||||||
|
|
||||||
if (readScale == 0)
|
if (readScale == 0)
|
||||||
pos[i] = axes->value;
|
axes[i] = axes->value;
|
||||||
else
|
else
|
||||||
pos[i] = (2.0f * (axes->value - axes->minReport) / readScale) - 1.0f;
|
axes[i] = (2.0f * (axes->value - axes->minReport) / readScale) - 1.0f;
|
||||||
|
|
||||||
if (i & 1)
|
if (i & 1)
|
||||||
pos[i] = -pos[i];
|
axes[i] = -axes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return numaxes;
|
return numaxes;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Cocoa/NSOpenGL
|
// Platform: Cocoa
|
||||||
// API Version: 3.0
|
// API Version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
@ -674,8 +674,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
|||||||
|
|
||||||
if (window->NS.object == nil)
|
if (window->NS.object == nil)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to create window");
|
||||||
"Cocoa/NSOpenGL: Failed to create window");
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -717,8 +716,8 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
(wndconfig->glMajor == 3 && wndconfig->glMinor != 2))
|
(wndconfig->glMajor == 3 && wndconfig->glMinor != 2))
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"Cocoa/NSOpenGL: The targeted version of Mac OS X does "
|
"NSOpenGL: The targeted version of Mac OS X does not "
|
||||||
"not support any OpenGL version above 2.1 except 3.2");
|
"support any OpenGL version above 2.1 except 3.2");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -727,8 +726,8 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
if (!wndconfig->glForward)
|
if (!wndconfig->glForward)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"Cocoa/NSOpenGL: The targeted version of Mac OS X "
|
"NSOpenGL: The targeted version of Mac OS X only "
|
||||||
"only supports OpenGL 3.2 contexts if they are "
|
"supports OpenGL 3.2 contexts if they are "
|
||||||
"forward-compatible");
|
"forward-compatible");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
@ -736,8 +735,8 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE)
|
if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"Cocoa/NSOpenGL: The targeted version of Mac OS X "
|
"NSOpenGL: The targeted version of Mac OS X only "
|
||||||
"only supports OpenGL 3.2 contexts if they use the "
|
"supports OpenGL 3.2 contexts if they use the "
|
||||||
"core profile");
|
"core profile");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
@ -747,8 +746,8 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
if (wndconfig->glMajor > 2)
|
if (wndconfig->glMajor > 2)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"Cocoa/NSOpenGL: The targeted version of Mac OS X does "
|
"NSOpenGL: The targeted version of Mac OS X does not "
|
||||||
"not support OpenGL version 3.0 or above");
|
"support OpenGL version 3.0 or above");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/
|
||||||
@ -757,8 +756,8 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
if (wndconfig->glRobustness)
|
if (wndconfig->glRobustness)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"Cocoa/NSOpenGL: Mac OS X does not support OpenGL "
|
"NSOpenGL: Mac OS X does not support OpenGL robustness "
|
||||||
"robustness strategies");
|
"strategies");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -821,7 +820,7 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
if (window->NSGL.pixelFormat == nil)
|
if (window->NSGL.pixelFormat == nil)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Cocoa/NSOpenGL: Failed to create OpenGL pixel format");
|
"NSOpenGL: Failed to create OpenGL pixel format");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,7 +835,7 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
if (window->NSGL.context == nil)
|
if (window->NSGL.context == nil)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Cocoa/NSOpenGL: Failed to create OpenGL context");
|
"NSOpenGL: Failed to create OpenGL context");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -868,8 +867,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|||||||
if (_glfwLibrary.NS.delegate == nil)
|
if (_glfwLibrary.NS.delegate == nil)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Cocoa/NSOpenGL: Failed to create application "
|
"Cocoa: Failed to create application delegate");
|
||||||
"delegate");
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -880,7 +878,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|||||||
if (window->NS.delegate == nil)
|
if (window->NS.delegate == nil)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Cocoa/NSOpenGL: Failed to create window delegate");
|
"Cocoa: Failed to create window delegate");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,38 +241,41 @@ extern _GLFWlibrary _glfwLibrary;
|
|||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Prototypes for platform specific implementation functions
|
// Prototypes for the platform API
|
||||||
|
// This is the interface exposed by the platform-specific code for each
|
||||||
|
// platform and is called by the shared code of the public API
|
||||||
|
// It mirrors the public API except it uses objects instead of handles
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
// Init/terminate
|
// Platform init and version
|
||||||
int _glfwPlatformInit(void);
|
int _glfwPlatformInit(void);
|
||||||
int _glfwPlatformTerminate(void);
|
int _glfwPlatformTerminate(void);
|
||||||
const char* _glfwPlatformGetVersionString(void);
|
const char* _glfwPlatformGetVersionString(void);
|
||||||
|
|
||||||
// Input
|
// Input mode support
|
||||||
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
|
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
|
||||||
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
|
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
|
||||||
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y);
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y);
|
||||||
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
|
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
|
||||||
|
|
||||||
// Fullscreen
|
// Video mode support
|
||||||
GLFWvidmode* _glfwPlatformGetVideoModes(int* count);
|
GLFWvidmode* _glfwPlatformGetVideoModes(int* count);
|
||||||
void _glfwPlatformGetDesktopMode(GLFWvidmode* mode);
|
void _glfwPlatformGetDesktopMode(GLFWvidmode* mode);
|
||||||
|
|
||||||
// Gamma ramp
|
// Gamma ramp support
|
||||||
void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp);
|
void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp);
|
||||||
void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp);
|
void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp);
|
||||||
|
|
||||||
// Clipboard
|
// Clipboard support
|
||||||
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string);
|
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string);
|
||||||
const char* _glfwPlatformGetClipboardString(_GLFWwindow* window);
|
const char* _glfwPlatformGetClipboardString(_GLFWwindow* window);
|
||||||
|
|
||||||
// Joystick
|
// Joystick input
|
||||||
int _glfwPlatformGetJoystickParam(int joy, int param);
|
int _glfwPlatformGetJoystickParam(int joy, int param);
|
||||||
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes);
|
int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numaxes);
|
||||||
int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
|
int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
|
||||||
|
|
||||||
// Time
|
// Time input
|
||||||
double _glfwPlatformGetTime(void);
|
double _glfwPlatformGetTime(void);
|
||||||
void _glfwPlatformSetTime(double time);
|
void _glfwPlatformSetTime(double time);
|
||||||
|
|
||||||
@ -285,7 +288,7 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y);
|
|||||||
void _glfwPlatformIconifyWindow(_GLFWwindow* window);
|
void _glfwPlatformIconifyWindow(_GLFWwindow* window);
|
||||||
void _glfwPlatformRestoreWindow(_GLFWwindow* window);
|
void _glfwPlatformRestoreWindow(_GLFWwindow* window);
|
||||||
|
|
||||||
// Event management
|
// Event processing
|
||||||
void _glfwPlatformPollEvents(void);
|
void _glfwPlatformPollEvents(void);
|
||||||
void _glfwPlatformWaitEvents(void);
|
void _glfwPlatformWaitEvents(void);
|
||||||
|
|
||||||
@ -301,19 +304,12 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long
|
|||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Prototypes for platform independent internal functions
|
// Prototypes for the event API
|
||||||
|
// This is used by the platform-specific code to notify the shared code of
|
||||||
|
// events that can be translated into state changes and/or callback calls,
|
||||||
|
// instead of directly calling callbacks or modifying shared state
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
// Fullscren management (fullscreen.c)
|
|
||||||
int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second);
|
|
||||||
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
|
|
||||||
|
|
||||||
// Error handling (init.c)
|
|
||||||
void _glfwSetError(int error, const char* format, ...);
|
|
||||||
|
|
||||||
// Window management (window.c)
|
|
||||||
void _glfwSetDefaultWindowHints(void);
|
|
||||||
|
|
||||||
// Window event notification (window.c)
|
// Window event notification (window.c)
|
||||||
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
|
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
|
||||||
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y);
|
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y);
|
||||||
@ -330,6 +326,24 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
|
|||||||
void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y);
|
void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y);
|
||||||
void _glfwInputCursorEnter(_GLFWwindow* window, int entered);
|
void _glfwInputCursorEnter(_GLFWwindow* window, int entered);
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Prototypes for internal utility functions
|
||||||
|
// These functions are shared code and may be used by any part of GLFW
|
||||||
|
// Each platform may add its own utility functions, but those may only be
|
||||||
|
// called by the platform-specific code
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
// Fullscren management (fullscreen.c)
|
||||||
|
int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second);
|
||||||
|
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
|
||||||
|
|
||||||
|
// Error handling (init.c)
|
||||||
|
void _glfwSetError(int error, const char* format, ...);
|
||||||
|
|
||||||
|
// Window management (window.c)
|
||||||
|
void _glfwSetDefaultWindowHints(void);
|
||||||
|
|
||||||
// OpenGL context helpers (opengl.c)
|
// OpenGL context helpers (opengl.c)
|
||||||
int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);
|
int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);
|
||||||
const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
|
const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
|
||||||
|
@ -61,7 +61,7 @@ GLFWAPI int glfwGetJoystickParam(int joy, int param)
|
|||||||
// Get joystick axis positions
|
// Get joystick axis positions
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes)
|
GLFWAPI int glfwGetJoystickAxes(int joy, float* axes, int numaxes)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos == NULL || numaxes < 0)
|
if (axes == NULL || numaxes < 0)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_INVALID_VALUE, NULL);
|
_glfwSetError(GLFW_INVALID_VALUE, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
@ -85,9 +85,9 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes)
|
|||||||
|
|
||||||
// Clear positions
|
// Clear positions
|
||||||
for (i = 0; i < numaxes; i++)
|
for (i = 0; i < numaxes; i++)
|
||||||
pos[i] = 0.0f;
|
axes[i] = 0.0f;
|
||||||
|
|
||||||
return _glfwPlatformGetJoystickPos(joy, pos, numaxes);
|
return _glfwPlatformGetJoystickAxes(joy, axes, numaxes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -508,7 +508,7 @@ GLFWAPI GLFWwindow glfwGetCurrentContext(void)
|
|||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return GL_FALSE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _glfwPlatformGetCurrentContext();
|
return _glfwPlatformGetCurrentContext();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Win32/WGL
|
// Platform: Win32
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
@ -53,7 +53,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
|
|||||||
if (!wideString)
|
if (!wideString)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to convert clipboard string to "
|
"Win32: Failed to convert clipboard string to "
|
||||||
"wide string");
|
"wide string");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
|
|||||||
free(wideString);
|
free(wideString);
|
||||||
|
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to allocate global handle for clipboard");
|
"Win32: Failed to allocate global handle for clipboard");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
|
|||||||
free(wideString);
|
free(wideString);
|
||||||
|
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to open clipboard");
|
"Win32: Failed to open clipboard");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
|
|||||||
if (!OpenClipboard(window->Win32.handle))
|
if (!OpenClipboard(window->Win32.handle))
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to open clipboard");
|
"Win32: Failed to open clipboard");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
|
|||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
|
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to retrieve clipboard data");
|
"Win32: Failed to retrieve clipboard data");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
|
|||||||
if (!_glfwLibrary.Win32.clipboardString)
|
if (!_glfwLibrary.Win32.clipboardString)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to convert wide string to UTF-8");
|
"Win32: Failed to convert wide string to UTF-8");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Win32/WGL
|
// Platform: Win32
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Win32/WGL
|
// Platform: Win32
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Win32/WGL
|
// Platform: Win32
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Win32/WGL
|
// Platform: Win32
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Win32/WGL
|
// Platform: Win32
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
@ -116,7 +116,7 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
|
|||||||
// Get joystick axis positions
|
// Get joystick axis positions
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
|
int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numaxes)
|
||||||
{
|
{
|
||||||
JOYCAPS jc;
|
JOYCAPS jc;
|
||||||
JOYINFOEX ji;
|
JOYINFOEX ji;
|
||||||
@ -137,22 +137,22 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
|
|||||||
// Get position values for all axes
|
// Get position values for all axes
|
||||||
axis = 0;
|
axis = 0;
|
||||||
if (axis < numaxes)
|
if (axis < numaxes)
|
||||||
pos[axis++] = calcJoystickPos(ji.dwXpos, jc.wXmin, jc.wXmax);
|
axes[axis++] = calcJoystickPos(ji.dwXpos, jc.wXmin, jc.wXmax);
|
||||||
|
|
||||||
if (axis < numaxes)
|
if (axis < numaxes)
|
||||||
pos[axis++] = -calcJoystickPos(ji.dwYpos, jc.wYmin, jc.wYmax);
|
axes[axis++] = -calcJoystickPos(ji.dwYpos, jc.wYmin, jc.wYmax);
|
||||||
|
|
||||||
if (axis < numaxes && jc.wCaps & JOYCAPS_HASZ)
|
if (axis < numaxes && jc.wCaps & JOYCAPS_HASZ)
|
||||||
pos[axis++] = calcJoystickPos(ji.dwZpos, jc.wZmin, jc.wZmax);
|
axes[axis++] = calcJoystickPos(ji.dwZpos, jc.wZmin, jc.wZmax);
|
||||||
|
|
||||||
if (axis < numaxes && jc.wCaps & JOYCAPS_HASR)
|
if (axis < numaxes && jc.wCaps & JOYCAPS_HASR)
|
||||||
pos[axis++] = calcJoystickPos(ji.dwRpos, jc.wRmin, jc.wRmax);
|
axes[axis++] = calcJoystickPos(ji.dwRpos, jc.wRmin, jc.wRmax);
|
||||||
|
|
||||||
if (axis < numaxes && jc.wCaps & JOYCAPS_HASU)
|
if (axis < numaxes && jc.wCaps & JOYCAPS_HASU)
|
||||||
pos[axis++] = calcJoystickPos(ji.dwUpos, jc.wUmin, jc.wUmax);
|
axes[axis++] = calcJoystickPos(ji.dwUpos, jc.wUmin, jc.wUmax);
|
||||||
|
|
||||||
if (axis < numaxes && jc.wCaps & JOYCAPS_HASV)
|
if (axis < numaxes && jc.wCaps & JOYCAPS_HASV)
|
||||||
pos[axis++] = -calcJoystickPos(ji.dwVpos, jc.wVmin, jc.wVmax);
|
axes[axis++] = -calcJoystickPos(ji.dwVpos, jc.wVmin, jc.wVmax);
|
||||||
|
|
||||||
return axis;
|
return axis;
|
||||||
}
|
}
|
||||||
|
@ -189,15 +189,14 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||||||
|
|
||||||
if (!available)
|
if (!available)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "Win32/WGL: No pixel formats found");
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "WGL: No pixel formats found");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fbconfigs = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * available);
|
fbconfigs = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * available);
|
||||||
if (!fbconfigs)
|
if (!fbconfigs)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
_glfwSetError(GLFW_OUT_OF_MEMORY, NULL);
|
||||||
"Win32/WGL: Failed to allocate _GLFWfbconfig array");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,6 +302,9 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||||||
|
|
||||||
if (*found == 0)
|
if (*found == 0)
|
||||||
{
|
{
|
||||||
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
|
"Win32/WGL: No usable pixel formats found");
|
||||||
|
|
||||||
free(fbconfigs);
|
free(fbconfigs);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -328,15 +330,15 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
|
|
||||||
if (!DescribePixelFormat(window->WGL.DC, pixelFormat, sizeof(pfd), &pfd))
|
if (!DescribePixelFormat(window->WGL.DC, pixelFormat, sizeof(pfd), &pfd))
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to retrieve PFD for selected pixel format");
|
"Win32: Failed to retrieve PFD for selected pixel format");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SetPixelFormat(window->WGL.DC, pixelFormat, &pfd))
|
if (!SetPixelFormat(window->WGL.DC, pixelFormat, &pfd))
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to set selected pixel format");
|
"Win32: Failed to set selected pixel format");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,7 +380,7 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
if (!window->WGL.ARB_create_context_profile)
|
if (!window->WGL.ARB_create_context_profile)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"Win32/WGL: OpenGL profile requested but "
|
"WGL: OpenGL profile requested but "
|
||||||
"WGL_ARB_create_context_profile is unavailable");
|
"WGL_ARB_create_context_profile is unavailable");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
@ -387,7 +389,7 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
!window->WGL.EXT_create_context_es2_profile)
|
!window->WGL.EXT_create_context_es2_profile)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"Win32/WGL: OpenGL ES 2.x profile requested but "
|
"WGL: OpenGL ES 2.x profile requested but "
|
||||||
"WGL_EXT_create_context_es2_profile is unavailable");
|
"WGL_EXT_create_context_es2_profile is unavailable");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
@ -410,7 +412,7 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
if (!window->WGL.ARB_create_context_robustness)
|
if (!window->WGL.ARB_create_context_robustness)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"Win32/WGL: An OpenGL robustness strategy was "
|
"WGL: An OpenGL robustness strategy was "
|
||||||
"requested but WGL_ARB_create_context_robustness "
|
"requested but WGL_ARB_create_context_robustness "
|
||||||
"is unavailable");
|
"is unavailable");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
@ -433,7 +435,7 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
if (!window->WGL.context)
|
if (!window->WGL.context)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"Win32/WGL: Failed to create OpenGL context");
|
"WGL: Failed to create OpenGL context");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -443,7 +445,7 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
if (!window->WGL.context)
|
if (!window->WGL.context)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to create OpenGL context");
|
"WGL: Failed to create OpenGL context");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,8 +454,8 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
if (!wglShareLists(share, window->WGL.context))
|
if (!wglShareLists(share, window->WGL.context))
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to enable sharing with "
|
"WGL: Failed to enable sharing with specified "
|
||||||
"specified OpenGL context");
|
"OpenGL context");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -484,7 +486,7 @@ int _glfwCreateContext(_GLFWwindow* window,
|
|||||||
if (!window->WGL.DC)
|
if (!window->WGL.DC)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to retrieve DC for window");
|
"Win32: Failed to retrieve DC for window");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,16 +498,12 @@ int _glfwCreateContext(_GLFWwindow* window,
|
|||||||
|
|
||||||
fbconfigs = getFBConfigs(window, &fbcount);
|
fbconfigs = getFBConfigs(window, &fbcount);
|
||||||
if (!fbconfigs)
|
if (!fbconfigs)
|
||||||
{
|
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
|
||||||
"Win32/WGL: No usable pixel formats found");
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_FORMAT_UNAVAILABLE,
|
||||||
"Win32/WGL: No pixel format matched the criteria");
|
"Win32/WGL: No pixel format matched the criteria");
|
||||||
|
|
||||||
free(fbconfigs);
|
free(fbconfigs);
|
||||||
@ -650,7 +648,7 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long
|
|||||||
if (!wglCopyContext(src->WGL.context, dst->WGL.context, mask))
|
if (!wglCopyContext(src->WGL.context, dst->WGL.context, mask))
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to copy OpenGL context attributes");
|
"WGL: Failed to copy OpenGL context attributes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ typedef struct _GLFWlibraryWin32
|
|||||||
|
|
||||||
// Timer data
|
// Timer data
|
||||||
struct {
|
struct {
|
||||||
GLboolean hasPerformanceCounter;
|
GLboolean hasPC;
|
||||||
double resolution;
|
double resolution;
|
||||||
unsigned int t0_32;
|
unsigned int t0_32;
|
||||||
__int64 t0_64;
|
__int64 t0_64;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: Win32/WGL
|
// Platform: Win32
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
@ -45,13 +45,13 @@ void _glfwInitTimer(void)
|
|||||||
|
|
||||||
if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq))
|
if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq))
|
||||||
{
|
{
|
||||||
_glfwLibrary.Win32.timer.hasPerformanceCounter = GL_TRUE;
|
_glfwLibrary.Win32.timer.hasPC = GL_TRUE;
|
||||||
_glfwLibrary.Win32.timer.resolution = 1.0 / (double) freq;
|
_glfwLibrary.Win32.timer.resolution = 1.0 / (double) freq;
|
||||||
QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Win32.timer.t0_64);
|
QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Win32.timer.t0_64);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_glfwLibrary.Win32.timer.hasPerformanceCounter = GL_FALSE;
|
_glfwLibrary.Win32.timer.hasPC = GL_FALSE;
|
||||||
_glfwLibrary.Win32.timer.resolution = 0.001; // winmm resolution is 1 ms
|
_glfwLibrary.Win32.timer.resolution = 0.001; // winmm resolution is 1 ms
|
||||||
_glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime();
|
_glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime();
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ double _glfwPlatformGetTime(void)
|
|||||||
double t;
|
double t;
|
||||||
__int64 t_64;
|
__int64 t_64;
|
||||||
|
|
||||||
if (_glfwLibrary.Win32.timer.hasPerformanceCounter)
|
if (_glfwLibrary.Win32.timer.hasPC)
|
||||||
{
|
{
|
||||||
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
|
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
|
||||||
t = (double)(t_64 - _glfwLibrary.Win32.timer.t0_64);
|
t = (double)(t_64 - _glfwLibrary.Win32.timer.t0_64);
|
||||||
@ -91,7 +91,7 @@ void _glfwPlatformSetTime(double t)
|
|||||||
{
|
{
|
||||||
__int64 t_64;
|
__int64 t_64;
|
||||||
|
|
||||||
if (_glfwLibrary.Win32.timer.hasPerformanceCounter)
|
if (_glfwLibrary.Win32.timer.hasPC)
|
||||||
{
|
{
|
||||||
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
|
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
|
||||||
_glfwLibrary.Win32.timer.t0_64 = t_64 - (__int64) (t / _glfwLibrary.Win32.timer.resolution);
|
_glfwLibrary.Win32.timer.t0_64 = t_64 - (__int64) (t / _glfwLibrary.Win32.timer.resolution);
|
||||||
|
@ -813,7 +813,7 @@ static ATOM registerWindowClass(void)
|
|||||||
if (!classAtom)
|
if (!classAtom)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"Win32/WGL: Failed to register window class");
|
"Win32: Failed to register window class");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -886,7 +886,7 @@ static int createWindow(_GLFWwindow* window,
|
|||||||
if (!wideTitle)
|
if (!wideTitle)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"glfwCreateWindow: Failed to convert title to wide string");
|
"Win32: Failed to convert title to wide string");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -904,7 +904,7 @@ static int createWindow(_GLFWwindow* window,
|
|||||||
|
|
||||||
if (!window->Win32.handle)
|
if (!window->Win32.handle)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to create window");
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Win32: Failed to create window");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1008,8 +1008,8 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|||||||
if (!window->WGL.ARB_create_context)
|
if (!window->WGL.ARB_create_context)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"Win32/WGL: A forward compatible OpenGL context "
|
"WGL: A forward compatible OpenGL context requested "
|
||||||
"requested but WGL_ARB_create_context is unavailable");
|
"but WGL_ARB_create_context is unavailable");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1021,7 +1021,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|||||||
if (!window->WGL.ARB_create_context_profile)
|
if (!window->WGL.ARB_create_context_profile)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"Win32/WGL: OpenGL profile requested but "
|
"WGL: OpenGL profile requested but "
|
||||||
"WGL_ARB_create_context_profile is unavailable");
|
"WGL_ARB_create_context_profile is unavailable");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
@ -1107,7 +1107,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
|||||||
if (!wideTitle)
|
if (!wideTitle)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"glfwSetWindowTitle: Failed to convert title to wide string");
|
"Win32: Failed to convert title to wide string");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
src/window.c
11
src/window.c
@ -84,6 +84,12 @@ void _glfwSetDefaultWindowHints(void)
|
|||||||
|
|
||||||
// The default is to allow window resizing
|
// The default is to allow window resizing
|
||||||
_glfwLibrary.hints.resizable = GL_TRUE;
|
_glfwLibrary.hints.resizable = GL_TRUE;
|
||||||
|
|
||||||
|
// The default is 24 bits of depth, 8 bits of color
|
||||||
|
_glfwLibrary.hints.depthBits = 24;
|
||||||
|
_glfwLibrary.hints.redBits = 8;
|
||||||
|
_glfwLibrary.hints.greenBits = 8;
|
||||||
|
_glfwLibrary.hints.blueBits = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -267,7 +273,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
|||||||
if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN)
|
if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_INVALID_ENUM,
|
_glfwSetError(GLFW_INVALID_ENUM,
|
||||||
"glfwCreateWindow: Invalid enum for 'mode' parameter");
|
"glfwCreateWindow: Invalid window mode");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,8 +298,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
|||||||
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
|
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
_glfwSetError(GLFW_OUT_OF_MEMORY, NULL);
|
||||||
"glfwCreateWindow: Failed to allocate window structure");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: X11/GLX
|
// Platform: X11
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
@ -182,7 +182,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
|
|||||||
if (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_FAILED)
|
if (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_FAILED)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_FORMAT_UNAVAILABLE,
|
_glfwSetError(GLFW_FORMAT_UNAVAILABLE,
|
||||||
"X11/GLX: Failed to convert selection to string");
|
"X11: Failed to convert selection to string");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: X11/GLX
|
// Platform: X11
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
@ -442,7 +442,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(int* found)
|
|||||||
if (visuals == NULL)
|
if (visuals == NULL)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"X11/GLX: Failed to retrieve the available visuals");
|
"X11: Failed to retrieve the available visuals");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: X11/GLX
|
// Platform: X11
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
@ -115,7 +115,7 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp)
|
|||||||
if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE)
|
if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"X11/GLX: Failed to get gamma ramp due to size "
|
"X11: Failed to get gamma ramp due to size "
|
||||||
"incompatibility");
|
"incompatibility");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp)
|
|||||||
if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE)
|
if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"X11/GLX: Failed to set gamma ramp due to size "
|
"X11: Failed to set gamma ramp due to size "
|
||||||
"incompatibility");
|
"incompatibility");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -491,7 +491,7 @@ static GLboolean initDisplay(void)
|
|||||||
_glfwLibrary.X11.display = XOpenDisplay(NULL);
|
_glfwLibrary.X11.display = XOpenDisplay(NULL);
|
||||||
if (!_glfwLibrary.X11.display)
|
if (!_glfwLibrary.X11.display)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: Failed to open X display");
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11: Failed to open X display");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,7 +525,7 @@ static GLboolean initDisplay(void)
|
|||||||
&_glfwLibrary.X11.RandR.minorVersion))
|
&_glfwLibrary.X11.RandR.minorVersion))
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"X11/GLX: Failed to query RandR version");
|
"X11: Failed to query RandR version");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: X11 (Unix)
|
// Platform: X11
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: X11/GLX
|
// Platform: X11
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
@ -36,6 +36,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -109,6 +110,7 @@ static void pollJoystickEvents(void)
|
|||||||
{
|
{
|
||||||
#ifdef _GLFW_USE_LINUX_JOYSTICKS
|
#ifdef _GLFW_USE_LINUX_JOYSTICKS
|
||||||
int i;
|
int i;
|
||||||
|
ssize_t result;
|
||||||
struct js_event e;
|
struct js_event e;
|
||||||
|
|
||||||
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
|
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
|
||||||
@ -117,8 +119,17 @@ static void pollJoystickEvents(void)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Read all queued events (non-blocking)
|
// Read all queued events (non-blocking)
|
||||||
while (read(_glfwLibrary.X11.joystick[i].fd, &e, sizeof(e)) > 0)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
errno = 0;
|
||||||
|
result = read(_glfwLibrary.X11.joystick[i].fd, &e, sizeof(e));
|
||||||
|
|
||||||
|
if (errno == ENODEV)
|
||||||
|
_glfwLibrary.X11.joystick[i].present = GL_FALSE;
|
||||||
|
|
||||||
|
if (result < sizeof(e))
|
||||||
|
break;
|
||||||
|
|
||||||
// We don't care if it's an init event or not
|
// We don't care if it's an init event or not
|
||||||
e.type &= ~JS_EVENT_INIT;
|
e.type &= ~JS_EVENT_INIT;
|
||||||
|
|
||||||
@ -221,6 +232,8 @@ void _glfwTerminateJoysticks(void)
|
|||||||
|
|
||||||
int _glfwPlatformGetJoystickParam(int joy, int param)
|
int _glfwPlatformGetJoystickParam(int joy, int param)
|
||||||
{
|
{
|
||||||
|
pollJoystickEvents();
|
||||||
|
|
||||||
if (!_glfwLibrary.X11.joystick[joy].present)
|
if (!_glfwLibrary.X11.joystick[joy].present)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -247,20 +260,20 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
|
|||||||
// Get joystick axis positions
|
// Get joystick axis positions
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numAxes)
|
int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numAxes)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
pollJoystickEvents();
|
||||||
|
|
||||||
if (!_glfwLibrary.X11.joystick[joy].present)
|
if (!_glfwLibrary.X11.joystick[joy].present)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pollJoystickEvents();
|
|
||||||
|
|
||||||
if (_glfwLibrary.X11.joystick[joy].numAxes < numAxes)
|
if (_glfwLibrary.X11.joystick[joy].numAxes < numAxes)
|
||||||
numAxes = _glfwLibrary.X11.joystick[joy].numAxes;
|
numAxes = _glfwLibrary.X11.joystick[joy].numAxes;
|
||||||
|
|
||||||
for (i = 0; i < numAxes; i++)
|
for (i = 0; i < numAxes; i++)
|
||||||
pos[i] = _glfwLibrary.X11.joystick[joy].axis[i];
|
axes[i] = _glfwLibrary.X11.joystick[joy].axis[i];
|
||||||
|
|
||||||
return numAxes;
|
return numAxes;
|
||||||
}
|
}
|
||||||
@ -275,11 +288,11 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
pollJoystickEvents();
|
||||||
|
|
||||||
if (!_glfwLibrary.X11.joystick[joy].present)
|
if (!_glfwLibrary.X11.joystick[joy].present)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pollJoystickEvents();
|
|
||||||
|
|
||||||
if (_glfwLibrary.X11.joystick[joy].numButtons < numButtons)
|
if (_glfwLibrary.X11.joystick[joy].numButtons < numButtons)
|
||||||
numButtons = _glfwLibrary.X11.joystick[joy].numButtons;
|
numButtons = _glfwLibrary.X11.joystick[joy].numButtons;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: X11/GLX
|
// Platform: X11
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
@ -94,7 +94,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||||||
if (!_glfwLibrary.GLX.SGIX_fbconfig)
|
if (!_glfwLibrary.GLX.SGIX_fbconfig)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
||||||
"X11/GLX: GLXFBConfig support not found");
|
"GLX: GLXFBConfig support not found");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||||||
if (!count)
|
if (!count)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
||||||
"X11/GLX: No GLXFBConfigs returned");
|
"GLX: No GLXFBConfigs returned");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||||||
if (!count)
|
if (!count)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
||||||
"X11/GLX: No GLXFBConfigs returned");
|
"GLX: No GLXFBConfigs returned");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,8 +137,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||||||
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
_glfwSetError(GLFW_OUT_OF_MEMORY, NULL);
|
||||||
"X11/GLX: Failed to allocate _GLFWfbconfig array");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +257,7 @@ static int createContext(_GLFWwindow* window,
|
|||||||
if (fbconfig == NULL)
|
if (fbconfig == NULL)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"X11/GLX: Failed to retrieve the selected GLXFBConfig");
|
"GLX: Failed to retrieve the selected GLXFBConfig");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,7 +279,7 @@ static int createContext(_GLFWwindow* window,
|
|||||||
XFree(fbconfig);
|
XFree(fbconfig);
|
||||||
|
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"X11/GLX: Failed to retrieve visual for GLXFBConfig");
|
"GLX: Failed to retrieve visual for GLXFBConfig");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,7 +318,7 @@ static int createContext(_GLFWwindow* window,
|
|||||||
if (!_glfwLibrary.GLX.ARB_create_context_profile)
|
if (!_glfwLibrary.GLX.ARB_create_context_profile)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"X11/GLX: An OpenGL profile requested but "
|
"GLX: An OpenGL profile requested but "
|
||||||
"GLX_ARB_create_context_profile is unavailable");
|
"GLX_ARB_create_context_profile is unavailable");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
@ -328,7 +327,7 @@ static int createContext(_GLFWwindow* window,
|
|||||||
!_glfwLibrary.GLX.EXT_create_context_es2_profile)
|
!_glfwLibrary.GLX.EXT_create_context_es2_profile)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"X11/GLX: OpenGL ES 2.x profile requested but "
|
"GLX: OpenGL ES 2.x profile requested but "
|
||||||
"GLX_EXT_create_context_es2_profile is unavailable");
|
"GLX_EXT_create_context_es2_profile is unavailable");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
@ -350,7 +349,7 @@ static int createContext(_GLFWwindow* window,
|
|||||||
if (!_glfwLibrary.GLX.ARB_create_context_robustness)
|
if (!_glfwLibrary.GLX.ARB_create_context_robustness)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"X11/GLX: An OpenGL robustness strategy was "
|
"GLX: An OpenGL robustness strategy was "
|
||||||
"requested but GLX_ARB_create_context_robustness "
|
"requested but GLX_ARB_create_context_robustness "
|
||||||
"is unavailable");
|
"is unavailable");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
@ -413,7 +412,7 @@ static int createContext(_GLFWwindow* window,
|
|||||||
// TODO: Handle all the various error codes here
|
// TODO: Handle all the various error codes here
|
||||||
|
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"X11/GLX: Failed to create OpenGL context");
|
"GLX: Failed to create OpenGL context");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,7 +452,7 @@ int _glfwInitOpenGL(void)
|
|||||||
|
|
||||||
if (!_glfwLibrary.GLX.libGL)
|
if (!_glfwLibrary.GLX.libGL)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to find libGL");
|
_glfwSetError(GLFW_PLATFORM_ERROR, "GLX: Failed to find libGL");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -461,7 +460,7 @@ int _glfwInitOpenGL(void)
|
|||||||
// Check if GLX is supported on this display
|
// Check if GLX is supported on this display
|
||||||
if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL))
|
if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL))
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: GLX support not found");
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "GLX: GLX support not found");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -470,7 +469,7 @@ int _glfwInitOpenGL(void)
|
|||||||
&_glfwLibrary.GLX.minorVersion))
|
&_glfwLibrary.GLX.minorVersion))
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
||||||
"X11/GLX: Failed to query GLX version");
|
"GLX: Failed to query GLX version");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,17 +580,13 @@ int _glfwCreateContext(_GLFWwindow* window,
|
|||||||
|
|
||||||
fbconfigs = getFBConfigs(window, &fbcount);
|
fbconfigs = getFBConfigs(window, &fbcount);
|
||||||
if (!fbconfigs)
|
if (!fbconfigs)
|
||||||
{
|
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
|
||||||
"X11/GLX: No usable GLXFBConfigs found");
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"X11/GLX: No GLXFBConfig matched the criteria");
|
"GLX: No GLXFBConfig matched the criteria");
|
||||||
|
|
||||||
free(fbconfigs);
|
free(fbconfigs);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// GLFW - An OpenGL library
|
// GLFW - An OpenGL library
|
||||||
// Platform: X11/GLX
|
// Platform: X11
|
||||||
// API version: 3.0
|
// API version: 3.0
|
||||||
// WWW: http://www.glfw.org/
|
// WWW: http://www.glfw.org/
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
@ -133,8 +133,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
|||||||
// TODO: Handle all the various error codes here and translate them
|
// TODO: Handle all the various error codes here and translate them
|
||||||
// to GLFW errors
|
// to GLFW errors
|
||||||
|
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR, "X11: Failed to create window");
|
||||||
"X11/GLX: Failed to create window");
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,7 +192,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
|||||||
if (!hints)
|
if (!hints)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
||||||
"X11/GLX: Failed to allocate WM hints");
|
"X11: Failed to allocate WM hints");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +209,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
|||||||
if (!hints)
|
if (!hints)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
||||||
"X11/GLX: Failed to allocate size hints");
|
"X11: Failed to allocate size hints");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -477,17 +476,10 @@ static void processEvent(XEvent *event)
|
|||||||
// A keyboard key was pressed
|
// A keyboard key was pressed
|
||||||
window = findWindow(event->xkey.window);
|
window = findWindow(event->xkey.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for KeyPress event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Translate and report key press
|
|
||||||
_glfwInputKey(window, translateKey(event->xkey.keycode), GLFW_PRESS);
|
|
||||||
|
|
||||||
// Translate and report character input
|
|
||||||
_glfwInputChar(window, translateChar(&event->xkey));
|
|
||||||
|
|
||||||
|
_glfwInputKey(window, translateKey(event.xkey.keycode), GLFW_PRESS);
|
||||||
|
_glfwInputChar(window, translateChar(&event.xkey));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,10 +488,7 @@ static void processEvent(XEvent *event)
|
|||||||
// A keyboard key was released
|
// A keyboard key was released
|
||||||
window = findWindow(event->xkey.window);
|
window = findWindow(event->xkey.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for KeyRelease event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Do not report key releases for key repeats. For key repeats we
|
// Do not report key releases for key repeats. For key repeats we
|
||||||
// will get KeyRelease/KeyPress pairs with similar or identical
|
// will get KeyRelease/KeyPress pairs with similar or identical
|
||||||
@ -527,9 +516,7 @@ static void processEvent(XEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate and report key release
|
_glfwInputKey(window, translateKey(event.xkey.keycode), GLFW_RELEASE);
|
||||||
_glfwInputKey(window, translateKey(event->xkey.keycode), GLFW_RELEASE);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,10 +525,7 @@ static void processEvent(XEvent *event)
|
|||||||
// A mouse button was pressed or a scrolling event occurred
|
// A mouse button was pressed or a scrolling event occurred
|
||||||
window = findWindow(event->xbutton.window);
|
window = findWindow(event->xbutton.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for ButtonPress event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (event->xbutton.button == Button1)
|
if (event->xbutton.button == Button1)
|
||||||
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS);
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS);
|
||||||
@ -570,10 +554,7 @@ static void processEvent(XEvent *event)
|
|||||||
// A mouse button was released
|
// A mouse button was released
|
||||||
window = findWindow(event->xbutton.window);
|
window = findWindow(event->xbutton.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for ButtonRelease event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (event->xbutton.button == Button1)
|
if (event->xbutton.button == Button1)
|
||||||
{
|
{
|
||||||
@ -601,10 +582,7 @@ static void processEvent(XEvent *event)
|
|||||||
// The cursor entered the window
|
// The cursor entered the window
|
||||||
window = findWindow(event->xcrossing.window);
|
window = findWindow(event->xcrossing.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for EnterNotify event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
||||||
hideCursor(window);
|
hideCursor(window);
|
||||||
@ -618,10 +596,7 @@ static void processEvent(XEvent *event)
|
|||||||
// The cursor left the window
|
// The cursor left the window
|
||||||
window = findWindow(event->xcrossing.window);
|
window = findWindow(event->xcrossing.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for LeaveNotify event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
||||||
showCursor(window);
|
showCursor(window);
|
||||||
@ -635,10 +610,7 @@ static void processEvent(XEvent *event)
|
|||||||
// The cursor was moved
|
// The cursor was moved
|
||||||
window = findWindow(event->xmotion.window);
|
window = findWindow(event->xmotion.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for MotionNotify event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (event->xmotion.x != window->X11.cursorPosX ||
|
if (event->xmotion.x != window->X11.cursorPosX ||
|
||||||
event->xmotion.y != window->X11.cursorPosY)
|
event->xmotion.y != window->X11.cursorPosY)
|
||||||
@ -676,10 +648,7 @@ static void processEvent(XEvent *event)
|
|||||||
// The window configuration changed somehow
|
// The window configuration changed somehow
|
||||||
window = findWindow(event->xconfigure.window);
|
window = findWindow(event->xconfigure.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for ConfigureNotify event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
_glfwInputWindowSize(window,
|
_glfwInputWindowSize(window,
|
||||||
event->xconfigure.width,
|
event->xconfigure.width,
|
||||||
@ -697,10 +666,7 @@ static void processEvent(XEvent *event)
|
|||||||
// Custom client message, probably from the window manager
|
// Custom client message, probably from the window manager
|
||||||
window = findWindow(event->xclient.window);
|
window = findWindow(event->xclient.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for ClientMessage event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if ((Atom) event->xclient.data.l[0] == _glfwLibrary.X11.wmDeleteWindow)
|
if ((Atom) event->xclient.data.l[0] == _glfwLibrary.X11.wmDeleteWindow)
|
||||||
{
|
{
|
||||||
@ -731,10 +697,7 @@ static void processEvent(XEvent *event)
|
|||||||
// The window was mapped
|
// The window was mapped
|
||||||
window = findWindow(event->xmap.window);
|
window = findWindow(event->xmap.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for MapNotify event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
_glfwInputWindowIconify(window, GL_FALSE);
|
_glfwInputWindowIconify(window, GL_FALSE);
|
||||||
break;
|
break;
|
||||||
@ -745,10 +708,7 @@ static void processEvent(XEvent *event)
|
|||||||
// The window was unmapped
|
// The window was unmapped
|
||||||
window = findWindow(event->xmap.window);
|
window = findWindow(event->xmap.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for UnmapNotify event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
_glfwInputWindowIconify(window, GL_TRUE);
|
_glfwInputWindowIconify(window, GL_TRUE);
|
||||||
break;
|
break;
|
||||||
@ -759,10 +719,7 @@ static void processEvent(XEvent *event)
|
|||||||
// The window gained focus
|
// The window gained focus
|
||||||
window = findWindow(event->xfocus.window);
|
window = findWindow(event->xfocus.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for FocusIn event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
_glfwInputWindowFocus(window, GL_TRUE);
|
_glfwInputWindowFocus(window, GL_TRUE);
|
||||||
|
|
||||||
@ -777,10 +734,7 @@ static void processEvent(XEvent *event)
|
|||||||
// The window lost focus
|
// The window lost focus
|
||||||
window = findWindow(event->xfocus.window);
|
window = findWindow(event->xfocus.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for FocusOut event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
_glfwInputWindowFocus(window, GL_FALSE);
|
_glfwInputWindowFocus(window, GL_FALSE);
|
||||||
|
|
||||||
@ -795,10 +749,7 @@ static void processEvent(XEvent *event)
|
|||||||
// The window's contents was damaged
|
// The window's contents was damaged
|
||||||
window = findWindow(event->xexpose.window);
|
window = findWindow(event->xexpose.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
|
||||||
fprintf(stderr, "Cannot find GLFW window structure for Expose event\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
_glfwInputWindowDamage(window);
|
_glfwInputWindowDamage(window);
|
||||||
break;
|
break;
|
||||||
|
@ -119,6 +119,32 @@ static void list_extensions(int major, int minor)
|
|||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GLboolean valid_version(void)
|
||||||
|
{
|
||||||
|
int major, minor, revision;
|
||||||
|
|
||||||
|
glfwGetVersion(&major, &minor, &revision);
|
||||||
|
|
||||||
|
printf("GLFW header version: %u.%u.%u\n",
|
||||||
|
GLFW_VERSION_MAJOR,
|
||||||
|
GLFW_VERSION_MINOR,
|
||||||
|
GLFW_VERSION_REVISION);
|
||||||
|
|
||||||
|
printf("GLFW library version: %u.%u.%u\n", major, minor, revision);
|
||||||
|
|
||||||
|
if (major != GLFW_VERSION_MAJOR)
|
||||||
|
{
|
||||||
|
printf("*** ERROR: GLFW major version mismatch! ***\n");
|
||||||
|
return GL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minor != GLFW_VERSION_MINOR || revision != GLFW_VERSION_REVISION)
|
||||||
|
printf("*** WARNING: GLFW version mismatch! ***\n");
|
||||||
|
|
||||||
|
printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
|
||||||
|
return GL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int ch, profile = 0, strategy = 0, major = 1, minor = 0, revision;
|
int ch, profile = 0, strategy = 0, major = 1, minor = 0, revision;
|
||||||
@ -126,6 +152,9 @@ int main(int argc, char** argv)
|
|||||||
GLint flags, mask;
|
GLint flags, mask;
|
||||||
GLFWwindow window;
|
GLFWwindow window;
|
||||||
|
|
||||||
|
if (!valid_version())
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "dfhlm:n:p:r:")) != -1)
|
while ((ch = getopt(argc, argv, "dfhlm:n:p:r:")) != -1)
|
||||||
{
|
{
|
||||||
switch (ch)
|
switch (ch)
|
||||||
@ -181,6 +210,8 @@ int main(int argc, char** argv)
|
|||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
|
// Initialize GLFW and create window
|
||||||
|
|
||||||
glfwSetErrorCallback(error_callback);
|
glfwSetErrorCallback(error_callback);
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
@ -216,26 +247,6 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
// Report GLFW version
|
|
||||||
|
|
||||||
glfwGetVersion(&major, &minor, &revision);
|
|
||||||
|
|
||||||
printf("GLFW header version: %u.%u.%u\n",
|
|
||||||
GLFW_VERSION_MAJOR,
|
|
||||||
GLFW_VERSION_MINOR,
|
|
||||||
GLFW_VERSION_REVISION);
|
|
||||||
|
|
||||||
printf("GLFW library version: %u.%u.%u\n", major, minor, revision);
|
|
||||||
|
|
||||||
if (major != GLFW_VERSION_MAJOR ||
|
|
||||||
minor != GLFW_VERSION_MINOR ||
|
|
||||||
revision != GLFW_VERSION_REVISION)
|
|
||||||
{
|
|
||||||
printf("*** WARNING: GLFW version mismatch! ***\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
|
|
||||||
|
|
||||||
// Report OpenGL version
|
// Report OpenGL version
|
||||||
|
|
||||||
printf("OpenGL context version string: \"%s\"\n", glGetString(GL_VERSION));
|
printf("OpenGL context version string: \"%s\"\n", glGetString(GL_VERSION));
|
||||||
|
@ -137,7 +137,7 @@ static void refresh_joysticks(void)
|
|||||||
j->axes = realloc(j->axes, j->axis_count * sizeof(float));
|
j->axes = realloc(j->axes, j->axis_count * sizeof(float));
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwGetJoystickPos(GLFW_JOYSTICK_1 + i, j->axes, j->axis_count);
|
glfwGetJoystickAxes(GLFW_JOYSTICK_1 + i, j->axes, j->axis_count);
|
||||||
|
|
||||||
button_count = glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_BUTTONS);
|
button_count = glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_BUTTONS);
|
||||||
if (button_count != j->button_count)
|
if (button_count != j->button_count)
|
||||||
|
Loading…
Reference in New Issue
Block a user