int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(800, 600); glutCreateWindow("Multiple Point Lights"); #ifdef FREEGLUT // Note: glutSetOption n'est disponible qu'avec freeGLUT glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS); #endif Initialize(); glutReshapeFunc(Resize); glutIdleFunc(Update); glutDisplayFunc(Render); // redirection pour AntTweakBar // dans le cas ou vous utiliseriez deja ces callbacks // il suffit d'appeler l'event d'AntTweakBar depuis votre fonction de rappel glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT); glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT); TwGLUTModifiersFunc(glutGetModifiers); glutMainLoop(); Terminate(); return 0; }
void RotationsViewer::initializeGui() { glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); TwGLUTModifiersFunc(glutGetModifiers); TwInit(TW_OPENGL, NULL); TwWindowSize(mWindowWidth, mWindowHeight); TwCopyStdStringToClientFunc(onCopyStdStringToClient); mDemoBar = TwNewBar("Demo controls"); TwDefine(" 'Demo controls' size='200 175' position='5 5' iconified=false fontresizable=false alpha=200"); TwEnumVal modeTypeEV[] = { { DEMO1, "Convert" }, { DEMO2, "Curve" } }; modeType = TwDefineEnum("ModeType", modeTypeEV, 2); TwAddVarRW(mDemoBar, "Demo", modeType, &mMode, NULL); TwAddVarRW(mDemoBar, "X Angle", TW_TYPE_DOUBLE, &mXAngle, " group='Convert params' "); TwAddVarRW(mDemoBar, "Y Angle", TW_TYPE_DOUBLE, &mYAngle, " group='Convert params' "); TwAddVarRW(mDemoBar, "Z Angle", TW_TYPE_DOUBLE, &mZAngle, " group='Convert params' "); TwEnumVal rooTypeEV[] = { { XYZ, "XYZ" }, { XZY, "XZY" }, { YXZ, "YXZ" }, { YZX, "YZX" }, { ZXY, "ZXY" }, { ZYX, "ZYX" } }; rooType = TwDefineEnum("RooType", rooTypeEV, 6); TwAddVarRW(mDemoBar, "Rot Order", rooType, &mRotOrder, " group='Convert params' "); TwEnumVal splineTypeEV[] = { { ASplineQuat::LINEAR, "Linear" }, { ASplineQuat::CUBIC, "Cubic" } }; splineType = TwDefineEnum("SplineType", splineTypeEV, 2); TwAddVarCB(mDemoBar, "Spline type", splineType, onSetStyleCb, onGetStyleCb, this, " group='Curve params'"); }
void DemoWindow::initTWBar() { glutCreateMenu(NULL); // Initialize AntTweakBar TwInit(TW_OPENGL, NULL); //// Set GLUT event callbacks // // - Directly redirect GLUT mouse button events to AntTweakBar // glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); // // - Directly redirect GLUT mouse motion events to AntTweakBar // glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); // // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion) // glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); // // - Directly redirect GLUT key events to AntTweakBar // glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT); // // - Directly redirect GLUT special key events to AntTweakBar // glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT); // - Send 'glutGetModifers' function pointer to AntTweakBar; // required because the GLUT key event functions do not report key modifiers states. TwGLUTModifiersFunc(glutGetModifiers); bar = TwNewBar("TweakBar"); TwWindowSize(100, 100); TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar. TwDefine(" TweakBar size='200 400' color='96 216 224' "); // change default tweak bar size and color }
int main(int args, char **argv) { glutInit(&args, argv); glutInitWindowSize(800, 600); glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("simple vertex shader"); TwInit(TW_OPENGL, NULL); TwBar *bar = TwNewBar("myBar"); TwDefine("myBar size='200 400' color = '96 216 224'"); TwAddVarRW(bar, "ObjectRotate", TW_TYPE_QUAT4F, &g_Rotate, "label='Object Rotation' opened=true"); TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &g_lightPos, "label='light Pos' opened=true"); glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT); TwGLUTModifiersFunc(glutGetModifiers); glutDisplayFunc(RenderScene); glutReshapeFunc(ChangeSize); SetupRC(); glutMainLoop(); Terminate(); return 0; }
int main( int argc, char ** argv ) { // Размеры окна по-умолчанию size_t const default_width = 800; size_t const default_height = 800; glutInit (&argc, argv); glutInitWindowSize (default_width, default_height); // Указание формата буфера экрана: // - GLUT_DOUBLE - двойная буферизация // - GLUT_RGB - 3-ёх компонентный цвет // - GLUT_DEPTH - будет использоваться буфер глубины glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); // Создаем контекст версии 3.2 glutInitContextVersion (3, 0); // Контекст будет поддерживать отладку и "устаревшую" функциональность, которой, например, может пользоваться библиотека AntTweakBar // glutInitContextFlags (GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG); // Указание либо на core либо на compatibility профил //glutInitContextProfile (GLUT_COMPATIBILITY_PROFILE ); int window_handle = glutCreateWindow("OpenGL basic sample"); // Инициализация указателей на функции OpenGL if (glewInit() != GLEW_OK) { cerr << "GLEW init failed" << endl; return 1; } // Проверка созданности контекста той версии, какой мы запрашивали if (!GLEW_VERSION_3_0) { cerr << "OpenGL 3.0 not supported" << endl; return 1; } // подписываемся на оконные события glutReshapeFunc(reshape_func); glutDisplayFunc(display_func); glutIdleFunc (idle_func ); glutCloseFunc (close_func ); glutKeyboardFunc(keyboard_func); // подписываемся на события для AntTweakBar'а glutMouseFunc ((GLUTmousebuttonfun)TwEventMouseButtonGLUT); glutMotionFunc ((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutSpecialFunc ((GLUTspecialfun )TwEventSpecialGLUT ); TwGLUTModifiersFunc (glutGetModifiers); try { // Создание класса-примера prog_state_ptr.reset(new prog_state()); // Вход в главный цикл приложения glutMainLoop(); } catch( std::exception const & except ) { std::cout << except.what() << endl; return 1; } return 0; }
void registerCallbacks() { // set the event handling methods TwGLUTModifiersFunc(glutGetModifiers); glutDisplayFunc(Repaint); glutReshapeFunc(Reshape); glutMouseFunc(MouseButton); glutMotionFunc(MouseMotion); glutKeyboardFunc(Keyboard); glutIdleFunc(Idle); glutFullScreen(); fullScreen=true; }
void creatTweakBar(void) { TwInit(TW_OPENGL, NULL); TwBar *myBar; myBar = TwNewBar("Tweak"); TwWindowSize(globals.width, globals.height); TwAddVarRW(myBar, "Period", TW_TYPE_FLOAT, &globals.period, "min = 1.0, max = 10.0, step = 1.0"); TwAddVarRW(myBar, "Point Size", TW_TYPE_FLOAT, &globals.pointSize, "min = 1.0, max = 20.0, step = 1.0"); // after GLUT initialization // directly redirect GLUT events to AntTweakBar glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); // same as MouseMotion glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT); glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT); // send the ''glutGetModifers'' function pointer to AntTweakBar TwGLUTModifiersFunc(glutGetModifiers); }
void Initialize(int argc, char **argv){ // To initialize GLUT and window glutInit(&argc, argv); glutInitContextFlags(GLUT_FORWARD_COMPATIBLE); glutInitContextProfile(GLUT_CORE_PROFILE); glutInitWindowSize(800, 600); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutCreateWindow("Project II"); glClearColor(0.0f, 0.0f, 0.4f, 0.0f); switch (sm) { case 0: glShadeModel(GL_FLAT); break; case 1: glShadeModel(GL_SMOOTH); break; default: glShadeModel(GL_FLAT); break; } glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glReadBuffer(GL_BACK); glDrawBuffer(GL_BACK); glEnable(GL_CULL_FACE); // Initialize AntTweakBar TwInit(TW_OPENGL, NULL); // Set GLUT event callbacks glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT); glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT); TwGLUTModifiersFunc(glutGetModifiers); }
// Main int main(int argc, char *argv[]) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); glutInitWindowSize( 800, 600 ); glutCreateWindow( "Font rendering advanced tweaking" ); glutCreateMenu( NULL ); #ifndef __APPLE__ GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf( stderr, "Error: %s\n", glewGetErrorString(err) ); exit( EXIT_FAILURE ); } fprintf( stderr, "Using GLEW %s\n", glewGetString(GLEW_VERSION) ); #endif glutDisplayFunc( display ); glutReshapeFunc( reshape ); atexit( terminate ); TwInit( TW_OPENGL, NULL ); glutMouseFunc( (GLUTmousebuttonfun)TwEventMouseButtonGLUT ); glutMotionFunc( (GLUTmousemotionfun)TwEventMouseMotionGLUT ); glutPassiveMotionFunc( (GLUTmousemotionfun)TwEventMouseMotionGLUT ); glutKeyboardFunc( (GLUTkeyboardfun)TwEventKeyboardGLUT ); glutSpecialFunc( (GLUTspecialfun)TwEventSpecialGLUT ); TwGLUTModifiersFunc( glutGetModifiers ); // Create a new tweak bar bar = TwNewBar("TweakBar"); TwDefine("GLOBAL " "help = 'This example shows how to tune all font parameters.' "); TwDefine("TweakBar " "size = '280 400' " "position = '500 20' " "color = '127 127 127' " "alpha = 240 " "label = 'Parameters' " "resizable = True " "fontresizable = True " "iconifiable = True "); { TwEnumVal familyEV[NUM_FONTS] = { {VERA, "Vera"}, {VERA_MONO, "Vera Mono"}, {LUCKIEST_GUY, "Luckiest Guy"}, {SOURCE_SANS, "Source Sans Pro"}, {SOURCE_CODE, "Source Code Pro"}, {OLD_STANDARD, "Old Standard TT"}, {LOBSTER, "Lobster"} }; TwType family_type = TwDefineEnum("Family", familyEV, NUM_FONTS); TwAddVarCB(bar, "Family", family_type, set_family, get_family, NULL, "label = 'Family' " "group = 'Font' " "help = ' ' "); } TwAddVarCB(bar, "Size", TW_TYPE_FLOAT, set_size, get_size, NULL, "label = 'Size' " "group = 'Font' " "min = 6.0 " "max = 24.0 " "step = 0.05 " "help = ' ' "); TwAddVarCB(bar, "LCD filtering", TW_TYPE_BOOL32, set_lcd_filtering, get_lcd_filtering, NULL, "label = 'LCD filtering' " "group = 'Font' " "help = ' ' "); // Rendering TwAddVarCB(bar, "Kerning", TW_TYPE_BOOL32, set_kerning, get_kerning, NULL, "label = 'Kerning' " "group = 'Rendering' " "help = ' ' "); TwAddVarCB(bar, "Hinting", TW_TYPE_BOOL32, set_hinting, get_hinting, NULL, "label = 'Hinting' " "group = 'Rendering' " "help = ' ' "); // Color TwAddVarCB(bar, "Invert", TW_TYPE_BOOL32, set_invert, get_invert, NULL, "label = 'Invert' " "group = 'Color' " "help = ' ' "); // Glyph TwAddVarCB(bar, "Width", TW_TYPE_FLOAT, set_width, get_width, NULL, "label = 'Width' " "group = 'Glyph' " "min = 0.75 " "max = 1.25 " "step = 0.01 " "help = ' ' "); TwAddVarCB(bar, "Interval", TW_TYPE_FLOAT, set_interval, get_interval, NULL, "label = 'Spacing' " "group = 'Glyph' " "min = -0.2 " "max = 0.2 " "step = 0.01 " "help = ' ' " ); TwAddVarCB(bar, "Faux italic", TW_TYPE_FLOAT, set_faux_italic, get_faux_italic, NULL, "label = 'Faux italic' " "group = 'Glyph' " "min = -30.0 " "max = 30.0 " "step = 0.1 " "help = ' ' "); // Energy distribution TwAddVarCB(bar, "Primary", TW_TYPE_FLOAT, set_primary, get_primary, NULL, "label = 'Primary weight' " "group = 'Energy distribution' " "min = 0 " "max = 1 " "step = 0.01 " "help = ' ' " ); TwAddVarCB(bar, "Secondary", TW_TYPE_FLOAT, set_secondary, get_secondary, NULL, "label = 'Secondy weight' " "group = 'Energy distribution' " "min = 0 " "max = 1 " "step = 0.01 " "help = ' ' " ); TwAddVarCB(bar, "Tertiary", TW_TYPE_FLOAT, set_tertiary, get_tertiary, NULL, "label = 'Tertiary weight' " "group = 'Energy distribution' " "min = 0 " "max = 1 " "step = 0.01 " "help = ' ' " ); TwAddSeparator(bar, "", "group = 'Energy distribution' " ); TwAddVarCB(bar, "Gamma", TW_TYPE_FLOAT, set_gamma, get_gamma, NULL, "label = 'Gamma correction' " "group = 'Energy distribution' " "min = 0.50 " "max = 2.5 " "step = 0.01 " "help = ' ' "); TwAddSeparator(bar, "", ""); TwAddButton(bar, "Reset", (TwButtonCallback) reset, NULL, "help='Reset all parameters to default values.'"); TwAddSeparator(bar, "", ""); TwAddButton(bar, "Quit", (TwButtonCallback) quit, NULL, "help='Quit.'"); buffer_a = text_buffer_new( 1 ); buffer_rgb = text_buffer_new( 3 ); buffer = buffer_rgb; reset(); glutTimerFunc( 1000.0/60.0, timer, 60 ); mat4_set_identity( &projection ); mat4_set_identity( &model ); mat4_set_identity( &view ); glutMainLoop(); return EXIT_SUCCESS; }
// Main int main(int argc, char *argv[]) { TwBar *bar; // Pointer to the tweak bar float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation float angle = 0.8f; // Initialize AntTweakBar // (note that AntTweakBar could also be intialized after GLUT, no matter) if( !TwInit(TW_OPENGL, NULL) ) { // A fatal error occured fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError()); return 1; } // Initialize GLUT glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(640, 480); glutCreateWindow("AntTweakBar simple example using GLUT"); glutCreateMenu(NULL); // Set GLUT callbacks glutDisplayFunc(Display); glutReshapeFunc(Reshape); atexit(Terminate); // Called after glutMainLoop ends // Set GLUT event callbacks // - Directly redirect GLUT mouse button events to AntTweakBar glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); // - Directly redirect GLUT mouse motion events to AntTweakBar glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion) glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); // - Directly redirect GLUT key events to AntTweakBar glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT); // - Directly redirect GLUT special key events to AntTweakBar glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT); // - Send 'glutGetModifers' function pointer to AntTweakBar; // required because the GLUT key event functions do not report key modifiers states. TwGLUTModifiersFunc(glutGetModifiers); // Create some 3D objects (stored in display lists) glNewList(SHAPE_TEAPOT, GL_COMPILE); glutSolidTeapot(1.0); glEndList(); glNewList(SHAPE_TORUS, GL_COMPILE); glutSolidTorus(0.3, 1.0, 16, 32); glEndList(); glNewList(SHAPE_CONE, GL_COMPILE); glutSolidCone(1.0, 1.5, 64, 4); glEndList(); // Create a tweak bar bar = TwNewBar("TweakBar"); TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar. TwDefine(" TweakBar size='200 400' color='96 216 224' "); // change default tweak bar size and color // Add 'g_Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z]. TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' "); // Add 'g_Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, " label='Object rotation' open help='Change the object orientation.' "); // Add callback to toggle auto-rotate mode (callback functions are defined above). TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, " label='Auto-rotate' key=space help='Toggle auto-rotate mode.' "); // Add 'g_LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-]. TwAddVarRW(bar, "Multiplier", TW_TYPE_FLOAT, &g_LightMultiplier, " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' "); // Add 'g_LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &g_LightDirection, " label='Light direction' open help='Change the light direction.' "); // Add 'g_MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored) // and is inserted into a group named 'Material'. TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &g_MatAmbient, " group='Material' "); // Add 'g_MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored) // and is inserted into group 'Material'. TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse, " group='Material' "); // Add the enum variable 'g_CurrentShape' to 'bar' // (before adding an enum variable, its enum type must be declared to AntTweakBar as follow) { // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} }; // Create a type for the enum shapeEV TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES); // add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>]. TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' help='Change object shape.' "); } // Store time g_RotateTime = glutGet(GLUT_ELAPSED_TIME); // Init rotation SetQuaternionFromAxisAngle(axis, angle, g_Rotation); SetQuaternionFromAxisAngle(axis, angle, g_RotateStart); // Call the GLUT main loop glutMainLoop(); return 0; }
// main func is temporary ugly int main(int argc, char ** argv) { srand(time(NULL)); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE | GLUT_ACCUM); glutInitWindowPosition(glutGet(GLUT_SCREEN_WIDTH) / 14, glutGet(GLUT_SCREEN_HEIGHT) / 21); glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH) * 6 / 7, glutGet(GLUT_SCREEN_HEIGHT) * 6/7); int window = glutCreateWindow("Star System"); //glutFullScreen(); glEnable(GL_ACCUM); glEnable(GL_DEPTH_TEST); //glEnable(GL_LINE_SMOOTH); //glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); //glCullFace(GL_BACK); //glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glutInitContextFlags(GLUT_FORWARD_COMPATIBLE); TwInit(TW_OPENGL, NULL); glutDisplayFunc(GlutCB::Display); glutReshapeFunc(GlutCB::Reshape); glutMouseFunc(GlutCB::Mouse); glutMotionFunc(GlutCB::Motion); glutPassiveMotionFunc(GlutCB::PassiveMotion); glutKeyboardFunc(GlutCB::Keyboard); glutKeyboardUpFunc(GlutCB::KeyboardUp); glutSpecialFunc(GlutCB::Special); glutSpecialUpFunc(GlutCB::SpecialUp); TwGLUTModifiersFunc(glutGetModifiers); glutTimerFunc(Constants::deltaTime, GlutCB::Timer, 1); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); Star sun("Sun", 2.0e30, 1.4e9, Vector3f(1.0f, 1.0f, 0.0f), Vector3d(0.0, 0.0, 0.0), Vector3d(0.0, 0.0, 0.0)); Planet mercury("Mercury", 3.3e23, 5.0e6, Vector3f(0.8f, 0.0f, 0.0f), Vector3d(4.6e10, 0.0, 0.0), Vector3d(0.0, 4.7e4, 0.0)); Planet venus("Venus", 4.8e24, 1.2e7, Vector3f(0.8f, 0.6f, 0.7f), Vector3d(1.0e11, 0.0, 0.0), Vector3d(0.0, 3.5e4, 0.0)); Planet earth("Earth", 6.0e24, 1.2e7, Vector3f(0.0f, 0.0f, 1.0f), Vector3d(1.5e11, 0.0, 0.0), Vector3d(0.0, 3.0e4, 0.0)); Sputnik moon("Moon", 7.35e22, 3.4e6, Vector3f(0.7f, 0.7f, 0.7f), &earth, Vector3d(4.0e8, 0.0, 0.0), Vector3d(0.0, 1.0e3, 0.0)); Planet mars("Mars", 6.4e23, 6.7e6, Vector3f(1.0f, 0.0f, 0.0f), Vector3d(2.0e11, 0.0, 0.0), Vector3d(0.0, 2.4e4, 0.0)); Teapot rasselsTeapot("RasselsTeapot", 0.0, 0.3, Vector3f(1.0f, 1.0f, 1.0f), Vector3d(3.0e11, 0.0, 0.0), Vector3d(0.0, 2.0e4, 0.0)); Planet jupiter("Jupiter", 1.9e27, 1.3e8, Vector3f(1.0f, 0.8f, 0.0f), Vector3d(7.4e11, 0.0, 0.0), Vector3d(0.0, 1.3e4, 0.0)); RenderManager * renderManager = RenderManager::getInstance(); renderManager->initAll(); Camera * camera = new Camera(); ControlPane * ctrlPane = ControlPane::getInstance(camera, renderManager); ctrlPane->show(); TwCopyStdStringToClientFunc(CopyStdStringToClient); ctrlPane->addSpaceObject(&sun); renderManager->renderSpaceObject(&sun); ctrlPane->addSpaceObject(&mercury); renderManager->renderSpaceObject(&mercury); ctrlPane->addSpaceObject(&venus); renderManager->renderSpaceObject(&venus); ctrlPane->addSpaceObject(&earth); renderManager->renderSpaceObject(&earth); ctrlPane->addSpaceObject(&moon); renderManager->renderSpaceObject(&moon); ctrlPane->addSpaceObject(&mars); renderManager->renderSpaceObject(&mars); ctrlPane->addSpaceObject(&rasselsTeapot); renderManager->renderSpaceObject(&rasselsTeapot); ctrlPane->addSpaceObject(&jupiter); renderManager->renderSpaceObject(&jupiter); GlutCBInitializer::init(camera, renderManager); glutMainLoop(); delete ctrlPane; glutDestroyWindow(window); return EXIT_SUCCESS; }
// Main int main(int argc, char *argv[]) { TwBar *bar; // Pointer to a tweak bar // Initialize AntTweakBar // (note that AntTweakBar could also be intialize after GLUT, no matter) if( !TwInit(TW_OPENGL, NULL) ) { // A fatal error occured fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError()); return 1; } // Initialize GLUT glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(640, 480); glutCreateWindow("AntTweakBar simple example using GLUT"); glutCreateMenu(NULL); // Set GLUT callbacks glutDisplayFunc(Display); glutReshapeFunc(Reshape); atexit(Terminate); // Called after glutMainLoop ends // Set GLUT event callbacks // - Directly redirect GLUT mouse button events to AntTweakBar glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); // - Directly redirect GLUT mouse motion events to AntTweakBar glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion) glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); // - Directly redirect GLUT key events to AntTweakBar glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT); // - Directly redirect GLUT special key events to AntTweakBar glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT); // - Send 'glutGetModifers' function pointer to AntTweakBar; // required because the GLUT key event functions do not report key modifiers states. TwGLUTModifiersFunc(glutGetModifiers); // Create some 3D objects (stored in display lists) glNewList(SHAPE_TEAPOT, GL_COMPILE); glutSolidTeapot(1.0); glEndList(); glNewList(SHAPE_TORUS, GL_COMPILE); glutSolidTorus(0.3, 1.0, 16, 32); glEndList(); glNewList(SHAPE_CONE, GL_COMPILE); glutSolidCone(1.0, 1.5, 64, 4); glEndList(); // Create a tweak bar bar = TwNewBar("TweakBar"); // Add 'g_Zoom' to 'bar': it is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z]. TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z "); // Add 'g_LightMultiplier' to 'bar': it is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-]. TwAddVarRW(bar, "Multiplier", TW_TYPE_FLOAT, &g_LightMultiplier, " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' "); // Add 'g_MatAmbient' to 'bar': it is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored). It is inserted into a group named 'Material'. TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &g_MatAmbient, " group='Material' "); // Add 'g_MatDiffuse' to 'bar': it is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored). It is inserted into group 'Material'. TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse, " group='Material' "); // Add the enum variable 'g_CurrentShape' to 'bar' // (before adding an enum variable, its enum type must be declared to AntTweakBar as follow) { // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} }; // Create a type for the enum shapeEV TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES); // add 'g_CurrentShape' to 'bar': it is a variable of type ShapeType. Its key shortcuts are [<] and [>]. TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' "); } // Call the GLUT main loop glutMainLoop(); return 0; }
int main(int argc, char *argv[]) { TwBar *bar; float axis[] = { 0.7f, 0.7f, 0.0f }; float angle = 0.8f; winW = 640; winH = 480; glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(640, 480); glutCreateWindow("Assignment3- Skinning"); glutCreateMenu(NULL); glutDisplayFunc(Display); glutReshapeFunc(Reshape); atexit(Terminate); TwInit(TW_OPENGL, NULL); glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT); glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT); TwGLUTModifiersFunc(glutGetModifiers); //Todo Matrices identity; skeletonWasp = new Skeleton("wasp_walk.skel"); skinningWasp = new skin("wasp_walk.skin", skeletonWasp->worldMatrixes); animation = new Animation("wasp_walk.anim", skeletonWasp->joints); skeletonWasp->calculate(identity.IDENTITY); skinningWasp->update(); bar = TwNewBar("TweakBar"); TwDefine(" GLOBAL help='This is rotate and zoom the skeleton also to change the lighting effects' "); TwDefine(" TweakBar size='200 400' color='96 216 224' "); TwAddButton(bar, "Reset", ResetValues, NULL, " label='Resets the View' "); TwAddButton(bar, "Animate", StartAnimation, NULL, " label='Starts the animation' "); TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' "); TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, " label='Object rotation' opened=true help='Change the object orientation.' "); TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, " label='Auto-rotate' key=space help='Toggle auto-rotate mode.' "); TwAddVarRW(bar, "Multiplier", TW_TYPE_FLOAT, &g_LightMultiplier, " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' "); TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &g_LightDirection, " label='Light direction' opened=true help='Change the light direction.' "); TwAddVarRW(bar, "LightDir2", TW_TYPE_DIR3F, &g_LightDirection2, " label='Light direction' opened=true help='Change the light direction.' "); TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &g_MatAmbient1, " group='Material' "); TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse1, " group='Material' "); { TwEnumVal shapeEV[NUM_SHAPES] = { { WASP, "Wasp" } }; TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES); TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' help='Change object shape.' "); } g_RotateTime = GetTimeMs(); SetQuaternionFromAxisAngle(axis, angle, g_Rotation); SetQuaternionFromAxisAngle(axis, angle, g_RotateStart); CreateBar(); glutMainLoop(); return 0; }
// Setup new sub-window void SetupSubWindow(int subWinIdx) { float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation float angle = 0.8f; SubWindowData *win; win = &g_SubWindowData[subWinIdx]; win->ObjectShape = (subWinIdx == 0) ? SHAPE_TEAPOT : SHAPE_TORUS; win->Zoom = 1; win->AutoRotate = (subWinIdx == 0); win->MatAmbient[0] = (subWinIdx == 1) ? 0.0f : 0.5f;; win->MatAmbient[1] = win->MatAmbient[2] = 0.2f; win->MatAmbient[3] = 1; win->MatDiffuse[0] = (subWinIdx == 1) ? 0.0f : 1.0f; win->MatDiffuse[1] = 1; win->MatDiffuse[2] = 0; win->MatDiffuse[3] = 1; win->LightMultiplier = 1; win->LightDirection[0] = win->LightDirection[1] = win->LightDirection[2] = -0.57735f; win->RotateTime = GetTimeMs(); SetQuaternionFromAxisAngle(axis, angle, win->Rotation); SetQuaternionFromAxisAngle(axis, angle, win->RotateStart); glutSetWindow(win->WinID); // Set GLUT callbacks glutDisplayFunc(DisplaySubWindow); glutReshapeFunc(ReshapeSubWindow); // Set GLUT event callbacks // - Register mouse button events callback glutMouseFunc((GLUTmousebuttonfun)MouseButtonCB); // - Register mouse motion events callback glutMotionFunc((GLUTmousemotionfun)MouseMotionCB); // - Register mouse "passive" motion events (same as Motion) glutPassiveMotionFunc((GLUTmousemotionfun)MouseMotionCB); // - Register keyboard events callback glutKeyboardFunc((GLUTkeyboardfun)KeyboardCB); // - Register special key events callback glutSpecialFunc((GLUTspecialfun)SpecialKeyCB); // - Send 'glutGetModifers' function pointer to AntTweakBar; // required because the GLUT key event functions do not report key modifiers states. TwGLUTModifiersFunc(glutGetModifiers); // Create some 3D objects (stored in display lists) glNewList(SHAPE_TEAPOT, GL_COMPILE); glutSolidTeapot(1.0); glEndList(); glNewList(SHAPE_TORUS, GL_COMPILE); glutSolidTorus(0.3, 1.0, 16, 32); glEndList(); glNewList(SHAPE_CONE, GL_COMPILE); glutSolidCone(1.0, 1.5, 64, 4); glEndList(); // Declare this window as current for AntTweakBar. // Here, this will create a new AntTweakBar context for this window, // which will be identified by the number WinID. TwSetCurrentWindow(win->WinID); // Create a tweak bar win->Bar = TwNewBar("TweakBar"); TwDefine(" GLOBAL help='This example shows how to use AntTweakBar with multiple windows.' "); // Message added to the help bar. TwDefine(" TweakBar size='200 400' color='96 216 224' "); // change default tweak bar size and color // Add 'win->Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z]. TwAddVarRW(win->Bar, "Zoom", TW_TYPE_FLOAT, &win->Zoom, " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' "); // Add 'win->Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation TwAddVarRW(win->Bar, "ObjRotation", TW_TYPE_QUAT4F, &win->Rotation, " label='Object rotation' open help='Change the object orientation.' "); // Add callback to toggle auto-rotate mode (callback functions are defined above). TwAddVarCB(win->Bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, win, " label='Auto-rotate' key=space help='Toggle auto-rotate mode.' "); // Add 'win->LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-]. TwAddVarRW(win->Bar, "Multiplier", TW_TYPE_FLOAT, &win->LightMultiplier, " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' "); // Add 'win->LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction TwAddVarRW(win->Bar, "LightDir", TW_TYPE_DIR3F, &win->LightDirection, " label='Light direction' open help='Change the light direction.' "); // Add 'win->MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored) // and is inserted into a group named 'Material'. TwAddVarRW(win->Bar, "Ambient", TW_TYPE_COLOR3F, &win->MatAmbient, " group='Material' "); // Add 'win->MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored) // and is inserted into group 'Material'. TwAddVarRW(win->Bar, "Diffuse", TW_TYPE_COLOR3F, &win->MatDiffuse, " group='Material' "); // Add the enum variable 'win->ObjectShape' to 'bar' // (before adding an enum variable, its enum type must be declared to AntTweakBar as follow) { // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} }; // Create a type for the enum shapeEV TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES); // add 'win->CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>]. TwAddVarRW(win->Bar, "Shape", shapeType, &win->ObjectShape, " keyIncr='<' keyDecr='>' help='Change object shape.' "); } }
int main(int argc, char** argv) { { ::SetPriorityClass(::GetCurrentProcess(),REALTIME_PRIORITY_CLASS); /*btDbvt::benchmark(); exit(0);*/ } // Initialize AntTweakBar // (note that AntTweakBar could also be intialize after GLUT, no matter) if(!TwInit(TW_OPENGL, NULL)) { // A fatal error occured fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError()); } // Initialize Glut glutInit(&argc, argv); glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); int mainHandle = glutCreateWindow("CD Test Framework"); /* HWND hWnd; hWnd = FindWindow("GLUT", "CD Test Framework"); RECT Rect; GetWindowRect(hWnd, &Rect); */ glutCreateMenu(NULL); glutSetWindow(mainHandle); glutDisplayFunc(RenderCallback); glutReshapeFunc(ReshapeCallback); glutIdleFunc(IdleCallback); glutKeyboardFunc(KeyboardCallback); glutSpecialFunc(ArrowKeyCallback); glutMouseFunc(MouseCallback); glutMotionFunc(MotionCallback); atexit(Terminate); // Called after glutMainLoop ends glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); TwGLUTModifiersFunc(glutGetModifiers); // Setup default render states glClearColor(0.3f, 0.4f, 0.5f, 1.0); glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); glEnable(GL_CULL_FACE); glDepthFunc(GL_LEQUAL); // Setup lighting glEnable(GL_LIGHTING); float AmbientColor[] = { 0.0f, 0.1f, 0.2f, 0.0f }; glLightfv(GL_LIGHT0, GL_AMBIENT, AmbientColor); float DiffuseColor[] = { 1.0f, 1.0f, 1.0f, 0.0f }; glLightfv(GL_LIGHT0, GL_DIFFUSE, DiffuseColor); float SpecularColor[] = { 0.0f, 0.0f, 0.0f, 0.0f }; glLightfv(GL_LIGHT0, GL_SPECULAR, SpecularColor); float Position[] = { -10.0f, 1000.0f, -4.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_POSITION, Position); glEnable(GL_LIGHT0); gFnt.init(); gFnt.setScreenResolution(WINDOW_WIDTH, WINDOW_HEIGHT); gFnt.setColor(1.0f, 1.0f, 1.0f, 1.0f); CreateTerrain(); // Create main tweak bar { gMainBar = TwNewBar("CollisionTests"); TwEnumVal testEV[MAX_NB_TESTS] = { // {TEST_SPHERE_MESH_QUERY, "Sphere-mesh query"}, // {TEST_OBB_MESH_QUERY, "OBB-mesh query"}, // {TEST_CAPSULE_MESH_QUERY, "Capsule-mesh query"}, // {TEST_COMPLETE_BOX_PRUNING, "OPCODE SAP 1024"}, {TEST_COMPLETE_BOX_PRUNING_8192, "OPCODE BOX PRUNING 8192"}, // {TEST_BULLET_SAP_1024, "Bullet SAP HASHPAIR 1024"}, // {TEST_BULLET_SAP_8192, "Bullet SAP HASHPAIR 8192"}, // {TEST_BULLET_SAP_SORTEDPAIRS_8192, "Bullet SAP SORTEDPAIR 8192"}, // {TEST_BULLET_MULTISAP_8192, "Bullet MultiSAP 8192"}, // {TEST_BIPARTITE_BOX_PRUNING, "Bipartite box pruning"}, {TEST_DBVT_8192, "Bullet DBVT 8192"}, {TEST_BULLET_CUDA_8192, "Bullet CUDA 8192"}, {TEST_BULLET_3DGRID_8192, "Bullet 3D Grid 8192"}, {TEST_OPCODE_ARRAY_SAP, "OPCODE ARRAY SAP"}, }; TwType testType = TwDefineEnum("CollisionTest", testEV, MAX_NB_TESTS); TwAddVarRW(gMainBar, "CollisionTests", testType, &gSelectedTest, ""); TwAddVarRW(gMainBar, "% of updates",TW_TYPE_INT32,&percentUpdate,"min=0 max=100"); TwAddVarRW(gMainBar, "Draw",TW_TYPE_BOOLCPP,&enableDraw,""); } // Create tests gTest = 0; // gCollisionTests[TEST_SPHERE_MESH_QUERY] = new SphereMeshQuery; // gCollisionTests[TEST_OBB_MESH_QUERY] = new OBBMeshQuery; // gCollisionTests[TEST_CAPSULE_MESH_QUERY] = new CapsuleMeshQuery; // gCollisionTests[TEST_COMPLETE_BOX_PRUNING] = new CompleteBoxPruningTest(NUM_SAP_BOXES); // gCollisionTests[TEST_COMPLETE_BOX_PRUNING_8192] = new CompleteBoxPruningTest(NUM_SAP_BOXES); gCollisionTests[TEST_COMPLETE_BOX_PRUNING_8192] = new CompleteBoxPruningTest(NUM_SAP_BOXES); // gCollisionTests[TEST_BULLET_SAP_1024] = new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,1); // gCollisionTests[TEST_BULLET_SAP_8192] = new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,1); // gCollisionTests[TEST_BULLET_SAP_SORTEDPAIRS_8192] = new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,3); // gCollisionTests[TEST_BULLET_MULTISAP_8192] = new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,6); // gCollisionTests[TEST_BIPARTITE_BOX_PRUNING] = new BipartiteBoxPruningTest; gCollisionTests[TEST_DBVT_8192] = new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,7); gCollisionTests[TEST_BULLET_CUDA_8192] = new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,8); gCollisionTests[TEST_BULLET_3DGRID_8192] = new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,9); gCollisionTests[TEST_OPCODE_ARRAY_SAP] = new OpcodeArraySAPTest(NUM_SAP_BOXES); for(int i=0;i<MAX_NB_TESTS;i++) gCollisionTests[i]->Init(); gCollisionTests[gTest]->Select(); // MotionCallback(0,0); // Run glutMainLoop(); return 0; }
int main ( int argc, char *argv[] ) { #pragma region [-- FreeGLUT --] glutInit (&argc, argv); glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH ); glutInitWindowSize( Width, Heigth ); main_window = glutCreateWindow ("Shaders"); #pragma endregion #pragma region [-- GLEW --] // Inicializacion de GLEW GLenum glew_err = glewInit (); if ( GLEW_OK != glew_err ){ cout << "No es posible inicializar GLEW\n"; return 1; } cout << "Usando GLEW Version: " << glewGetString ( GLEW_VERSION ) << "\n\n"; #pragma endregion initShaders(); initLights(); #pragma region [-- AntTweakBar --] TwBar *bar; // Pointer to the tweak bar TwBar *barLights; // Initialize AntTweakBar TwInit(TW_OPENGL, NULL); glutMouseFunc(mouseClick); // Set GLUT event callbacks // - Directly redirect GLUT mouse button events to AntTweakBar //glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); // - Directly redirect GLUT mouse motion events to AntTweakBar glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion) glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); // - Directly redirect GLUT key events to AntTweakBar glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT); // - Directly redirect GLUT special key events to AntTweakBar glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT); // - Send 'glutGetModifers' function pointer to AntTweakBar; // required because the GLUT key event functions do not report key modifiers states. TwGLUTModifiersFunc(glutGetModifiers); bar = TwNewBar("Objetos"); TwDefine(" Objetos size='225 350' color='25 255 0' "); // change default tweak bar size and color 96 216 224 // Define the required callback function to copy a std::string (see TwCopyStdStringToClientFunc documentation) TwCopyStdStringToClientFunc(CopyStdStringToClient); TwAddVarRW(bar, "Cargar figura", TW_TYPE_STDSTRING, &direccion_carga, " label='direccion' group=Cargar help='Define a title for the new tweak bar.' "); // Add a button to create a new bar using the title TwAddButton(bar, "NewBarCreate", Cargar, &direccion_carga, " label='--> Create' group=Cargar key=c help='Create a new tweak bar.' "); TwAddVarRW(bar, "ObjRotation1", TW_TYPE_QUAT4F, &g_Rotation, " label='Object rotation' opened=true help='Change the object orientation.' "); // Add 'g_Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [m] and [M]. TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, " min=0.01 max=2.5 step=0.01 keyIncr=m keyDecr=M help='Scale the object (1=original size).' "); // Add 'g_Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [m] and [M]. TwAddVarRW(bar, "Shinnes", TW_TYPE_FLOAT, &shinnes, " min=0.00 max=200 step=0.1 keyIncr=m keyDecr=M help='Scale the object (1=original size).' "); // Add 'Translate' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [xyz] and [xyz]. TwAddVarRW(bar, "TranslateX", TW_TYPE_FLOAT, &Translation[0], " min=-20.0 max=20 step=0.01 keyIncr=x keyDecr=X help='Scale the object (1=original size).' group='Translation' "); TwAddVarRW(bar, "TranslateY", TW_TYPE_FLOAT, &Translation[1], " min=-20.0 max=20 step=0.01 keyIncr=y keyDecr=Y help='Scale the object (1=original size).' group='Translation' "); TwAddVarRW(bar, "TranslateZ", TW_TYPE_FLOAT, &Translation[2], " min=-20.0 max=20 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' group='Translation' "); barLights = TwNewBar("Luces"); TwDefine(" Luces size='225 350' position='580 16' color='25 255 0' "); // change default tweak bar size and color 96 216 224 { // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values TwEnumVal lightType[3] = { {DIRECTIONALLIGHT, "Direccional"}, {SPOTLIGHT, "Reflector"}, {POINTLIGHT, "Puntual"} }; // Create a type for the enum lightType TwType shapeType = TwDefineEnum("lightType", lightType, 3); // add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>]. TwAddVarRW(barLights, "Shape", shapeType, &g_light->status, " keyIncr='<' keyDecr='>' help='Change object shape.' "); } // Add 'g_LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction TwAddVarRW(barLights, "LightDir", TW_TYPE_DIR3F, &g_light->spotDirection, " label='Light direction' opened=true help='Change the light direction.' "); // Add 'g_MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored) // and is inserted into a group named 'Material'. TwAddVarRW(barLights, "Ambient", TW_TYPE_COLOR3F, &g_light->ambient, " group='Material' "); // Add 'g_MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored) // and is inserted into group 'Material'. TwAddVarRW(barLights, "Diffuse", TW_TYPE_COLOR3F, &g_light->diffuse, " group='Material' "); // Add 'g_MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored) // and is inserted into group 'Material'. TwAddVarRW(barLights, "specular", TW_TYPE_COLOR3F, &g_light->specular, " group='Material' "); TwAddVarRW(barLights, "TranslateX", TW_TYPE_FLOAT, &g_light->position.x, " min=-20.0 max=20 step=0.01 keyIncr=x keyDecr=X help='Scale the object (1=original size).' group='Translation' "); TwAddVarRW(barLights, "Translatey", TW_TYPE_FLOAT, &g_light->position.y, " min=-20.0 max=20 step=0.01 keyIncr=y keyDecr=Y help='Scale the object (1=original size).' group='Translation' "); TwAddVarRW(barLights, "Translatez", TW_TYPE_FLOAT, &g_light->position.z, " min=-20.0 max=20 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' group='Translation' "); TwAddVarRW(barLights, "spotExponent", TW_TYPE_FLOAT, &g_light->spotExponent, " min=0.0 max=10 step=1.0 help='Scale the object (1=original size).' "); TwAddVarRW(barLights, "spotCutoff", TW_TYPE_FLOAT, &g_light->spotCutoff, " min=0.0 max=60 step=1.0 help='Scale the object (1=original size).' "); TwAddVarRW(barLights, "constantAttenuation", TW_TYPE_FLOAT, &g_light->constantAttenuation, " min=0.0 step=1.0 help='Scale the object (1=original size).' "); TwAddVarRW(barLights, "linearAttenuation", TW_TYPE_FLOAT, &g_light->linearAttenuation, " min=0.0 step=1.0 help='Scale the object (1=original size).' "); TwAddVarRW(barLights, "quadraticAttenuation", TW_TYPE_FLOAT, &g_light->quadraticAttenuation, " min=0.0 max=60 step=1.0 help='Scale the object (1=original size).' "); #pragma endregion #pragma region [-- Callbacks --] glutDisplayFunc(Display); glutReshapeFunc(Reshape); #pragma endregion glEnable(GL_DEPTH_TEST); glutMainLoop (); return 0; }
// Main int main(int argc, char *argv[]) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); glutInitWindowSize( 800, 600 ); glutCreateWindow( "Font rendering advanced tweaking" ); glutCreateMenu( NULL ); glutDisplayFunc( display ); glutReshapeFunc( reshape ); atexit( terminate ); TwInit( TW_OPENGL, NULL ); glutMouseFunc( (GLUTmousebuttonfun)TwEventMouseButtonGLUT ); glutMotionFunc( (GLUTmousemotionfun)TwEventMouseMotionGLUT ); glutPassiveMotionFunc( (GLUTmousemotionfun)TwEventMouseMotionGLUT ); glutKeyboardFunc( (GLUTkeyboardfun)TwEventKeyboardGLUT ); glutSpecialFunc( (GLUTspecialfun)TwEventSpecialGLUT ); TwGLUTModifiersFunc( glutGetModifiers ); // Create a new tweak bar bar = TwNewBar("TweakBar"); TwDefine("GLOBAL " "help = 'This example shows how to tune all font parameters.' "); TwDefine("TweakBar " "size = '280 400' " "position = '500 20' " "color = '127 127 127' " "alpha = 240 " "label = 'Parameters' " "resizable = True " "fontresizable = True " "iconifiable = True "); { TwEnumVal familyEV[NUM_FONTS] = { {VERA, "Vera"}, {VERA_MONO, "Vera Mono"}, {GEORGIA, "Georgia"}, {TIMES, "Times"}, {VERDANA, "Verdana"}, {TAHOMA, "Tahoma"}, {ARIAL, "Arial"} }; TwType family_type = TwDefineEnum("Family", familyEV, NUM_FONTS); TwAddVarCB(bar, "Family", family_type, set_family, get_family, NULL, "label = 'Family' " "group = 'Font' " "help = ' ' "); } TwAddVarCB(bar, "Size", TW_TYPE_FLOAT, set_size, get_size, NULL, "label = 'Size' " "group = 'Font' " "min = 6.0 " "max = 24.0 " "step = 0.05 " "help = ' ' "); TwAddVarCB(bar, "LCD filtering", TW_TYPE_BOOL32, set_lcd_filtering, get_lcd_filtering, NULL, "label = 'LCD filtering' " "group = 'Font' " "help = ' ' "); // Rendering TwAddVarCB(bar, "Kerning", TW_TYPE_BOOL32, set_kerning, get_kerning, NULL, "label = 'Kerning' " "group = 'Rendering' " "help = ' ' "); TwAddVarCB(bar, "Hinting", TW_TYPE_BOOL32, set_hinting, get_hinting, NULL, "label = 'Hinting' " "group = 'Rendering' " "help = ' ' "); // Color TwAddVarCB(bar, "Invert", TW_TYPE_BOOL32, set_invert, get_invert, NULL, "label = 'Invert' " "group = 'Color' " "help = ' ' "); // Glyph TwAddVarCB(bar, "Width", TW_TYPE_FLOAT, set_width, get_width, NULL, "label = 'Width' " "group = 'Glyph' " "min = 0.75 " "max = 1.25 " "step = 0.01 " "help = ' ' "); TwAddVarCB(bar, "Interval", TW_TYPE_FLOAT, set_interval, get_interval, NULL, "label = 'Spacing' " "group = 'Glyph' " "min = -0.2 " "max = 0.2 " "step = 0.01 " "help = ' ' " ); TwAddVarCB(bar, "Faux italic", TW_TYPE_FLOAT, set_faux_italic, get_faux_italic, NULL, "label = 'Faux italic' " "group = 'Glyph' " "min = -30.0 " "max = 30.0 " "step = 0.1 " "help = ' ' "); // Energy distribution TwAddVarCB(bar, "Primary", TW_TYPE_FLOAT, set_primary, get_primary, NULL, "label = 'Primary weight' " "group = 'Energy distribution' " "min = 0 " "max = 1 " "step = 0.01 " "help = ' ' " ); TwAddVarCB(bar, "Secondary", TW_TYPE_FLOAT, set_secondary, get_secondary, NULL, "label = 'Secondy weight' " "group = 'Energy distribution' " "min = 0 " "max = 1 " "step = 0.01 " "help = ' ' " ); TwAddVarCB(bar, "Tertiary", TW_TYPE_FLOAT, set_tertiary, get_tertiary, NULL, "label = 'Tertiary weight' " "group = 'Energy distribution' " "min = 0 " "max = 1 " "step = 0.01 " "help = ' ' " ); TwAddSeparator(bar, "", "group = 'Energy distribution' " ); TwAddVarCB(bar, "Gamma", TW_TYPE_FLOAT, set_gamma, get_gamma, NULL, "label = 'Gamma correction' " "group = 'Energy distribution' " "min = 0.50 " "max = 2.5 " "step = 0.01 " "help = ' ' "); TwAddSeparator(bar, "", ""); TwAddButton(bar, "Reset", (TwButtonCallback) reset, NULL, "help='Reset all parameters to default values.'"); TwAddSeparator(bar, "", ""); TwAddButton(bar, "Quit", (TwButtonCallback) quit, NULL, "help='Quit.'"); atlas_gray = texture_atlas_new( 512, 256, 1 ); atlas_rgb = texture_atlas_new( 512, 256, 3 ); buffer = vertex_buffer_new( "v3f:t2f:c4f:1g1f" ); reset(); // Create the shader program = shader_load( "shaders/agg.vert", "shaders/agg.frag" ); texture_location = glGetUniformLocation( program, "texture" ); pixel_location = glGetUniformLocation( program, "pixel" ); gamma_location = glGetUniformLocation( program, "gamma" ); primary_location = glGetUniformLocation( program, "primary" ); secondary_location = glGetUniformLocation( program, "secondary" ); tertiary_location = glGetUniformLocation( program, "tertiary" ); //glEnable(GL_FRAMEBUFFER_SRGB); glutTimerFunc( 1000.0/60.0, timer, 60 ); glutMainLoop(); return EXIT_SUCCESS; }
// Main int main(int argc, char *argv[]) { TwBar *bar; // Pointer to the tweak bar float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation float angle = 0.8f; // Initialize GLUT //OutputDebugStringA("Test\n"); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(800, 600); glutInitWindowPosition(100, 100); glutCreateWindow("SRTP Middle Check"); glutCreateMenu(NULL); glewInit(); initTextureList(); for (int i = 0; i < textpoint; i++){ glActiveTexture(GL_TEXTURE0 + i); glBindTexture(GL_TEXTURE_2D, textureObjects[i]); } glActiveTexture(GL_TEXTURE0); sprintf(path, "%sCook-Torrorence", root); programs[2] = setupShaders(path); // Set GLUT callbacks glutDisplayFunc(Display); glutReshapeFunc(Reshape); // Initialize AntTweakBar TwInit(TW_OPENGL, NULL); // Set GLUT event callbacks // - Directly redirect GLUT mouse button events to AntTweakBar glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); // - Directly redirect GLUT mouse motion events to AntTweakBar glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion) glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); // - Directly redirect GLUT key events to AntTweakBar glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT); // - Directly redirect GLUT special key events to AntTweakBar glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT); // - Send 'glutGetModifers' function pointer to AntTweakBar; // required because the GLUT key event functions do not report key modifiers states. TwGLUTModifiersFunc(glutGetModifiers); // Create some 3D objects (stored in display lists) glNewList(SHAPE_TEAPOT, GL_COMPILE); glutSolidTeapot(1.0); glEndList(); glNewList(SHAPE_TORUS, GL_COMPILE); //glutSolidTorus(0.3, 1.0, 16, 32); glutSolidSphere(0.75f, 20, 20); glEndList(); glNewList(SHAPE_DRAGON, GL_COMPILE); drawBunny("dragon"); glEndList(); glNewList(SHAPE_SKULL, GL_COMPILE); drawBunny("skull"); glEndList(); glNewList(SHAPE_GARGO, GL_COMPILE); drawBunny("Gargoyle_ABF"); glEndList(); glNewList(DRAW_EN, GL_COMPILE); drawEnv(30); glEndList(); // Create a tweak bar bar = TwNewBar("TweakBar"); TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar. TwDefine(" TweakBar size='250 540' color='96 216 224' "); // change default tweak bar size and color TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, " min=0.01 max=7.5 step=0.01 "); TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, " label='Object rotation' opened=true "); TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, " label='Auto-rotate' key=space "); TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &lightDirection, " label='Light direction' opened=true "); TwAddVarRW(bar, "LightDist", TW_TYPE_FLOAT, &lightDistance, " label='Light distance' "); TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &lightAmbient, ""); TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &lightDiffuse, ""); TwAddVarRW(bar, "Rf", TW_TYPE_COLOR3F, &rf, ""); TwAddVarRW(bar, "Roughness", TW_TYPE_FLOAT, &roughness, " label='Roughness' min=0.01 max=1.99 step=0.01 keyIncr='+' keyDecr='-' "); { TwEnumVal shaders[NUM_SHADERS] = { { SHADER_PHONG, "Phong" }, { SHADER_COOKTORRORENCE, "CookTorrorence" } }; TwType shaderType = TwDefineEnum("ShaderType", shaders, NUM_SHADERS); TwAddVarRW(bar, "Shader", shaderType, ¤tShader, ""); } // Add the enum variable 'g_CurrentShape' to 'bar' // (before adding an enum variable, its enum type must be declared to AntTweakBar as follow) { // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values TwEnumVal shapeEV[NUM_SHAPES] = { { SHAPE_TEAPOT, "Teapot" }, { SHAPE_TORUS, "Sphere" }, { SHAPE_DRAGON, "Dragon" }, { SHAPE_SKULL, "Skull" }, { SHAPE_GARGO, "Gargo" } }; // Create a type for the enum shapeEV TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES); // add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>]. TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, ""); } // Store time g_RotateTime = GetTimeMs(); // Init rotation SetQuaternionFromAxisAngle(axis, angle, g_Rotation); SetQuaternionFromAxisAngle(axis, angle, g_RotateStart); atexit(Terminate); // Called after glutMainLoop ends // Call the GLUT main loop glutMainLoop(); return 0; }
int main( int argc, char ** argv ) { // Размеры окна по-умолчанию size_t const default_width = 800; size_t const default_height = 800; glutInit (&argc, argv); glutInitWindowSize (default_width, default_height); // Указание формата буфера экрана: // - GLUT_DOUBLE - двойная буферизация // - GLUT_RGB - 3-ёх компонентный цвет // - GLUT_DEPTH - будет использоваться буфер глубины glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); // Создаем контекст версии 3.3 glutInitContextVersion (3, 3); // Контекст будет поддерживать отладку и "устаревшую" функциональность, которой, например, может пользоваться библиотека AntTweakBar glutInitContextFlags (GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG); // Указание либо на core либо на compatibility профил glutInitContextProfile (GLUT_COMPATIBILITY_PROFILE ); int window_handle = glutCreateWindow("OpenGL basic sample"); // Инициализация указателей на функции OpenGL if (glewInit() != GLEW_OK) { cerr << "GLEW init failed" << endl; return 1; } // Проверка созданности контекста той версии, какой мы запрашивали if (!GLEW_VERSION_3_3) { cerr << "OpenGL 3.3 not supported" << endl; return 1; } #ifdef USE_CORE_OPENGL glutDestroyWindow(window_handle); glutInitContextProfile(GLUT_CORE_PROFILE); window_handle = glutCreateWindow("OpenGL basic sample"); #endif // Трассировка ошибок по callback'у glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); glDebugMessageCallbackARB(gl_debug_proc, NULL); // выключить все трассировки glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE , GL_DONT_CARE, 0, NULL, false); // включить сообщения только об ошибках glDebugMessageControlARB(GL_DONT_CARE, GL_DEBUG_TYPE_ERROR_ARB, GL_DONT_CARE, 0, NULL, true ); // подписываемся на оконные события glutReshapeFunc(reshape_func); glutDisplayFunc(display_func); glutIdleFunc (idle_func ); glutCloseFunc (close_func ); glutKeyboardFunc(keyboard_func); // подписываемся на события для AntTweakBar'а glutMouseFunc ((GLUTmousebuttonfun)TwEventMouseButtonGLUT); glutMotionFunc ((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutSpecialFunc ((GLUTspecialfun )TwEventSpecialGLUT ); TwGLUTModifiersFunc (glutGetModifiers); try { g_triangle.reset(new triangle_demo_t()); // Вход в главный цикл приложения glutMainLoop(); } catch( std::exception const & except ) { std::cout << except.what() << endl; return 1; } return 0; }
int main(int argc, char *argv[]) { // Initialize GLUT glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(640, 480); glutCreateWindow("AntTweakBar string example"); glutCreateMenu(NULL); // Set GLUT callbacks glutDisplayFunc(OnDisplay); glutReshapeFunc(OnReshape); atexit(OnTerminate); // Called after glutMainLoop ends // Initialize AntTweakBar TwInit(TW_OPENGL, NULL); // Set GLUT event callbacks // - Directly redirect GLUT mouse button events to AntTweakBar glutMouseFunc(OnMouseButton); // - Directly redirect GLUT mouse motion events to AntTweakBar glutMotionFunc(OnMouseMotion); // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion) glutPassiveMotionFunc(OnMouseMotion); // - Directly redirect GLUT key events to AntTweakBar glutKeyboardFunc(OnKeyboard); // - Directly redirect GLUT special key events to AntTweakBar glutSpecialFunc(OnSpecial); // - Send 'glutGetModifers' function pointer to AntTweakBar; // required because the GLUT key event functions do not report key modifiers states. TwGLUTModifiersFunc(glutGetModifiers); // Create a tweak bar TwBar *bar = TwNewBar("Main"); TwDefine(" Main label='~ String variable examples ~' fontSize=3 position='180 16' size='270 440' valuesWidth=100 "); // // 1) C++ std::string variable example // TwAddButton(bar, "Info1.1", NULL, NULL, " label='1) This example uses' "); TwAddButton(bar, "Info1.2", NULL, NULL, " label='std::string variables' "); // Define the required callback function to copy a std::string (see TwCopyStdStringToClientFunc documentation) TwCopyStdStringToClientFunc(CopyStdStringToClient); // Adding a std::string variable std::string newBarTitle = "a title"; TwAddVarRW(bar, "NewBarTitle", TW_TYPE_STDSTRING, &newBarTitle, " label='Bar title' group=StdString help='Define a title for the new tweak bar.' "); // Add a button to create a new bar using the title TwAddButton(bar, "NewBarCreate", CreateBarCB, &newBarTitle, " label='--> Create' group=StdString key=c help='Create a new tweak bar.' "); // Set the group label & separator TwDefine(" Main/StdString label='Create a new tweak bar' help='This example demonstates different use of std::string variables.' "); TwAddSeparator(bar, "Sep1", ""); TwAddButton(bar, "Blank1", NULL, NULL, " label=' ' "); // // 2) C-Dynamic string variable example // TwAddButton(bar, "Info2.1", NULL, NULL, "label='2) This example uses' "); TwAddButton(bar, "Info2.2", NULL, NULL, "label='C-Dynamic string variables' "); // Define the required callback function to copy a CDString (see TwCopyCDStringToClientFunc documentation) TwCopyCDStringToClientFunc(CopyCDStringToClient); // Add a CDString variable char *someText = NULL; TwAddVarRW(bar, "Input", TW_TYPE_CDSTRING, &someText, " label='Text input' group=CDString help=`The text to be copied to 'Text output'.` "); TwAddVarRO(bar, "Output", TW_TYPE_CDSTRING, &someText, " label='Text output' group=CDString help=`Carbon copy of the text entered in 'Text input'.` "); // Add a line of text (we will use the label of a inactive button) #define TEXTLINE "a line of text" TwAddButton(bar, "Echo", NULL, NULL, " label=`" TEXTLINE "` group=CDString help='Echo of the text entered in the next field' "); // Add a CDString variable accessed through callbacks char *textLine = (char *)malloc(sizeof(TEXTLINE)+1); strncpy(textLine, TEXTLINE, sizeof(TEXTLINE)); TwAddVarCB(bar, "TextLine", TW_TYPE_CDSTRING, SetTextLineCB, GetTextLineCB, &textLine, " label='Change text above' group=CDString help='The text to be echoed.' "); // Set the group label & separator TwDefine(" Main/CDString label='Echo some text' help='This example demonstates different use of C-Dynamic string variables.' "); TwAddSeparator(bar, "Sep2", ""); TwAddButton(bar, "Blank2", NULL, NULL, " label=' ' "); // // 3) C-Static string variable example // TwAddButton(bar, "Info3.1", NULL, NULL, "label='3) This example uses' "); TwAddButton(bar, "Info3.2", NULL, NULL, "label='C strings of fixed size' "); // Add a CSString char tenStr[] = "0123456789"; // 10 characters + null_termination_char -> size = 11 TwAddVarRW(bar, "Ten", TW_TYPE_CSSTRING(sizeof(tenStr)), tenStr, " label='10 chars max' group=CSString help='A string with a length of 10 characters max.' "); // Add a CSString accessed through callbacks. The callbacks will convert the string characters to upper or lower case int capCase = 1; // O: lower-case, 1: upper-case TwAddVarCB(bar, "Capitalize", TW_TYPE_CSSTRING(sizeof(g_CapStr)), SetCapStrCB, GetCapStrCB, &capCase, " group=CSString help='A string of fixed size to be converted to upper or lower case.' "); // Add a bool variable TwAddVarRW(bar, "Case", TW_TYPE_BOOL32, &capCase, " false=lower true=UPPER group=CSString key=Space help=`Changes the characters case of the 'Capitalize' string.` "); // Set the group label & separator TwDefine(" Main/CSString label='Character capitalization' help='This example demonstates different use of C-Static sized variables.' "); TwAddSeparator(bar, "Sep3", ""); // Call the GLUT main loop glutMainLoop(); return 0; }