static void setGraphics(int w, int h) { glfwSetWindowSize(w, h); GLFWvidmode desktopMode; glfwGetDesktopMode( &desktopMode ); glfwSetWindowPos( (desktopMode.Width-w)/2,(desktopMode.Height-h)/2 ); }
int main( void ) { GLFWvidmode dtmode, modes[ MAX_NUM_MODES ]; int modecount, i; // Initialize GLFW if( !glfwInit() ) { return 0; } // Show desktop video mode glfwGetDesktopMode( &dtmode ); printf( "Desktop mode: %d x %d x %d\n\n", dtmode.Width, dtmode.Height, dtmode.RedBits + dtmode.GreenBits + dtmode.BlueBits ); // List available video modes modecount = glfwGetVideoModes( modes, MAX_NUM_MODES ); printf( "Available modes:\n" ); for( i = 0; i < modecount; i ++ ) { printf( "%3d: %d x %d x %d\n", i, modes[i].Width, modes[i].Height, modes[i].RedBits + modes[i].GreenBits + modes[i].BlueBits ); } // Terminate GLFW glfwTerminate(); return 0; }
// Get The Display Height In Pixels int System::GetDisplayHeight(){ // Set Variables GLFWvidmode return_struct; // Get Screen Size glfwGetDesktopMode (&return_struct); // Return Window Height return (int) return_struct.Height; }
// Get The Display Width In Pixels int System::GetDisplayWidth(){ // Set Variables GLFWvidmode return_struct; // Get Screen Size glfwGetDesktopMode (&return_struct); // Return Window Width return (int) return_struct.Width; }
// Get Total Number Of Pixels In Display int System::GetDisplayPixels(){ // Set Variables GLFWvidmode return_struct; // Get Screen Size glfwGetDesktopMode (&return_struct); // Return Window Pixels return ((int) return_struct.Width) * ((int) return_struct.Height); }
int main(void) { GLFWvidmode mode; if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(1); } glfwGetDesktopMode(&mode); if (!glfwOpenWindow(mode.Width, mode.Height, 0, 0, 0, 0, 0, 0, GLFW_FULLSCREEN)) { glfwTerminate(); fprintf(stderr, "Failed to open GLFW window\n"); exit(1); } glfwSetWindowTitle("Fullscreen Input Detector"); glfwSetKeyCallback(key_callback); glfwSetCharCallback(char_callback); glfwSetMousePosCallback(mouse_position_callback); glfwSetMouseButtonCallback(mouse_button_callback); glfwSetMouseWheelCallback(mouse_wheel_callback); glfwSetWindowSizeCallback(window_size_callback); glfwSwapInterval(1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glfwSetTime(0.0); running = GL_TRUE; while (running) { glClearColor((GLclampf) fabs(cos(glfwGetTime() * 4.f)), 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(); if (!glfwGetWindowParam(GLFW_OPENED)) running = GL_FALSE; if (glfwGetTime() > 10.0) running = GL_FALSE; } glfwTerminate(); exit(0); }
//##############GAME CLIENT################# GameClient::GameClient():Client(),readerThread(*this, &GameClient::readerThreadProc,0){ gameClientPtr = this; glfwInit(); Thread<Server,int>::sleep(1); GLFWvidmode dvm; glfwGetDesktopMode(&dvm); glfwSetWindowTitle("FPS!"); glfwOpenWindow(400, 400, dvm.RedBits, dvm.GreenBits, dvm.BlueBits, 8, 24, 0, GLFW_WINDOW); glEnable(GL_DEPTH_TEST); for (int i=0; i<256; keysState[i++]=0); }
static const VideoMode GetDesktopMode() { GLFWvidmode mode; glfwGetDesktopMode(&mode); VideoMode vm; vm.width = mode.Width; vm.height = mode.Height; vm.red_bits = mode.RedBits; vm.green_bits = mode.GreenBits; vm.blue_bits = mode.BlueBits; return vm; }
void BBMonkeyGame::Main( int argc,const char *argv[] ){ if( !glfwInit() ){ puts( "glfwInit failed" ); exit(-1); } GLFWvidmode desktopMode; glfwGetDesktopMode( &desktopMode ); int w=CFG_GLFW_WINDOW_WIDTH; if( !w ) w=desktopMode.Width; int h=CFG_GLFW_WINDOW_HEIGHT; if( !h ) h=desktopMode.Height; glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE,CFG_GLFW_WINDOW_RESIZABLE ? GL_FALSE : GL_TRUE ); if( !glfwOpenWindow( w,h, 0,0,0,0,CFG_OPENGL_DEPTH_BUFFER_ENABLED ? 32 : 0,0,CFG_GLFW_WINDOW_FULLSCREEN ? GLFW_FULLSCREEN : GLFW_WINDOW ) ){ puts( "glfwOpenWindow failed" ); exit(-1); } glfwSetWindowPos( (desktopMode.Width-w)/2,(desktopMode.Height-h)/2 ); glfwSetWindowTitle( _STRINGIZE(CFG_GLFW_WINDOW_TITLE) ); #if CFG_OPENGL_INIT_EXTENSIONS Init_GL_Exts(); #endif BBMonkeyGame *game=new BBMonkeyGame(); try{ bb_std_main( argc,argv ); }catch( ThrowableObject *ex ){ game->Die( ex ); return; } if( game->Delegate() ) game->Run(); glfwTerminate(); exit( 0 ); }
void keyPressListener( int key, int action ) { if( !running ) return; if( action == GLFW_PRESS ) { int width = appWidth, height = appHeight; switch (key) { case GLFW_KEY_ESC: running = false; break; case GLFW_KEY_SPACE: app->keyPress( key, true ); break; case GLFW_KEY_F1: app->release(); glfwCloseWindow(); // Toggle fullscreen mode fullScreen = !fullScreen; if( fullScreen ) { GLFWvidmode mode; glfwGetDesktopMode( &mode ); // Use desktop resolution width = mode.Width; height = mode.Height; } if( !setupWindow( width, height, fullScreen ) ) { glfwTerminate(); exit( -1 ); } app->init(sceneFile); app->resize( width, height ); t0 = glfwGetTime(); break; default: app->keyPress( key, true ); } } if( key >= 0 ) app->keyPress( key, action == GLFW_PRESS ); }
int main(int argc, char** argv) { // Frame counter and window settings variables int redBits = 8, greenBits = 8, blueBits = 8; int alphaBits = 8, depthBits = 24, stencilBits = 0; // Inicializar GLFW if (!glfwInit()) { std::cout << "Failed to initialise GLFW!" << endl; glfwTerminate(); return GLFW_INIT_ERROR; } // get the current Desktop screen resolution and colour depth GLFWvidmode desktop; glfwGetDesktopMode(&desktop); width = desktop.Width; height = desktop.Height; // open the window at the current Desktop resolution and colour depth if (!glfwOpenWindow( desktop.Width, desktop.Height, desktop.RedBits, desktop.GreenBits, desktop.BlueBits, 8, // alpha bits 32, // depth bits 0, // stencil bits GLFW_FULLSCREEN )) { std::cout << "Failed to open fullscreen window!" << std::endl; glfwTerminate(); return GLFW_WINDOW_ERROR; } //Inicializar, carregar e correr a simulação AppStart(); // Clean up GLFW and exit glfwTerminate(); delete cam; // Delete our pointer to the camera object return 0; }
int main(int argc, char **argv) { shmup_game *g; GLFWvidmode d_mode; if(!glfwInit()) { fprintf( stderr, "Failed to initialize GLFW\n" ); exit(EXIT_FAILURE); } glfwGetDesktopMode(&d_mode); //d_mode.Width/1.5, d_mode.Height/1.5 if(!glfwOpenWindow(800, 600, d_mode.RedBits, d_mode.GreenBits, d_mode.BlueBits, 8, 8, 0, GLFW_WINDOW)) { fprintf(stderr, "Failed to open GLFW window\n"); glfwTerminate(); exit(EXIT_FAILURE); } g = shmup_game_init(); glfwSetWindowTitle("ShmupEngine"); // glfwSetWindowSizeCallback(resize); glfwSwapInterval(1); glfwSetMousePos(g->window_width/2, g->window_height/2); glfwEnable(GLFW_MOUSE_CURSOR); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, g->window_width, 0, g->window_height, 100, -100); glMatrixMode(GL_MODELVIEW); g->network_type = CLIENT; for (int i=0; i<argc; ++i) { if (strcmp("-a", argv[i])) g->network_type = SERVER; } shmup_game_run(g); shmup_game_close(g); glfwTerminate(); exit(EXIT_SUCCESS); }
void RenderWindow::create(int desiredWidth, int desiredHeight, bool fullscreen, int samples) { // multisampling glfwOpenWindowHint(GLFW_FSAA_SAMPLES, samples); // set OpenGL version/profile glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, OPENGL_VERSION_MAJOR); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, OPENGL_VERSION_MINOR); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // debugging? #if _DEBUG glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif // open window/create OpenGL context GLFWvidmode videomode; glfwGetDesktopMode(&videomode); int win_width, win_height, win_mode; if (fullscreen) { win_width = videomode.Width; win_height = videomode.Height; win_mode = GLFW_FULLSCREEN; } else { win_width = std::min(desiredWidth, videomode.Width); win_height = std::min(desiredHeight, videomode.Height); win_mode = GLFW_WINDOW; } const int depth_bits = 32; const int stencil_bits = 32; if (!glfwOpenWindow(win_width, win_height, 0, 0, 0, 0, // r, g, b, a - color & alpha buffer bit depth depth_bits, // depth buffer bit depth stencil_bits, // stencil buffer bit depth win_mode // GLFW_WINDOW | GLFW_FULLSCREEN )) { destroy(); std::stringstream msg; msg << "Failed to open GLFW window for OpenGL " << OPENGL_VERSION_MAJOR << "." << OPENGL_VERSION_MINOR << std::endl; throw std::exception(msg.str().c_str()); } }
static void list_modes(void) { int count, i; GLFWvidmode desktop_mode; GLFWvidmode* modes = glfwGetVideoModes(&count); glfwGetDesktopMode(&desktop_mode); printf("Desktop mode: %s\n", format_mode(&desktop_mode)); printf("Available modes:\n"); for (i = 0; i < count; i++) { printf("%3u: %s", (unsigned int) i, format_mode(modes + i)); if (memcmp(&desktop_mode, modes + i, sizeof(GLFWvidmode)) == 0) printf(" (desktop mode)"); putchar('\n'); } }
void CEngine::_WindowInit(char *WindowTitle, E_ENGINE_INITIALISATION_FLAGS InitFlags) { glfwInit(); glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); GLFWvidmode DesktopMode; glfwGetDesktopMode(&DesktopMode); _Width = DesktopMode.Width; _Height = DesktopMode.Height; if(!glfwOpenWindow(_Width, _Height, DesktopMode.RedBits, DesktopMode.GreenBits, DesktopMode.BlueBits, 8, 8, 0, (InitFlags & EIF_FULLSCREEN)? GLFW_FULLSCREEN : GLFW_WINDOW)) { glfwTerminate(); } glfwSetWindowTitle(WindowTitle); glfwSetWindowSizeCallback( WindowResize ); glfwGetWindowSize( &_Width, &_Height); glfwSwapInterval(1); _Height = _Height > 0 ? _Height : 1; }
bool Root::initGLFW() { if(!glfwInit()) { LOG_ERROR("Could not init glfw!"); return false; } GLFWvidmode mode; glfwGetDesktopMode(&mode); desktopWidth = mode.Width; desktopHeight = mode.Height; if(fullscreen) { windowWidth = desktopWidth; windowHeight = desktopHeight; } #ifdef __APPLE__ glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // Use OpenGL Core v3.2 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); #endif if(!glfwOpenWindow(windowWidth, windowHeight, 0, 0, 0, 0, 32, 0, (fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW))) { return false; } glfwSetWindowTitle("Arya"); glfwEnable(GLFW_MOUSE_CURSOR); glfwSetKeyCallback(keyCallback); glfwSetMouseButtonCallback(mouseButtonCallback); glfwSetMousePosCallback(mousePosCallback); glfwSetMouseWheelCallback(mouseWheelCallback); return true; }
void Input::update() { m_mouse.z = glfwGetMouseWheel(); glfwSetMouseWheel(0); if (m_mouseVisible == false) { #ifdef __APPLE__ CGGetLastMouseDelta(&m_mouse.x, &m_mouse.y); GLFWvidmode mode; glfwGetDesktopMode(&mode); CGPoint p; p.x = m_mouseMiddleX; p.y = m_mouseMiddleY; CGWarpMouseCursorPosition(p); #else glfwGetMousePos(&m_mouse.x, &m_mouse.y); m_mouse.x -= m_mouseMiddleX; m_mouse.y -= m_mouseMiddleY; glfwSetMousePos(m_mouseMiddleX, m_mouseMiddleY); #endif } else { glfwGetMousePos(&m_mouse.x, &m_mouse.y); } m_mouse.b = 0; if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_1)) { m_mouse.b |= 1; } if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_2)) { m_mouse.b |= 2; } }
void GLFWCALL keyPressListener( int key, int action ) { if( !running ) return; if( action == GLFW_PRESS ) { int width = appWidth, height = appHeight; switch (key) { case GLFW_KEY_ESC: running = false; break; case GLFW_KEY_SPACE: app->keyPressEvent( key ); break; case GLFW_KEY_F1: app->release(); glfwCloseWindow(); // Toggle fullscreen mode fullScreen = !fullScreen; if( fullScreen ) { GLFWvidmode mode; glfwGetDesktopMode( &mode ); float aspect = mode.Width / (float)mode.Height; if( (int)(aspect * 100) == 133 || (int)(aspect * 100) == 125 ) // Standard { width = 1280; height = 1024; } else if( (int)(aspect * 100) == 160 ) // Widescreen { width = 1280; height = 800; } else // Unknown { // Use desktop resolution width = mode.Width; height = mode.Height; } } if( !setupWindow( width, height, fullScreen ) ) { glfwTerminate(); exit( -1 ); } app->init(); app->resize( width, height ); t0 = glfwGetTime(); break; default: app->keyPressEvent( key ); break; } } if( key >= 0 ) app->keyStateChange( key, action == GLFW_PRESS ); }
// Main function int main(int argc, char * argv[]) { /*{ PointerState test; test.UpdateButtonState(0) = true; test.UpdateButtonState(1) = true; test.UpdateButtonState(2) = true; PointerState test2(test); test2.UpdateButtonState(2) = false; std::cout << test.GetButtonState(2) << &std::endl; std::cout << test2.GetButtonState(2) << &std::endl; return 0; }*/ #if 0 { std::function<void()> Test = []() { std::cout << "Hi from anon func.\n"; }; //std::function<ConceptString(const std::vector<ConceptId> &)> Test = [](const std::vector<ConceptId> & Parameters){ return ConceptString({FindConcept("<"), GetParameterIfExists(Parameters, 0), FindConcept(">")}); }; // Call Test() //Test(); printf("size of func %ld\n", sizeof(Test)); return 0; } #endif // Set env vars std::string GoPath; // This has to exist even after putenv() call because putenv simply adds a pointer rather than copying the value std::string Path = "PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/go/bin"; { // Initialize the value of GoPath GoPath = "GOPATH="; // Get current working directory { auto cwd = getcwd(nullptr, 0); if (nullptr == cwd) { printf("Fatal Error: getcwd() failed."); exit(1); } printf("Current-working-dir is '%s' (should be the folder where README.md is).\n", cwd); GoPath = GoPath + cwd + "/GoLand"; GoPath += ":"; GoPath = GoPath + cwd + "/GoLanding"; Path = Path + ":" + cwd + "/GoLand/bin"; free(cwd); } putenv(const_cast<char *>("DYLD_INSERT_LIBRARIES=")); // HACK: Const cast putenv(const_cast<char *>("TERM=xterm")); // HACK: Const cast putenv(const_cast<char *>(GoPath.c_str())); // HACK: Const cast // HACK: Add go/bin to $PATH by hardcoding the whole PATH for OS X putenv(const_cast<char *>(Path.c_str())); // HACK: Const cast } glfwInit(); // Verify the GLFW library and header versions match { int Major, Minor, Revision; glfwGetVersion(&Major, &Minor, &Revision); bool Match = (GLFW_VERSION_MAJOR == Major && GLFW_VERSION_MINOR == Minor && GLFW_VERSION_REVISION == Revision); if (!Match) { std::cerr << "Error: GLFW library and header versions do not match." << std::endl; throw 0; } else { std::cout << "Using GLFW " << Major << "." << Minor << "." << Revision << "." << std::endl; } } // Open main window { GLFWvidmode DesktopMode; glfwGetDesktopMode(&DesktopMode); glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 32); const bool Fullscreen = static_cast<bool>(0); const Vector2n WindowDimensons(1536, 960); if (!Fullscreen) { glfwOpenWindow(WindowDimensons.X(), WindowDimensons.Y(), DesktopMode.RedBits, DesktopMode.GreenBits, DesktopMode.BlueBits, 0, 0, 0, GLFW_WINDOW); glfwSetWindowPos((DesktopMode.Width - WindowDimensons.X()) / 2, (DesktopMode.Height - WindowDimensons.Y()) / 2); // Center the window } else { glfwOpenWindow(DesktopMode.Width, DesktopMode.Height, DesktopMode.RedBits, DesktopMode.GreenBits, DesktopMode.BlueBits, 0, 0, 0, GLFW_FULLSCREEN); glfwEnable(GLFW_MOUSE_CURSOR); } { std::ostringstream x; x << "CPU Count: " << glfwGetNumberOfProcessors() << std::endl << "GL Renderer: " << glGetString(GL_VENDOR) << " " << glGetString(GL_RENDERER) << " " << glGetString(GL_VERSION) << std::endl << "GLFW_ACCELERATED: " << glfwGetWindowParam(GLFW_ACCELERATED) << std::endl << "GLFW_RED_BITS: " << glfwGetWindowParam(GLFW_RED_BITS) << std::endl << "GLFW_GREEN_BITS: " << glfwGetWindowParam(GLFW_GREEN_BITS) << std::endl << "GLFW_BLUE_BITS: " << glfwGetWindowParam(GLFW_BLUE_BITS) << std::endl << "GLFW_ALPHA_BITS: " << glfwGetWindowParam(GLFW_ALPHA_BITS) << std::endl << "GLFW_DEPTH_BITS: " << glfwGetWindowParam(GLFW_DEPTH_BITS) << std::endl << "GLFW_STENCIL_BITS: " << glfwGetWindowParam(GLFW_STENCIL_BITS) << std::endl << "GLFW_REFRESH_RATE: " << glfwGetWindowParam(GLFW_REFRESH_RATE) << std::endl << "GLFW_FSAA_SAMPLES: " << glfwGetWindowParam(GLFW_FSAA_SAMPLES) << std::endl; std::cout << x.str(); } { //glfwSetWindowTitle("Conception"); glfwSwapInterval(1); // Set Vsync glfwDisable(GLFW_AUTO_POLL_EVENTS); glfwEnable(GLFW_KEY_REPEAT); glfwDisable(GLFW_SYSTEM_KEYS); } } { InputManager InputManager; g_InputManager = &InputManager; ConceptionApp MainApp(InputManager); //LiveEditorApp MainApp(InputManager); //ConceptionTestApp MainApp(InputManager); //MultitouchTestApp MainApp(InputManager); //SentienceApp MainApp(InputManager); glfwSetWindowTitle(MainApp.GetTitle().c_str()); // Perform the layout of UI widgets MainApp.Layout(); // OpenGL settings InitializeOpenGL(); std::cout << std::endl; // Done loading // Main loop while (glfwGetWindowParam(GLFW_OPENED)) { auto CurrentTime = glfwGetTime(); static auto LastTime = CurrentTime; auto TimePassed = CurrentTime - LastTime; LastTime = CurrentTime; // DEBUG: Moved to top of loop to enable debug printing from input handling code glClear(GL_COLOR_BUFFER_BIT); // Clear frame // Process input { // Populate InputEventQueue if (MainApp.ShouldRedrawRegardless()) glfwPollEvents(); else { glfwWaitEvents(); //if (glfwGetTime() - LastTime >= 1) printf("Slept for %f secs\n", glfwGetTime() - LastTime); LastTime = glfwGetTime(); } //InputManager.ProcessTimePassed(TimePassed); MainApp.ProcessEventQueue(InputManager.ModifyInputEventQueue()); MainApp.ProcessTimePassed(TimePassed); } // Render { // DEBUG: Moved to top of loop to enable debug printing from input handling code ///glClear(GL_COLOR_BUFFER_BIT); // Clear frame MainApp.Render(); } // Display new frame glfwSwapBuffers(); //glFinish(); ///printf("%f ms frame\n", TimePassed * 1000); // Use less CPU in background if (!glfwGetWindowParam(GLFW_ACTIVE)) { glfwSleep(0.100); } } } // Clean up OglUtilsKillFont(); glfwTerminate(); std::cout << "\nReturning 0 from main().\n"; return 0; }
int main (int argc, const char * argv[]) { TwBar *myBar; float bgColor[] = { 0.0f, 0.0f, 0.0f, 0.1f }; glm::mat4 mat; float axis[] = { 0.7f, 0.7f, 0.7f }; // initial model rotation float angle = 0.8f; double FT = 0; double FPS = 0; double starting = 0.0; double ending = 0.0; int rate = 0; int fr = 0; zNear = 0.1f; zFar = 100.0f; FOV = 45.0f; // Current time double time = 0; // initialise GLFW int running = GL_TRUE; if (!glfwInit()) { exit(EXIT_FAILURE); } //only for OpenGL 2.1 #ifdef USE_OPENGL21 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 2); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1); #endif //Only for OpenGL 3.2 #ifdef USE_OPENGL32 glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1); #endif GLFWvidmode mode; glfwGetDesktopMode(&mode); if( !glfwOpenWindow(windowWidth, windowHeight, mode.RedBits, mode.GreenBits, mode.BlueBits, 0, 32, 0, GLFW_WINDOW /* or GLFW_FULLSCREEN */) ) { glfwTerminate(); exit(EXIT_FAILURE); } glfwEnable(GLFW_MOUSE_CURSOR); glfwEnable(GLFW_KEY_REPEAT); // Ensure we can capture the escape key being pressed below glfwEnable( GLFW_STICKY_KEYS ); glfwSetMousePos(windowWidth/2, windowHeight/2); glfwSetWindowTitle("Chapter-11"); // Initialize AntTweakBar if ( !TwInit(TW_OPENGL_CORE, NULL)) { fprintf(stderr,"AntweakBar initialiazation failed: %s\n",TwGetLastError()); exit(1); } // Create a tweak bar myBar = TwNewBar("TweakBar"); //init GLEW and basic OpenGL information // VERY IMPORTANT OTHERWISE GLEW CANNOT HANDLE GL3 #ifdef USE_OPENGL32 glewExperimental = true; #endif glewInit(); std::cout<<"\nUsing GLEW "<<glewGetString(GLEW_VERSION)<<std::endl; if (GLEW_VERSION_2_1) { std::cout<<"\nYay! OpenGL 2.1 is supported and GLSL 1.2!\n"<<std::endl; } if (GLEW_VERSION_3_2) { std::cout<<"Yay! OpenGL 3.2 is supported and GLSL 1.5!\n"<<std::endl; } /* This extension defines an interface that allows various types of data (especially vertex array data) to be cached in high-performance graphics memory on the server, thereby increasing the rate of data transfers. Chunks of data are encapsulated within "buffer objects", which conceptually are nothing more than arrays of bytes, just like any chunk of memory. An API is provided whereby applications can read from or write to buffers, either via the GL itself (glBufferData, glBufferSubData, glGetBufferSubData) or via a pointer to the memory. */ if (glewIsSupported("GL_ARB_vertex_buffer_object")) std::cout<<"ARB VBO's are supported"<<std::endl; else if (glewIsSupported("GL_APPLE_vertex_buffer_object")) std::cout<<"APPLE VBO's are supported"<<std::endl; else std::cout<<"VBO's are not supported,program will not run!!!"<<std::endl; /* This extension introduces named vertex array objects which encapsulate vertex array state on the client side. The main purpose of these objects is to keep pointers to static vertex data and provide a name for different sets of static vertex data. By extending vertex array range functionality this extension allows multiple vertex array ranges to exist at one time, including their complete sets of state, in manner analogous to texture objects. GenVertexArraysAPPLE creates a list of n number of vertex array object names. After creating a name, BindVertexArrayAPPLE associates the name with a vertex array object and selects this vertex array and its associated state as current. To get back to the default vertex array and its associated state the client should bind to vertex array named 0. */ if (glewIsSupported("GL_ARB_vertex_array_object")) std::cout<<"ARB VAO's are supported\n"<<std::endl; else if (glewIsSupported("GL_APPLE_vertex_array_object"))//this is the name of the extension for GL2.1 in MacOSX std::cout<<"APPLE VAO's are supported\n"<<std::endl; else std::cout<<"VAO's are not supported, program will not run!!!\n"<<std::endl; std::cout<<"Vendor: "<<glGetString (GL_VENDOR)<<std::endl; std::cout<<"Renderer: "<<glGetString (GL_RENDERER)<<std::endl; std::cout<<"Version: "<<glGetString (GL_VERSION)<<std::endl; std::ostringstream stream1,stream2; stream1 << glGetString(GL_VENDOR); stream2 << glGetString(GL_RENDERER); std::string vendor ="Title : Chapter-11 Vendor : " + stream1.str() + " Renderer : " +stream2.str(); const char *tit = vendor.c_str(); glfwSetWindowTitle(tit); // Set GLFW event callbacks // - Redirect window size changes to the callback function WindowSizeCB glfwSetWindowSizeCallback(WindowSizeCB); // - Directly redirect GLFW mouse button events to AntTweakBar glfwSetMouseButtonCallback((GLFWmousebuttonfun)TwEventMouseButtonGLFW); // - Directly redirect GLFW mouse position events to AntTweakBar glfwSetMousePosCallback((GLFWmouseposfun)TwEventMousePosGLFW); // - Directly redirect GLFW mouse wheel events to AntTweakBar glfwSetMouseWheelCallback((GLFWmousewheelfun)TwEventMouseWheelGLFW); // - Directly redirect GLFW key events to AntTweakBar glfwSetKeyCallback((GLFWkeyfun)TwEventKeyGLFW); // - Directly redirect GLFW char events to AntTweakBar glfwSetCharCallback((GLFWcharfun)TwEventCharGLFW); TwDefine("TweakBar label='Main TweakBar' alpha=0 help='Use this bar to control the objects of the scene.' "); // Add 'wire' to 'myBar': it is a modifable variable of type TW_TYPE_BOOL32 (32 bits boolean). Its key shortcut is [w]. TwAddVarRW(myBar, "wireframe mode", TW_TYPE_BOOL32, &wireFrame," label='Wireframe mode' key=w help='Toggle wireframe display mode.' "); // Add 'bgColor' to 'myBar': it is a modifable variable of type TW_TYPE_COLOR3F (3 floats color) TwAddVarRW(myBar, "bgColor", TW_TYPE_COLOR3F, &bgColor, " label='Background color' "); // Add 'Rotation' to 'myBar': this is a variable of type TW_TYPE_QUAT4F which defines the scene's orientation TwAddVarRW(myBar, "SceneRotation", TW_TYPE_QUAT4F, &Rotation," label='Scene rotation' opened=true help='Change the scenes orientation.' "); TwAddButton(myBar, "Reset", ResetView,NULL," label='Reset View' "); TwAddVarRW(myBar, "Near Clip Plane", TW_TYPE_FLOAT, &zNear,"min=0.5 max=100 step=0.5 label='Near Clip' group='Projection Properties'"); TwAddVarRW(myBar, "Far Clip Plane", TW_TYPE_FLOAT, &zFar," min=0.5 max=1000 step=0.5 label='Far Clip' group='Projection Properties'"); TwAddVarRW(myBar, "Field of View", TW_TYPE_FLOAT, &FOV," label='FoV' readonly=true group='Projection Properties'"); TwAddVarRW(myBar, "MS per 1 Frame" , TW_TYPE_DOUBLE, &FPS, "label='MS per 1 Frame' readonly=true group='Frame Rate'"); TwAddVarRW(myBar, "Frames Per Second" , TW_TYPE_INT32, &rate, "label='FPS' readonly=true group='Frame Rate'"); TwAddVarRW(myBar, "vSYNC" , TW_TYPE_BOOL8, &SYNC, "label='vSync' readonly=true group='Frame Rate'"); // Enable depth test glEnable(GL_DEPTH_TEST); // Accept fragment if it closer to the camera than the former one glDepthFunc(GL_LESS); initPlane(); //initialize Plane init3Dmodel(); // initialize 3D model create_Bump_bar(); GLfloat rat = 0.001f; if(SYNC == false) { rat = 0.001f; } else { rat = 0.01f; } // Initialize time time = glfwGetTime(); double currentTime; float lastTime = 0.0f; int Frames = 0; double LT = glfwGetTime(); starting = glfwGetTime(); setVSync(SYNC); while (running) { glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); glClearColor( bgColor[0], bgColor[1], bgColor[2], bgColor[3]); //black color FOV = initialFoV - 5 * glfwGetMouseWheel(); if(camera == true) { glfwGetMousePos(&xpos,&ypos); glfwSetMousePos(windowWidth/2, windowHeight/2); horizAngle += mouseSpeedo * float(windowWidth/2 - xpos ); verticAngle += mouseSpeedo * float( windowHeight/2 - ypos ); } glm::vec3 direction(cos(verticAngle) * sin(horizAngle),sin(verticAngle),cos(verticAngle) * cos(horizAngle)); glm::vec3 right = glm::vec3(sin(horizAngle - 3.14f/2.0f),0,cos(horizAngle - 3.14f/2.0f)); glm::vec3 up = glm::cross( right, direction ); currentTime = glfwGetTime(); float dTime = float(currentTime - lastTime); lastTime = (float)currentTime; // Move forward if (glfwGetKey( GLFW_KEY_UP ) == GLFW_PRESS){ pos += direction * dTime* speedo; } // Move backward if (glfwGetKey( GLFW_KEY_DOWN ) == GLFW_PRESS){ pos -= direction * dTime * speedo; } // Strafe right if (glfwGetKey( GLFW_KEY_RIGHT ) == GLFW_PRESS){ pos += right * dTime * speedo; } //Strafe left if (glfwGetKey( GLFW_KEY_LEFT ) == GLFW_PRESS){ pos -= right * dTime * speedo; } if (glfwGetKey(GLFW_KEY_SPACE) == GLFW_PRESS){ if(camera == false) { camera=true; glfwSetMousePos(windowWidth/2, windowHeight/2); glfwGetMousePos(&xpos,&ypos); } else { camera=false; glfwSetMousePos(windowWidth/2, windowHeight/2); glfwGetMousePos(&xpos,&ypos); } } mat = ConvertQuaternionToMatrix(Rotation, mat); glm::mat4 cube; glm::mat4 translateMat = glm::mat4(); translateMat = glm::translate(translateMat,glm::vec3(5.0,3.0,4.0)); cube = mat * translateMat; displayPlane(mat,pos,direction,up); display3Dmodel(cube,mat,pos,direction,up); // drawing the AntWeakBar if (wireFrame) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); TwDraw(); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); TwDraw(); } fr++; ending = glfwGetTime(); if(ending - starting >= 1) { rate = fr; fr = 0; starting = glfwGetTime(); } double CT = glfwGetTime(); Frames++; if(CT -LT >= 1.0) { FPS = 1000.0 / (double)Frames; Frames = 0; LT += 1.0f; } glfwSwapBuffers(); //check if ESC was pressed running=!glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); } //close OpenGL window and terminate AntTweakBar and GLFW TwTerminate(); glfwTerminate(); exit(EXIT_SUCCESS); }
// Main int main() { GLFWvidmode mode; // GLFW video mode TwBar *bar; // Pointer to a tweak bar double time = 0, dt;// Current time and enlapsed time double turn = 0; // Model turn counter double speed = 0.3; // Model rotation speed int wire = 0; // Draw model in wireframe? float bgColor[] = { 0.1f, 0.2f, 0.4f }; // Background color unsigned char cubeColor[] = { 255, 0, 0, 128 }; // Model color (32bits RGBA) // Intialize GLFW if( !glfwInit() ) { // An error occured fprintf(stderr, "GLFW initialization failed\n"); return 1; } // Create a window glfwGetDesktopMode(&mode); if( !glfwOpenWindow(640, 480, mode.RedBits, mode.GreenBits, mode.BlueBits, 0, 16, 0, GLFW_WINDOW /* or GLFW_FULLSCREEN */) ) { // A fatal error occured fprintf(stderr, "Cannot open GLFW window\n"); glfwTerminate(); return 1; } glfwEnable(GLFW_MOUSE_CURSOR); glfwEnable(GLFW_KEY_REPEAT); glfwSetWindowTitle("AntTweakBar simple example using GLFW"); // Initialize AntTweakBar TwInit(TW_OPENGL, NULL); // Create a tweak bar bar = TwNewBar("TweakBar"); TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLFW and OpenGL.' "); // Message added to the help bar. // Add 'speed' to 'bar': it is a modifable (RW) variable of type TW_TYPE_DOUBLE. Its key shortcuts are [s] and [S]. TwAddVarRW(bar, "speed", TW_TYPE_DOUBLE, &speed, " label='Rot speed' min=0 max=2 step=0.01 keyIncr=s keyDecr=S help='Rotation speed (turns/second)' "); // Add 'wire' to 'bar': it is a modifable variable of type TW_TYPE_BOOL32 (32 bits boolean). Its key shortcut is [w]. TwAddVarRW(bar, "wire", TW_TYPE_BOOL32, &wire, " label='Wireframe mode' key=w help='Toggle wireframe display mode.' "); // Add 'time' to 'bar': it is a read-only (RO) variable of type TW_TYPE_DOUBLE, with 1 precision digit TwAddVarRO(bar, "time", TW_TYPE_DOUBLE, &time, " label='Time' precision=1 help='Time (in seconds).' "); // Add 'bgColor' to 'bar': it is a modifable variable of type TW_TYPE_COLOR3F (3 floats color) TwAddVarRW(bar, "bgColor", TW_TYPE_COLOR3F, &bgColor, " label='Background color' "); // Add 'cubeColor' to 'bar': it is a modifable variable of type TW_TYPE_COLOR32 (32 bits color) with alpha TwAddVarRW(bar, "cubeColor", TW_TYPE_COLOR32, &cubeColor, " label='Cube color' alpha help='Color and transparency of the cube.' "); // Set GLFW event callbacks // - Redirect window size changes to the callback function WindowSizeCB glfwSetWindowSizeCallback(WindowSizeCB); // - Directly redirect GLFW mouse button events to AntTweakBar glfwSetMouseButtonCallback((GLFWmousebuttonfun)TwEventMouseButtonGLFW); // - Directly redirect GLFW mouse position events to AntTweakBar glfwSetMousePosCallback((GLFWmouseposfun)TwEventMousePosGLFW); // - Directly redirect GLFW mouse wheel events to AntTweakBar glfwSetMouseWheelCallback((GLFWmousewheelfun)TwEventMouseWheelGLFW); // - Directly redirect GLFW key events to AntTweakBar glfwSetKeyCallback((GLFWkeyfun)TwEventKeyGLFW); // - Directly redirect GLFW char events to AntTweakBar glfwSetCharCallback((GLFWcharfun)TwEventCharGLFW); // Initialize time time = glfwGetTime(); // Main loop (repeated while window is not closed and [ESC] is not pressed) while( glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC) ) { // Clear frame buffer using bgColor glClearColor(bgColor[0], bgColor[1], bgColor[2], 1); glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); // Rotate model dt = glfwGetTime() - time; if( dt < 0 ) dt = 0; time += dt; turn += speed*dt; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotated(360.0*turn, 0.4, 1, 0.2); glTranslated(-0.5, -0.5, -0.5); // Set color and draw model glColor4ubv(cubeColor); DrawModel(wire); // Draw tweak bars TwDraw(); // Present frame buffer glfwSwapBuffers(); } // Terminate AntTweakBar and GLFW TwTerminate(); glfwTerminate(); return 0; }
uint16 Screen::GetDesktopHeight() const { GLFWvidmode mode; glfwGetDesktopMode(&mode); return uint16(mode.Height); }
uint16 Screen::GetDesktopWidth() const { GLFWvidmode mode; glfwGetDesktopMode(&mode); return uint16(mode.Width); }
// Main function int main() { // Initialize GLFW if( !glfwInit() ) { // A fatal error occurred std::cerr << "GLFW initialization failed" << std::endl; return 1; } // Create a window GLFWvidmode mode; glfwGetDesktopMode(&mode); if( !glfwOpenWindow(800, 600, mode.RedBits, mode.GreenBits, mode.BlueBits, 0, 16, 0, GLFW_WINDOW /* or GLFW_FULLSCREEN */) ) { // A fatal error occurred std::cerr << "Cannot open GLFW window" << std::endl; glfwTerminate(); return 1; } glfwSwapInterval(0); glfwEnable(GLFW_MOUSE_CURSOR); glfwEnable(GLFW_KEY_REPEAT); const char title[] = "AntTweakBar example: TwAdvanced1"; glfwSetWindowTitle(title); // Set GLFW event callbacks glfwSetWindowSizeCallback(OnWindowSize); glfwSetMouseButtonCallback(OnMouseButton); glfwSetMousePosCallback(OnMousePos); glfwSetMouseWheelCallback(OnMouseWheel); glfwSetKeyCallback(OnKey); glfwSetCharCallback(OnChar); // Initialize AntTweakBar TwInit(TW_OPENGL, NULL); // Change the font size, and add a global message to the Help bar. TwDefine(" GLOBAL fontSize=3 help='This example illustrates the definition of custom structure type as well as many other features.' "); // Initialize the 3D scene Scene scene; scene.Init(true); // Create a tweak bar called 'Main' and change its refresh rate, position, size and transparency TwBar *mainBar = TwNewBar("Main"); TwDefine(" Main label='Main TweakBar' refresh=0.5 position='16 16' size='260 320' alpha=0"); // Add some variables to the Main tweak bar TwAddVarRW(mainBar, "Wireframe", TW_TYPE_BOOLCPP, &scene.Wireframe, " group='Display' key=w help='Toggle wireframe display mode.' "); // 'Wireframe' is put in the group 'Display' (which is then created) TwAddVarRW(mainBar, "BgTop", TW_TYPE_COLOR3F, &scene.BgColor1, " group='Background' help='Change the top background color.' "); // 'BgTop' and 'BgBottom' are put in the group 'Background' (which is then created) TwAddVarRW(mainBar, "BgBottom", TW_TYPE_COLOR3F, &scene.BgColor0, " group='Background' help='Change the bottom background color.' "); TwDefine(" Main/Background group='Display' "); // The group 'Background' of bar 'Main' is put in the group 'Display' TwAddVarCB(mainBar, "Subdiv", TW_TYPE_INT32, SetSubdivCB, GetSubdivCB, &scene, " group='Scene' label='Meshes subdivision' min=1 max=50 keyincr=s keyDecr=S help='Subdivide the meshes more or less (switch to wireframe to see the effect).' "); TwAddVarRW(mainBar, "Ambient", TW_TYPE_FLOAT, &scene.Ambient, " label='Ambient factor' group='Scene' min=0 max=1 step=0.001 keyIncr=a keyDecr=A help='Change scene ambient.' "); TwAddVarRW(mainBar, "Reflection", TW_TYPE_FLOAT, &scene.Reflection, " label='Reflection factor' group='Scene' min=0 max=1 step=0.001 keyIncr=r keyDecr=R help='Change ground reflection.' "); // Create a new TwType called rotationType associated with the Scene::RotMode enum, and use it TwEnumVal rotationEV[] = { { Scene::ROT_OFF, "Stopped"}, { Scene::ROT_CW, "Clockwise" }, { Scene::ROT_CCW, "Counter-clockwise" } }; TwType rotationType = TwDefineEnum( "Rotation Mode", rotationEV, 3 ); TwAddVarRW(mainBar, "Rotation", rotationType, &scene.Rotation, " group='Scene' keyIncr=Backspace keyDecr=SHIFT+Backspace help='Stop or change the rotation mode.' "); // Add a read-only float variable; its precision is 0 which means that the fractionnal part of the float value will not be displayed TwAddVarRO(mainBar, "RotYAngle", TW_TYPE_DOUBLE, &scene.RotYAngle, " group='Scene' label='Rot angle (degree)' precision=0 help='Animated rotation angle' "); // Initialize time double time = glfwGetTime(), dt = 0; // Current time and elapsed time double frameDTime = 0, frameCount = 0, fps = 0; // Framerate // Main loop (repeated while window is not closed) while( glfwGetWindowParam(GLFW_OPENED) ) { // Get elapsed time dt = glfwGetTime() - time; if (dt < 0) dt = 0; time += dt; // Rotate scene if( scene.Rotation==Scene::ROT_CW ) scene.RotYAngle -= 5.0*dt; else if( scene.Rotation==Scene::ROT_CCW ) scene.RotYAngle += 5.0*dt; // Move lights scene.Update(time); // Draw scene scene.Draw(); // Draw tweak bars TwDraw(); // Present frame buffer glfwSwapBuffers(); // Estimate framerate frameCount++; frameDTime += dt; if( frameDTime>1.0 ) { fps = frameCount/frameDTime; char newTitle[128]; _snprintf(newTitle, sizeof(newTitle), "%s (%.1f fps)", title, fps); //glfwSetWindowTitle(newTitle); // uncomment to display framerate frameCount = frameDTime = 0; } } // Terminate AntTweakBar and GLFW TwTerminate(); glfwTerminate(); return 0; }
int main(int argc, char* argv[]) { app_argc = argc; app_argv = argv; int width, height, running, frames, x, y; double t, t1; char titlestr[ 200 ]; // Initialise GLFW glfwInit(); bool start_fullscreen = false; int x_res = 1280; int y_res = 720; bool manual_resolution_set = false; for (int i = 1; i < argc; i++) { vsx_string arg1 = argv[i]; if (arg1 == "--help" || arg1 == "/?" || arg1 == "-help" || arg1 == "-?") { printf( "Usage:\n" " vsxu_player [path_to_vsx_file]\n" "\n" "Flags: \n" " -pl Preload all visuals on start \n" " -dr Disable randomizer \n" " -p [x,y] Set window position x,y \n" " -s [x,y] Set window size x,y \n\n\n" ); exit(0); } else if (arg1 == "-f") { start_fullscreen = true; } else if (arg1 == "-pl") { option_preload_all = true; } else if (arg1 == "-dr") { disable_randomizer = true; } else if (arg1 == "-no") { no_overlay = true; } else if (arg1 == "-s") { if (i+1 < argc) { i++; vsx_string arg2 = argv[i]; vsx_avector<vsx_string> parts; vsx_string deli = ","; explode(arg2, deli, parts); if (parts.size() == 2) { x_res = s2i(parts[0]); y_res = s2i(parts[1]); manual_resolution_set = true; } else { deli = "x"; explode(arg2, deli, parts); if ( parts.size() == 2 ) { x_res = s2i(parts[0]); y_res = s2i(parts[1]); manual_resolution_set = true; } } } } } if (start_fullscreen && !manual_resolution_set) { // try to get the resolution from the desktop for fullscreen GLFWvidmode video_mode; glfwGetDesktopMode(&video_mode); x_res = video_mode.Height; y_res = video_mode.Width; } // Open OpenGL window glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); if( !glfwOpenWindow( x_res, y_res, 0,0,0,0,16,0, start_fullscreen?GLFW_FULLSCREEN:GLFW_WINDOW ) ) // GLFW_FULLSCREEN { printf("Error! Could not create an OpenGL context. Please check your GPU drivers...\n"); glfwTerminate(); return 0; } if (start_fullscreen) glfwEnable( GLFW_MOUSE_CURSOR ); app_init(0); glfwEnable(GLFW_AUTO_POLL_EVENTS); for (int i = 1; i < argc; i++) { vsx_string arg1 = argv[i]; if (arg1 == "-p") { if (i+1 < argc) { i++; vsx_string arg2 = argv[i]; vsx_avector<vsx_string> parts; vsx_string deli = ","; explode(arg2, deli, parts); glfwSetWindowPos(s2i(parts[0]), s2i(parts[1])); } } } glfwSetKeyCallback(&key_event); glfwSetMouseButtonCallback(&mouse_button_event); glfwSetMousePosCallback(&mouse_pos_event); glfwSetCharCallback(&key_char_event); glfwSetMouseWheelCallback(&mouse_wheel); // set window size callback function glfwSetWindowSizeCallback(window_size); // Enable sticky keys glfwEnable( GLFW_STICKY_KEYS ); glfwSwapInterval(1); // Main loop running = GL_TRUE; frames = 0; #if PLATFORM_FAMILY == PLATFORM_FAMILY_UNIX sprintf( titlestr, "Vovoid VSXu Player %s [GNU/Linux %d-bit]", vsxu_ver, PLATFORM_BITS); #endif #if PLATFORM_FAMILY == PLATFORM_FAMILY_WINDOWS sprintf( titlestr, "Vovoid VSXu Player %s [Windows %d-bit]", vsxu_ver, PLATFORM_BITS); #endif glfwSetWindowTitle( titlestr ); while( running ) { if (mouse_pos_type) { if (mouse_pos_type == 1) app_mouse_move(last_x,last_y); else app_mouse_move_passive(last_x,last_y); mouse_pos_type = 0; } app_pre_draw(); // Get time and mouse position t = glfwGetTime(); glfwGetMousePos( &x, &y ); float delta = t-t1; t1 = t; if (key_pressed != -1) { //printf("%f\n", delta); key_time += delta; if (key_time > 0.3f) { key_repeat_time += delta; if (key_repeat_time > initial_key_delay) { key_repeat_time = 0.0f; if (key_character != -1) app_char(key_character); app_key_down((long)key_pressed); initial_key_delay *= 0.99f; //printf("repeating key: %d\n", key_character); } } } frames ++; // Get window size (may be different than the requested size) glfwGetWindowSize( &width, &height ); height = height > 0 ? height : 1; // Set viewport gl_state.viewport_set( 0, 0, width, height ); // Clear color buffer glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClear( GL_COLOR_BUFFER_BIT ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); app_draw(0); glfwSwapBuffers(); // Check if the ESC key was pressed or the window was closed running = /*!glfwGetKey( GLFW_KEY_ESC ) &&*/ glfwGetWindowParam( GLFW_OPENED ); } // Close OpenGL window and terminate GLFW glfwTerminate(); return 0; }
int main(int argc, char** argv) { parseConfigXml(); if (sceneFile.empty() && argc >= 2) { sceneFile = argv[1]; } if (sceneFile.empty()) { std::cerr << "No Scenefile given. Please configure config.xml or pass an argument!" << std::endl; glfwOpenWindow( 640, 16, 8, 8, 8, 8, 24, 8, GLFW_WINDOW ); glfwSetWindowTitle( "No Scenefile given. Please configure config.xml or pass an argument!" ); double startTime = glfwGetTime(); while( glfwGetTime() - startTime < 5.0 ) {} glfwTerminate(); return -1; } // Initialize GLFW glfwInit(); if( !setupWindow( width, height, fullScreen ) ) return -1; GLFWvidmode desktopMode; glfwGetDesktopMode( &desktopMode ); // Initalize application and engine app = new DemoApp(); if ( !app->init(sceneFile.c_str()) ) { std::cout << "Unable to initalize engine" << std::endl; std::cout << "Make sure you have an OpenGL 2.0 compatible graphics card"; // Fake message box glfwCloseWindow(); glfwOpenWindow( 800, 16, 8, 8, 8, 8, 24, 8, GLFW_WINDOW ); glfwSetWindowTitle( "Unable to initalize engine - Make sure you have an OpenGL 2.0 compatible " "graphics card and have specified a valid GameEngine scene" ); double startTime = glfwGetTime(); while( glfwGetTime() - startTime < 5.0 ) {} // Sleep glfwTerminate(); return -1; } app->resize( width, height ); //glfwDisable( GLFW_MOUSE_CURSOR ); int frames = 0; float fps = 30.0f; t0 = glfwGetTime(); running = true; // Game loop while( running ) { // Calc FPS ++frames; if( frames >= 3 ) { double t = glfwGetTime(); fps = frames / (float)(t - t0); frames = 0; t0 = t; } // Render app->render(); glfwSwapBuffers(); } glfwEnable( GLFW_MOUSE_CURSOR ); // Quit app->release(); delete app; glfwTerminate(); return 0; }
int main(int argc, char *argv[]) { if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(1); } printf("Welcome to the demo. Controls are quite simple--left/right arrows and space to play, escape to quit. Enjoy!\n"); printf("Press enter to continue..."); std::getchar(); // Demand a core profile. glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // This is really for multisampling not FSAA but whatevs, we still need it. glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 8); int screen_mode = fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW; int width, height; if (fullscreen) { // Gets native resolution of monitor. GLFWvidmode mode; glfwGetDesktopMode(&mode); width = mode.Width; height = mode.Height; } else { width = 800; height = 600; } if (!glfwOpenWindow(width, height, 0, 0, 0, 0, 24, 8, screen_mode)) { fprintf(stderr, "Failed to open GLFW window.\n"); cleanupAndExit(1); } int major, minor, rev; glfwGetGLVersion(&major, &minor, &rev); fprintf(stderr, "OpenGL version: %d.%d.%d\n", major, minor, rev); // Init glew. We need experimental for a core profile till glew fixes a bug... glewExperimental = GL_TRUE; GLenum err = glewInit(); // Glew init spawns an error sometimes. This clears the GL error state for our own use. glGetError(); if (GLEW_OK != err) { fprintf(stderr, "GLEW error: %s\n", glewGetErrorString(err)); cleanupAndExit(1); } if (!GLEW_VERSION_3_3) { fprintf(stderr, "OpenGL 3.3 is not supported.\n"); cleanupAndExit(1); } // GLFW options. glfwEnable(GLFW_KEY_REPEAT); glfwSwapInterval(1); // Set callback functions. glfwSetKeyCallback(keyboardCallback); glfwSetWindowCloseCallback(windowCloseCallback); // Make the main game object. game = new Game(); game->init(width, height); // Main loop. int frame = 0; int print_frequency = 500; float last_print_time = static_cast<float>(glfwGetTime()); float time_updating = 0.0f, time_drawing = 0.0f; while (game->stillRunning()) { float frame_start_time = static_cast<float>(glfwGetTime()); ++frame; // Update and draw the game. game->draw(); // glFinish will hurt framerate but gives better estimate of the draw time. //glFinish(); float frame_draw_time = static_cast<float>(glfwGetTime()); time_drawing += frame_draw_time - frame_start_time; game->update(); time_updating += static_cast<float>(glfwGetTime()) - frame_draw_time; // Print the frame rate every once and a while. if (frame % print_frequency == 0) { float time_elapsed = frame_start_time - last_print_time; printf("FPS: %f\n", print_frequency / (time_elapsed)); last_print_time = frame_start_time; printf("Draw time per frame: %f.\n", time_drawing / print_frequency); time_drawing = 0.0f; printf("Update time per frame: %f.\n", time_updating / print_frequency); time_updating = 0.0f; } glfwSwapBuffers(); } cleanupAndExit(0); return 0; }
/* * main(argc, argv) - the standard C entry point for the program */ int main(int argc, char *argv[]) { GLuint quadList, sphereList; GLuint programObject[5]; // One quad and four spheres double fps = 0.0; GLFWvidmode vidmode; GLboolean running = GL_TRUE; // Main loop exits when this is set to GL_FALSE // Initialise GLFW glfwInit(); // Open a temporary OpenGL window just to determine the desktop size if( !glfwOpenWindow(256, 256, 8,8,8,8, 32,0, GLFW_WINDOW) ) { glfwTerminate(); // glfwOpenWindow failed, quit the program. return 1; } glfwGetDesktopMode(&vidmode); glfwCloseWindow(); // Open a window to cover the width of the current desktop if( !glfwOpenWindow(vidmode.Width-20, (int)(0.316*(vidmode.Width-20)), 8,8,8,8, 32,0, GLFW_WINDOW) ) { glfwTerminate(); // glfwOpenWindow failed, quit the program. return 1; } // Load the extensions for GLSL - note that this has to be done // *after* the window has been opened, or we won't have a GL context // to query for those extensions and connect to instances of them. loadExtensions(); printf("GL vendor: %s\n", glGetString(GL_VENDOR)); printf("GL renderer: %s\n", glGetString(GL_RENDERER)); printf("GL version: %s\n", glGetString(GL_VERSION)); printf("Desktop size: %d x %d pixels\n", vidmode.Width, vidmode.Height); glEnable(GL_DEPTH_TEST); // Use the Z buffer glfwSwapInterval(0); // Do not wait for screen refresh between frames // Compile a display list for the demo geometry, to render it efficiently initQuadList(&quadList); initSphereList(&sphereList); createShader(&programObject[0], PATH VERTSHADER0, PATH FRAGSHADER0); createShader(&programObject[1], PATH VERTSHADER1, PATH FRAGSHADER1); createShader(&programObject[2], PATH VERTSHADER2, PATH FRAGSHADER2); createShader(&programObject[3], PATH VERTSHADER3, PATH FRAGSHADER3); createShader(&programObject[4], PATH VERTSHADER4, PATH FRAGSHADER4); // Main loop while(running) { // Calculate and update the frames per second (FPS) display fps = computeFPS(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(0.0f, 0.3f, 0.5f, 0.0f); // Set up the camera projection. setupCamera(); // Draw the scene. renderScene(quadList, sphereList, programObject); // Swap buffers, i.e. display the image and prepare for next frame. glfwSwapBuffers(); // Exit if the ESC key is pressed or the window is closed. if(glfwGetKey(GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED)) { running = GL_FALSE; } } printf("Performance: %.1f FPS\n", fps); // Close the OpenGL window and terminate GLFW. glfwTerminate(); return 0; }
int main(int argc, char** argv) { int width, height, ch; int mode = GLFW_WINDOWED; GLFWwindow window; while ((ch = getopt(argc, argv, "fh")) != -1) { switch (ch) { case 'h': usage(); exit(EXIT_SUCCESS); case 'f': mode = GLFW_FULLSCREEN; break; default: usage(); exit(EXIT_FAILURE); } } glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); if (mode == GLFW_FULLSCREEN) { GLFWvidmode desktop_mode; glfwGetDesktopMode(&desktop_mode); width = desktop_mode.width; height = desktop_mode.height; } else { width = 200; height = 200; } window = glfwCreateWindow(width, height, mode, "Gamma Test", NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } set_gamma(1.f); glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwSetKeyCallback(window, key_callback); glfwSetWindowCloseCallback(window, window_close_callback); glfwSetWindowSizeCallback(window, size_callback); glMatrixMode(GL_PROJECTION); glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f); glMatrixMode(GL_MODELVIEW); glClearColor(0.5f, 0.5f, 0.5f, 0); while (!closed) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.8f, 0.2f, 0.4f); glRectf(-0.5f, -0.5f, 0.5f, 0.5f); glfwSwapBuffers(window); glfwPollEvents(); } glfwTerminate(); exit(EXIT_SUCCESS); }
int changeWindowMode(){ glfwGetDesktopMode(&desktop); if (gameMode){ //Passar para modo janela glfwCloseWindow(); width = 800; height = 600; // get the current Desktop screen resolution and colour depth // open the window at the current Desktop resolution and colour depth if (!glfwOpenWindow( width, height, desktop.RedBits, desktop.GreenBits, desktop.BlueBits, 8, // alpha bits 32, // depth bits 0, // stencil bits GLFW_WINDOW )) { std::cout << "Failed to open window window!" << std::endl; glfwTerminate(); return GLFW_WINDOW_ERROR; } gameMode = false; AppStart(); } else{ //Passar para o modo de jogo glfwCloseWindow(); width = desktop.Width; height = desktop.Height; // open the window at the current Desktop resolution and colour depth if (!glfwOpenWindow( width, height, desktop.RedBits, desktop.GreenBits, desktop.BlueBits, 8, // alpha bits 32, // depth bits 0, // stencil bits GLFW_FULLSCREEN )) { std::cout << "Failed to open fullscreen window!" << std::endl; glfwTerminate(); return GLFW_WINDOW_ERROR; } gameMode = true; AppStart(); } }