Removed calling of callbacks from setters.

This commit is contained in:
Camilla Berglund 2012-08-07 12:14:58 +02:00
parent c55f84ef3f
commit 8ed66ea4d5
7 changed files with 47 additions and 48 deletions

View File

@ -579,6 +579,7 @@ void DrawGrid( void )
int main( void )
{
GLFWwindow window;
int width, height;
/* Init GLFW */
if( !glfwInit() )
@ -587,6 +588,9 @@ int main( void )
exit( EXIT_FAILURE );
}
glfwSetWindowCloseCallback( window_close_callback );
glfwSetWindowSizeCallback( reshape );
glfwWindowHint(GLFW_DEPTH_BITS, 16);
window = glfwCreateWindow( 400, 400, GLFW_WINDOWED, "Boing (classic Amiga demo)", NULL );
@ -597,8 +601,9 @@ int main( void )
exit( EXIT_FAILURE );
}
glfwSetWindowCloseCallback( window_close_callback );
glfwSetWindowSizeCallback( reshape );
glfwGetWindowSize(window, &width, &height);
reshape(window, width, height);
glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
glfwSwapInterval( 1 );
glfwSetTime( 0.0 );

View File

@ -330,6 +330,7 @@ static void init(int argc, char *argv[])
int main(int argc, char *argv[])
{
GLFWwindow window;
int width, height;
if( !glfwInit() )
{
@ -337,6 +338,11 @@ int main(int argc, char *argv[])
exit( EXIT_FAILURE );
}
// Set callback functions
glfwSetWindowCloseCallback(window_close_callback);
glfwSetWindowSizeCallback( reshape );
glfwSetKeyCallback( key );
glfwWindowHint(GLFW_DEPTH_BITS, 16);
window = glfwCreateWindow( 300, 300, GLFW_WINDOWED, "Gears", NULL );
@ -347,17 +353,15 @@ int main(int argc, char *argv[])
exit( EXIT_FAILURE );
}
glfwGetWindowSize(window, &width, &height);
reshape(window, width, height);
glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE );
glfwSwapInterval( 1 );
// Parse command-line options
init(argc, argv);
// Set callback functions
glfwSetWindowCloseCallback(window_close_callback);
glfwSetWindowSizeCallback( reshape );
glfwSetKeyCallback( key );
// Main loop
while( running )
{

View File

@ -456,6 +456,7 @@ static int windowCloseFun(GLFWwindow window)
int main(void)
{
GLFWwindow window;
int width, height;
// Initialise GLFW
if (!glfwInit())
@ -464,6 +465,13 @@ int main(void)
exit(EXIT_FAILURE);
}
// Set callback functions
glfwSetWindowCloseCallback(windowCloseFun);
glfwSetWindowSizeCallback(windowSizeFun);
glfwSetWindowRefreshCallback(windowRefreshFun);
glfwSetCursorPosCallback(cursorPosFun);
glfwSetMouseButtonCallback(mouseButtonFun);
glfwWindowHint(GLFW_DEPTH_BITS, 16);
// Open OpenGL window
@ -474,6 +482,9 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwGetWindowSize(window, &width, &height);
windowSizeFun(window, width, height);
// Enable vsync
glfwSwapInterval(1);
@ -483,13 +494,6 @@ int main(void)
// Enable mouse cursor (only needed for fullscreen mode)
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
// Set callback functions
glfwSetWindowCloseCallback(windowCloseFun);
glfwSetWindowSizeCallback(windowSizeFun);
glfwSetWindowRefreshCallback(windowRefreshFun);
glfwSetCursorPosCallback(cursorPosFun);
glfwSetMouseButtonCallback(mouseButtonFun);
// Main loop
do
{

View File

@ -355,7 +355,7 @@ void scroll_callback(GLFWwindow window, double x, double y)
// Callback function for window resize events
//========================================================================
void window_resize_callback(GLFWwindow window, int width, int height)
void window_size_callback(GLFWwindow window, int width, int height)
{
float ratio = 1.f;
@ -391,6 +391,7 @@ int main(int argc, char* argv[])
{
GLFWwindow window;
double t, dt_total, t_old;
int width, height;
if (!glfwInit())
{
@ -398,6 +399,13 @@ int main(int argc, char* argv[])
exit(EXIT_FAILURE);
}
glfwSetKeyCallback(key_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetMouseButtonCallback(mouse_button_callback);
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetScrollCallback(scroll_callback);
window = glfwCreateWindow(640, 480, GLFW_WINDOWED, "Wave Simulation", NULL);
if (!window)
{
@ -405,19 +413,13 @@ int main(int argc, char* argv[])
exit(EXIT_FAILURE);
}
glfwGetWindowSize(window, &width, &height);
window_size_callback(window, width, height);
glfwSwapInterval(1);
// Keyboard handler
glfwSetKeyCallback(key_callback);
glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);
// Window resize handler
glfwSetWindowCloseCallback(window_close_callback);
glfwSetWindowSizeCallback(window_resize_callback);
glfwSetMouseButtonCallback(mouse_button_callback);
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetScrollCallback(scroll_callback);
// Initialize OpenGL
init_opengl();

View File

@ -551,16 +551,6 @@ GLFWAPI void glfwSetCursorPosCallback(GLFWcursorposfun cbfun)
}
_glfwLibrary.cursorPosCallback = cbfun;
// Call the callback function to let the application know the current
// cursor position
if (cbfun)
{
_GLFWwindow* window;
for (window = _glfwLibrary.windowListHead; window; window = window->next)
cbfun(window, window->cursorPosX, window->cursorPosY);
}
}

View File

@ -762,16 +762,6 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun)
}
_glfwLibrary.windowSizeCallback = cbfun;
// Call the callback function to let the application know the current
// window size
if (cbfun)
{
_GLFWwindow* window;
for (window = _glfwLibrary.windowListHead; window; window = window->next)
cbfun(window, window->width, window->height);
}
}

View File

@ -80,6 +80,7 @@ static void key_callback(GLFWwindow window, int key, int action)
int main(void)
{
GLFWwindow window;
int width, height;
if (!glfwInit())
{
@ -87,6 +88,10 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetKeyCallback(key_callback);
window = glfwCreateWindow(window_width, window_height, GLFW_WINDOWED, "", NULL);
if (!window)
{
@ -96,11 +101,10 @@ int main(void)
exit(EXIT_FAILURE);
}
set_swap_interval(window, swap_interval);
glfwGetWindowSize(window, &width, &height);
window_size_callback(window, width, height);
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetKeyCallback(key_callback);
set_swap_interval(window, swap_interval);
while (glfwGetCurrentContext())
{