mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 04:54:35 +00:00
Updated some examples to new API.
This commit is contained in:
parent
e229ccd7c4
commit
0c4b67795d
@ -40,7 +40,7 @@
|
|||||||
/* Prototypes */
|
/* Prototypes */
|
||||||
void init( void );
|
void init( void );
|
||||||
void display( void );
|
void display( void );
|
||||||
void reshape( int w, int h );
|
void reshape( GLFWwindow window, int w, int h );
|
||||||
void DrawBoingBall( void );
|
void DrawBoingBall( void );
|
||||||
void BounceBall( double dt );
|
void BounceBall( double dt );
|
||||||
void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi );
|
void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi );
|
||||||
@ -222,7 +222,7 @@ void display(void)
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* reshape()
|
* reshape()
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void reshape( int w, int h )
|
void reshape( GLFWwindow window, int w, int h )
|
||||||
{
|
{
|
||||||
glViewport( 0, 0, (GLsizei)w, (GLsizei)h );
|
glViewport( 0, 0, (GLsizei)w, (GLsizei)h );
|
||||||
|
|
||||||
|
@ -215,13 +215,13 @@ static void animate(void)
|
|||||||
|
|
||||||
|
|
||||||
/* change view angle, exit upon ESC */
|
/* change view angle, exit upon ESC */
|
||||||
void key( int k, int action )
|
void key( GLFWwindow window, int k, int action )
|
||||||
{
|
{
|
||||||
if( action != GLFW_PRESS ) return;
|
if( action != GLFW_PRESS ) return;
|
||||||
|
|
||||||
switch (k) {
|
switch (k) {
|
||||||
case 'Z':
|
case 'Z':
|
||||||
if( glfwGetKey( GLFW_KEY_LSHIFT ) )
|
if( glfwGetKey( window, GLFW_KEY_LSHIFT ) )
|
||||||
view_rotz -= 5.0;
|
view_rotz -= 5.0;
|
||||||
else
|
else
|
||||||
view_rotz += 5.0;
|
view_rotz += 5.0;
|
||||||
@ -248,7 +248,7 @@ void key( int k, int action )
|
|||||||
|
|
||||||
|
|
||||||
/* new window size */
|
/* new window size */
|
||||||
void reshape( int width, int height )
|
void reshape( GLFWwindow window, int width, int height )
|
||||||
{
|
{
|
||||||
GLfloat h = (GLfloat) height / (GLfloat) width;
|
GLfloat h = (GLfloat) height / (GLfloat) width;
|
||||||
GLfloat xmax, znear, zfar;
|
GLfloat xmax, znear, zfar;
|
||||||
@ -321,29 +321,32 @@ static void init(int argc, char *argv[])
|
|||||||
/* program entry */
|
/* program entry */
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
GLFWwindow window;
|
||||||
|
|
||||||
if( !glfwInit() )
|
if( !glfwInit() )
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Failed to initialize GLFW\n" );
|
fprintf( stderr, "Failed to initialize GLFW\n" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !glfwOpenWindow( 300,300, 0,0,0,0, 16,0, GLFW_WINDOW ) )
|
window = glfwOpenWindow( 300,300, 0,0,0,0, 16,0, GLFW_WINDOW );
|
||||||
|
if (!window)
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowTitle( "Gears" );
|
glfwSetWindowTitle( window, "Gears" );
|
||||||
glfwEnable( GLFW_KEY_REPEAT );
|
glfwEnable( window, GLFW_KEY_REPEAT );
|
||||||
glfwSwapInterval( 1 );
|
glfwSwapInterval( 1 );
|
||||||
|
|
||||||
// Parse command-line options
|
// Parse command-line options
|
||||||
init(argc, argv);
|
init(argc, argv);
|
||||||
|
|
||||||
// Set callback functions
|
// Set callback functions
|
||||||
glfwSetWindowSizeCallback( reshape );
|
glfwSetWindowSizeCallback( window, reshape );
|
||||||
glfwSetKeyCallback( key );
|
glfwSetKeyCallback( window, key );
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while( running )
|
while( running )
|
||||||
@ -356,9 +359,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Swap buffers
|
// Swap buffers
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers();
|
||||||
|
glfwPollEvents();
|
||||||
|
|
||||||
// Was the window closed?
|
// Was the window closed?
|
||||||
if( !glfwGetWindowParam( GLFW_OPENED ) )
|
if( !glfwIsWindow( window ) )
|
||||||
{
|
{
|
||||||
running = 0;
|
running = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user