/* * Reference * http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:howto * https://github.com/SpriteStudio/SpriteStudio5-SDK/blob/master/viewer_sample/main.cpp */ #include #include #include //typedef void (* GLFWmousebuttonfun)(GLFWwindow*,int,int,int); void MouseButtonCB( GLFWwindow*,int button ,int action ,int mods) { TwEventMouseButtonGLFW( button , action ); } //typedef void (* GLFWcursorposfun)(GLFWwindow*,double,double); void MousePosCB(GLFWwindow*,double x ,double y) { TwEventMousePosGLFW( (int)x, (int)y ); } //typedef void (* GLFWkeyfun)(GLFWwindow*,int,int,int,int); void KeyFunCB( GLFWwindow* window,int key,int scancode,int action,int mods) { TwEventKeyGLFW( key , action ); TwEventCharGLFW( key , action ); } //typedef void (* GLFWscrollfun)(GLFWwindow*,double,double); void MouseScrollCB( GLFWwindow* window, double x , double y ) { TwEventMouseWheelGLFW( (int)y ); } int main(void) { GLFWwindow* window; int window_width = 640; int window_height = 480; /* Initialize the library */ if (!glfwInit()){ printf(" Can't initialize GLFW.\n"); return -1; } /* Setting of resize */ glfwWindowHint( GLFW_RESIZABLE, GL_FALSE); /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow(window_width, window_height, "AntTweakBar using GLFW", NULL, NULL); if (!window) { printf(" Can't create GLFW window.\n"); glfwTerminate(); return -1; } /* Make the window's context current */ glfwMakeContextCurrent(window); printf("============================================\n"); printf(" Vendor : %s\n",glGetString(GL_VENDOR)); printf(" GPU : %s\n",glGetString(GL_RENDERER)); printf(" OpenGL ver. %s\n",glGetString(GL_VERSION)); printf("============================================\n\n"); /* Initialize AntTweakBar */ TwInit(TW_OPENGL,NULL); /* Tell the size of the graphic window to AntTweakBar */ TwWindowSize(window_width,window_height); /* Create a tweak bar*/ TwBar *bar = TwNewBar("TweakBar"); TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLFW and OpenGL.' "); // Message added to the help bar. /* Set GLFW event callbacks */ // - Directly redirect GLFW mouse button events to AntTweakBar glfwSetMouseButtonCallback( window , MouseButtonCB ); // - Directly redirect GLFW mouse position events to AntTweakBar glfwSetCursorPosCallback( window , MousePosCB); // - Directly redirect GLFW mouse wheel events to AntTweakBar glfwSetScrollCallback( window , MouseScrollCB ); // - Directly redirect GLFW key events to AntTweakBar glfwSetKeyCallback(window , KeyFunCB); /* Initialize */ glClearColor(0.0, 0.0, 0.0, 0.0); // Background color glEnable(GL_DEPTH_TEST); // /* Loop until the user closes the window */ while (!glfwWindowShouldClose(window)) { /* Clear buffer */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Render here */ TwDraw(); // draw the tweak bar(s) /* Swap front and back buffers */ glfwSwapBuffers(window); /* Waiting for events */ glfwWaitEvents(); /* Poll for and process events */ //glfwPollEvents(); } TwTerminate(); glfwTerminate(); return 0; }