int main(int argc, char **argv) { glutInit(&argc, argv); numdials = glutDeviceGet(GLUT_NUM_DIALS); if(numdials <= 0) { fprintf(stderr, "dials: No dials available\n"); exit(1); } numbuttons = glutDeviceGet(GLUT_NUM_BUTTON_BOX_BUTTONS); dials = (int*) calloc(numdials, sizeof(int)); buttons = (int*) calloc(numbuttons, sizeof(int)); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(300, ((numdials+1)/2) * 100 + 100); dw = glutCreateWindow("GLUT dials"); glClearColor(0.5, 0.5, 0.5, 1.0); glLineWidth(3.0); glutDialsFunc(dodial); glutButtonBoxFunc(dobutton); glutDisplayFunc(displayDials); glutReshapeFunc(reshape); glutInitWindowSize(240, 240); bw = glutCreateWindow("GLUT button box"); glClearColor(0.5, 0.5, 0.5, 1.0); glutDisplayFunc(displayButtons); glutReshapeFunc(reshape); glutDialsFunc(dodial); glutButtonBoxFunc(dobutton); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
int main(int argc, char **argv) { glutInit(&argc, argv); mouseButtons = glutDeviceGet(GLUT_NUM_MOUSE_BUTTONS); if (mouseButtons < 0) { printf("FAIL: negative mouse buttons? mouseButtons=%d\n", mouseButtons); exit(1); } if (mouseButtons > 3) { printf("More than 3 mouse buttons (ok). mouseButtons=%d\n", mouseButtons); mouseButtons = 3; /* Testing only of 3 mouse buttons. */ } glutCreateWindow("test"); glutDisplayFunc(display); glutTimerFunc(1000, time0, 0); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
/* Initialises and creates the opengl window */ bool initGLWindow(void) { if(Settings::stereoMode==STEREOMODE) { glutInitDisplayMode(GLUT_DOUBLE|GLUT_ACCUM|GLUT_RGB|GLUT_DEPTH|GLUT_STEREO); } else { glutInitDisplayMode(GLUT_DOUBLE|GLUT_ACCUM|GLUT_RGB|GLUT_DEPTH); } glutInitWindowSize(Settings::pixelWidth, Settings::pixelHeight); mainWindow = glutCreateWindow(WINTITLE); glutDisplayFunc(&display); glutReshapeFunc(&reshape); glutIdleFunc(&motionUpdate); // Keyboard controlls glutKeyboardFunc(&Controller::handleKeyboard); glutSpecialFunc(&Controller::handleSpecialKeys); // Mouse controlls glutMouseFunc(&Controller::processMouseButton); glutMotionFunc(&Controller::processMouseActiveMotion); glutPassiveMotionFunc(&Controller::processMousePassiveMotion); // Tablet controls glutTabletMotionFunc(&Controller::processTabletMotion); glutTabletButtonFunc(&Controller::processTabletButton); Controller::noTabletButtons = glutDeviceGet(GLUT_NUM_TABLET_BUTTONS); // Pop-up menu createMenu(); // Set the cursor glutSetCursor(GLUT_CURSOR_NONE); // Enable anti-aliasing glEnable(GL_LINE_SMOOTH); if(Settings::fullScreen) glutFullScreen(); return true; }
void fgPlatformProcessSingleEvent ( void ) { SFG_Window* window; XEvent event; /* This code was repeated constantly, so here it goes into a definition: */ #define GETWINDOW(a) \ window = fgWindowByHandle( event.a.window ); \ if( window == NULL ) \ break; #define GETMOUSE(a) \ window->State.MouseX = event.a.x; \ window->State.MouseY = event.a.y; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" ); while( XPending( fgDisplay.pDisplay.Display ) ) { XNextEvent( fgDisplay.pDisplay.Display, &event ); #if _DEBUG fghPrintEvent( &event ); #endif switch( event.type ) { case ClientMessage: if (fgStructure.CurrentWindow) if(fgIsSpaceballXEvent(&event)) { fgSpaceballHandleXEvent(&event); break; } /* Destroy the window when the WM_DELETE_WINDOW message arrives */ if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.pDisplay.DeleteWindow ) { GETWINDOW( xclient ); fgDestroyWindow ( window ); if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT ) { fgDeinitialize( ); exit( 0 ); } else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS ) fgState.ExecState = GLUT_EXEC_STATE_STOP; return; } break; /* * CreateNotify causes a configure-event so that sub-windows are * handled compatibly with GLUT. Otherwise, your sub-windows * (in freeglut only) will not get an initial reshape event, * which can break things. * * GLUT presumably does this because it generally tries to treat * sub-windows the same as windows. */ case CreateNotify: case ConfigureNotify: { int width, height, x, y; if( event.type == CreateNotify ) { GETWINDOW( xcreatewindow ); width = event.xcreatewindow.width; height = event.xcreatewindow.height; x = event.xcreatewindow.x; y = event.xcreatewindow.y; } else { GETWINDOW( xconfigure ); width = event.xconfigure.width; height = event.xconfigure.height; x = event.xconfigure.x; y = event.xconfigure.y; } /* Update state and call callback, if there was a change */ fghOnPositionNotify(window, x, y, GL_FALSE); /* Update state and call callback, if there was a change */ fghOnReshapeNotify(window, width, height, GL_FALSE); } break; case DestroyNotify: /* * This is sent to confirm the XDestroyWindow call. * * XXX WHY is this commented out? Should we re-enable it? */ /* fgAddToWindowDestroyList ( window ); */ break; case Expose: /* * We are too dumb to process partial exposes... * * XXX Well, we could do it. However, it seems to only * XXX be potentially useful for single-buffered (since * XXX double-buffered does not respect viewport when we * XXX do a buffer-swap). * */ if( event.xexpose.count == 0 ) { GETWINDOW( xexpose ); window->State.WorkMask |= GLUT_DISPLAY_WORK; } break; case MapNotify: break; case UnmapNotify: /* We get this when iconifying a window. */ GETWINDOW( xunmap ); INVOKE_WCB( *window, WindowStatus, ( GLUT_HIDDEN ) ); window->State.Visible = GL_FALSE; break; case MappingNotify: /* * Have the client's keyboard knowledge updated (xlib.ps, * page 206, says that's a good thing to do) */ XRefreshKeyboardMapping( (XMappingEvent *) &event ); break; case VisibilityNotify: { /* * Sending this event, the X server can notify us that the window * has just acquired one of the three possible visibility states: * VisibilityUnobscured, VisibilityPartiallyObscured or * VisibilityFullyObscured. Note that we DO NOT receive a * VisibilityNotify event when iconifying a window, we only get an * UnmapNotify then. */ GETWINDOW( xvisibility ); switch( event.xvisibility.state ) { case VisibilityUnobscured: INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) ); window->State.Visible = GL_TRUE; break; case VisibilityPartiallyObscured: INVOKE_WCB( *window, WindowStatus, ( GLUT_PARTIALLY_RETAINED ) ); window->State.Visible = GL_TRUE; break; case VisibilityFullyObscured: INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) ); window->State.Visible = GL_FALSE; break; default: fgWarning( "Unknown X visibility state: %d", event.xvisibility.state ); break; } } break; case EnterNotify: case LeaveNotify: GETWINDOW( xcrossing ); GETMOUSE( xcrossing ); if( ( event.type == LeaveNotify ) && window->IsMenu && window->ActiveMenu && window->ActiveMenu->IsActive ) fgUpdateMenuHighlight( window->ActiveMenu ); INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ? GLUT_ENTERED : GLUT_LEFT ) ); break; case MotionNotify: { /* if GLUT_SKIP_STALE_MOTION_EVENTS is true, then discard all but * the last motion event from the queue */ if(fgState.SkipStaleMotion) { while(XCheckIfEvent(fgDisplay.pDisplay.Display, &event, match_motion, 0)); } GETWINDOW( xmotion ); GETMOUSE( xmotion ); if( window->ActiveMenu ) { if( window == window->ActiveMenu->ParentWindow ) { window->ActiveMenu->Window->State.MouseX = event.xmotion.x_root - window->ActiveMenu->X; window->ActiveMenu->Window->State.MouseY = event.xmotion.y_root - window->ActiveMenu->Y; } fgUpdateMenuHighlight( window->ActiveMenu ); break; } /* * XXX For more than 5 buttons, just check {event.xmotion.state}, * XXX rather than a host of bit-masks? Or maybe we need to * XXX track ButtonPress/ButtonRelease events in our own * XXX bit-mask? */ fgState.Modifiers = fgPlatformGetModifiers( event.xmotion.state ); if ( event.xmotion.state & ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) ) { INVOKE_WCB( *window, Motion, ( event.xmotion.x, event.xmotion.y ) ); } else { INVOKE_WCB( *window, Passive, ( event.xmotion.x, event.xmotion.y ) ); } fgState.Modifiers = INVALID_MODIFIERS; } break; case ButtonRelease: case ButtonPress: { GLboolean pressed = GL_TRUE; int button; if( event.type == ButtonRelease ) pressed = GL_FALSE ; /* * A mouse button has been pressed or released. Traditionally, * break if the window was found within the freeglut structures. */ GETWINDOW( xbutton ); GETMOUSE( xbutton ); /* * An X button (at least in XFree86) is numbered from 1. * A GLUT button is numbered from 0. * Old GLUT passed through buttons other than just the first * three, though it only gave symbolic names and official * support to the first three. */ button = event.xbutton.button - 1; /* * Do not execute the application's mouse callback if a menu * is hooked to this button. In that case an appropriate * private call should be generated. */ if( fgCheckActiveMenu( window, button, pressed, event.xbutton.x, event.xbutton.y ) ) break; /* * Check if there is a mouse or mouse wheel callback hooked to the * window */ if( ! FETCH_WCB( *window, Mouse ) && ! FETCH_WCB( *window, MouseWheel ) ) break; fgState.Modifiers = fgPlatformGetModifiers( event.xbutton.state ); /* Finally execute the mouse or mouse wheel callback */ if( ( button < glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS ) ) || ( ! FETCH_WCB( *window, MouseWheel ) ) ) INVOKE_WCB( *window, Mouse, ( button, pressed ? GLUT_DOWN : GLUT_UP, event.xbutton.x, event.xbutton.y ) ); else { /* * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1 * " 6 and 7 " " one; ... * * XXX This *should* be behind some variables/macros, * XXX since the order and numbering isn't certain * XXX See XFree86 configuration docs (even back in the * XXX 3.x days, and especially with 4.x). * * XXX Note that {button} has already been decremented * XXX in mapping from X button numbering to GLUT. * * XXX Should add support for partial wheel turns as Windows does -- 5/27/11 */ int wheel_number = (button - glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS )) / 2; int direction = -1; if( button % 2 ) direction = 1; if( pressed ) INVOKE_WCB( *window, MouseWheel, ( wheel_number, direction, event.xbutton.x, event.xbutton.y ) ); } fgState.Modifiers = INVALID_MODIFIERS; } break; case KeyRelease: case KeyPress: { FGCBKeyboard keyboard_cb; FGCBSpecial special_cb; GETWINDOW( xkey ); GETMOUSE( xkey ); /* Detect auto repeated keys, if configured globally or per-window */ if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) { if (event.type==KeyRelease) { /* * Look at X11 keystate to detect repeat mode. * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs. */ char keys[32]; XQueryKeymap( fgDisplay.pDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */ if ( event.xkey.keycode<256 ) /* XQueryKeymap is limited to 256 keycodes */ { if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) ) window->State.pWState.KeyRepeating = GL_TRUE; else window->State.pWState.KeyRepeating = GL_FALSE; } } } else window->State.pWState.KeyRepeating = GL_FALSE; /* Cease processing this event if it is auto repeated */ if (window->State.pWState.KeyRepeating) { if (event.type == KeyPress) window->State.pWState.KeyRepeating = GL_FALSE; break; } if( event.type == KeyPress ) { keyboard_cb = (FGCBKeyboard)( FETCH_WCB( *window, Keyboard )); special_cb = (FGCBSpecial) ( FETCH_WCB( *window, Special )); } else { keyboard_cb = (FGCBKeyboard)( FETCH_WCB( *window, KeyboardUp )); special_cb = (FGCBSpecial) ( FETCH_WCB( *window, SpecialUp )); } /* Is there a keyboard/special callback hooked for this window? */ if( keyboard_cb || special_cb ) { XComposeStatus composeStatus; char asciiCode[ 32 ]; KeySym keySym; int len; /* Check for the ASCII/KeySym codes associated with the event: */ len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode), &keySym, &composeStatus ); /* GLUT API tells us to have two separate callbacks... */ if( len > 0 ) { /* ...one for the ASCII translateable keypresses... */ if( keyboard_cb ) { fgSetWindow( window ); fgState.Modifiers = fgPlatformGetModifiers( event.xkey.state ); keyboard_cb( asciiCode[ 0 ], event.xkey.x, event.xkey.y ); fgState.Modifiers = INVALID_MODIFIERS; } } else { int special = -1; /* * ...and one for all the others, which need to be * translated to GLUT_KEY_Xs... */ switch( keySym ) { case XK_F1: special = GLUT_KEY_F1; break; case XK_F2: special = GLUT_KEY_F2; break; case XK_F3: special = GLUT_KEY_F3; break; case XK_F4: special = GLUT_KEY_F4; break; case XK_F5: special = GLUT_KEY_F5; break; case XK_F6: special = GLUT_KEY_F6; break; case XK_F7: special = GLUT_KEY_F7; break; case XK_F8: special = GLUT_KEY_F8; break; case XK_F9: special = GLUT_KEY_F9; break; case XK_F10: special = GLUT_KEY_F10; break; case XK_F11: special = GLUT_KEY_F11; break; case XK_F12: special = GLUT_KEY_F12; break; case XK_KP_Left: case XK_Left: special = GLUT_KEY_LEFT; break; case XK_KP_Right: case XK_Right: special = GLUT_KEY_RIGHT; break; case XK_KP_Up: case XK_Up: special = GLUT_KEY_UP; break; case XK_KP_Down: case XK_Down: special = GLUT_KEY_DOWN; break; case XK_KP_Prior: case XK_Prior: special = GLUT_KEY_PAGE_UP; break; case XK_KP_Next: case XK_Next: special = GLUT_KEY_PAGE_DOWN; break; case XK_KP_Home: case XK_Home: special = GLUT_KEY_HOME; break; case XK_KP_End: case XK_End: special = GLUT_KEY_END; break; case XK_KP_Insert: case XK_Insert: special = GLUT_KEY_INSERT; break; case XK_Num_Lock : special = GLUT_KEY_NUM_LOCK; break; case XK_KP_Begin : special = GLUT_KEY_BEGIN; break; case XK_KP_Delete: special = GLUT_KEY_DELETE; break; case XK_Shift_L: special = GLUT_KEY_SHIFT_L; break; case XK_Shift_R: special = GLUT_KEY_SHIFT_R; break; case XK_Control_L: special = GLUT_KEY_CTRL_L; break; case XK_Control_R: special = GLUT_KEY_CTRL_R; break; case XK_Alt_L: special = GLUT_KEY_ALT_L; break; case XK_Alt_R: special = GLUT_KEY_ALT_R; break; } /* * Execute the callback (if one has been specified), * given that the special code seems to be valid... */ if( special_cb && (special != -1) ) { fgSetWindow( window ); fgState.Modifiers = fgPlatformGetModifiers( event.xkey.state ); special_cb( special, event.xkey.x, event.xkey.y ); fgState.Modifiers = INVALID_MODIFIERS; } } } }
/* * Class: gruenewa_opengl_GLUT__ * Method: glutDeviceGet * Signature: (I)I */ JNIEXPORT jint JNICALL Java_gruenewa_opengl_GLUT_00024_glutDeviceGet (JNIEnv * jenv, jobject jobj, jint arg1) { return glutDeviceGet(arg1); }
int /* O - Exit status */ main(int argc, /* I - Number of command-line arguments */ char *argv[]) /* I - Command-line arguments */ { glutInit(&argc, argv); #ifdef BOOK_COVER glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH); #else glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); #endif /* BOOK_COVER */ glutInitWindowSize(792, 573); glutCreateWindow("Terrain Using Vertex Culling Extension"); glutDisplayFunc(Redraw); if (glutDeviceGet(GLUT_HAS_JOYSTICK)) glutJoystickFunc(Joystick, 200); glutKeyboardFunc(Keyboard); glutMotionFunc(Motion); glutMouseFunc(Mouse); glutReshapeFunc(Resize); glutSpecialFunc(Special); BuildF16(); LandTexture = TextureLoad("land.bmp", GL_FALSE, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT); SkyTexture = TextureLoad("sky.bmp", GL_FALSE, GL_LINEAR, GL_LINEAR, GL_CLAMP); LoadTerrain(36, -112); puts("QUICK HELP:"); puts(""); puts("ESC - Quit"); puts("',' - Slow down, '<' - Slowest"); puts("'.' - Speed up, '>' - Fastest"); puts("'3' - Toggle terrain"); puts("'a' - Toggle aircraft"); puts("'f' - Toggle fog"); puts("'l' - Toggle lighting"); puts("'s' - Toggle sky/clouds"); puts("'t' - Toggle texturing"); puts("'w' - Toggle water"); puts("'W' - Toggle wireframe"); printf("GL_EXTENSIONS = %s\n", glGetString(GL_EXTENSIONS)); if (strstr(glGetString(GL_EXTENSIONS), "EXT_cull_vertex") != NULL) { UseCullVertex = 1; glCullParameterfvEXT = wglGetProcAddress("glCullParameterfvEXT"); } else if (strstr(glGetString(GL_EXTENSIONS), "SGI_cull_vertex") != NULL) { UseCullVertex = 1; glCullParameterfvEXT = wglGetProcAddress("glCullParameterfvSGI"); } else UseCullVertex = 0; glutMainLoop(); return (0); }