int main () { // Initialize GLFW if ( !glfwInit()) { std::cerr << "Failed to initialize GLFW! I'm out!" << std::endl; exit(-1); } // Use OpenGL 3.2 core profile /* glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); */ // Open a window and attach an OpenGL rendering context to the window surface if( !glfwOpenWindow(500, 500, 8, 8, 8, 0, 0, 0, GLFW_WINDOW)) { std::cerr << "Failed to open a window! I'm out!" << std::endl; glfwTerminate(); exit(-1); } // Register a callback function for window resize events glfwSetWindowSizeCallback( window_resized ); // Register a callback function for keyboard pressed events glfwSetKeyCallback(keyboard); // Print the OpenGL version int major, minor, rev; glfwGetGLVersion(&major, &minor, &rev); std::cout << "OpenGL - " << major << "." << minor << "." << rev << std::endl; // Initialize GLEW glewExperimental = GL_TRUE; if(glewInit() != GLEW_OK) { std::cerr << "Failed to initialize GLEW! I'm out!" << std::endl; glfwTerminate(); exit(-1); } // Create a rendering loop int running = GL_TRUE; while(running) { // Display scene display(); // Pool for events glfwPollEvents(); // Check if the window was closed running = glfwGetWindowParam(GLFW_OPENED); } // Terminate GLFW 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; }
void PullInfo(){ printf("================================================================================\n"); int major, minor, rev; glfwGetVersion(&major, &minor, &rev); printf("GLFW version is %i.%i.%i\n", major, minor, rev); int width, height; glfwGetWindowSize(&width, &height); printf("Window size is %i %i\n", width, height); int status = glfwGetKey(GLFW_KEY_LCTRL); if(status == GLFW_PRESS) printf("Left control is pressed\n"); else printf("Left control is released\n"); status = glfwGetMouseButton(GLFW_MOUSE_BUTTON_1); if(status == GLFW_PRESS) printf("Mouse button 1 is pressed\n"); else printf("Mouse button 1 is released\n"); int x, y; glfwGetMousePos(&x, &y); printf("Mouse position is %i %i\n", x, y); int wheel = glfwGetMouseWheel(); printf("Mouse wheel pos is %i\n", wheel); double time = glfwGetTime(); printf("Time is %f\n", time); glfwGetGLVersion(&major, &minor, &rev); printf("GL version is %i.%i.%i\n", major, minor, rev); int proc = glfwGetNumberOfProcessors(); printf("%i processors are available\n", proc); unsigned int i; for(i = 0; i<nb_params; i++) printf(" - %-27s : %i\n", GetParamName(params[i]), glfwGetWindowParam(params[i])); const char* extension = "MOZ_WEBGL_compressed_texture_s3tc"; printf("'%s' extension is %s.\n", extension, glfwExtensionSupported(extension) ? "supported" : "not supported"); extension = "GL_EXT_framebuffer_object"; printf("'%s' extension is %s.\n", extension, glfwExtensionSupported(extension) ? "supported" : "not supported"); extension = "glBindBuffer"; void* proc_addr = glfwGetProcAddress(extension); printf("'%s' extension proc address is %p.\n", extension, proc_addr); printf("Sleeping 1 sec...\n"); glfwSleep(1); printf("...Done.\n"); printf("================================================================================\n"); #ifdef REPORT_RESULT int result = 1; REPORT_RESULT(); #endif }
GLFWAPI int GLFWAPIENTRY glfwOpenWindow( int width, int height, int redbits, int greenbits, int bluebits, int alphabits, int depthbits, int stencilbits, int mode ) { int AccumRedBits, AccumGreenBits, AccumBlueBits, AccumAlphaBits; int AuxBuffers, Stereo, RefreshRate, x, Samples; // Is GLFW initialized? if( !_glfwInitialized || _glfwWin.Opened ) { return GL_FALSE; } // Check input arguments if( mode != GLFW_WINDOW && mode != GLFW_FULLSCREEN ) { return GL_FALSE; } // Clear GLFW window state _glfwWin.Active = GL_TRUE; _glfwWin.Iconified = GL_FALSE; _glfwWin.MouseLock = GL_FALSE; _glfwWin.AutoPollEvents = GL_TRUE; _glfwClearInput(); // Unregister all callback functions _glfwWin.WindowSizeCallback = NULL; _glfwWin.WindowCloseCallback = NULL; _glfwWin.WindowRefreshCallback = NULL; _glfwWin.KeyCallback = NULL; _glfwWin.CharCallback = NULL; _glfwWin.MousePosCallback = NULL; _glfwWin.MouseButtonCallback = NULL; _glfwWin.MouseWheelCallback = NULL; // Get window hints AccumRedBits = _glfwWinHints.AccumRedBits; AccumGreenBits = _glfwWinHints.AccumGreenBits; AccumBlueBits = _glfwWinHints.AccumBlueBits; AccumAlphaBits = _glfwWinHints.AccumAlphaBits; AuxBuffers = _glfwWinHints.AuxBuffers; Stereo = _glfwWinHints.Stereo; RefreshRate = _glfwWinHints.RefreshRate; Samples = _glfwWinHints.Samples; // Check width & height if( width > 0 && height <= 0 ) { // Set the window aspect ratio to 4:3 height = (width * 3) / 4; } else if( width <= 0 && height > 0 ) { // Set the window aspect ratio to 4:3 width = (height * 4) / 3; } else if( width <= 0 && height <= 0 ) { // Default window size width = 640; height = 480; } // Remember window settings _glfwWin.Width = width; _glfwWin.Height = height; _glfwWin.Fullscreen = (mode == GLFW_FULLSCREEN ? 1 : 0); _glfwWin.WindowNoResize = _glfwWinHints.WindowNoResize; // Platform specific window opening routine if( !_glfwPlatformOpenWindow( width, height, redbits, greenbits, bluebits, alphabits, depthbits, stencilbits, mode, AccumRedBits, AccumGreenBits, AccumBlueBits, AccumAlphaBits, AuxBuffers, Stereo, RefreshRate, Samples ) ) { return GL_FALSE; } // Flag that window is now opened _glfwWin.Opened = GL_TRUE; // Clear window hints _glfwWinHints.RefreshRate = 0; _glfwWinHints.AccumRedBits = 0; _glfwWinHints.AccumGreenBits = 0; _glfwWinHints.AccumBlueBits = 0; _glfwWinHints.AccumAlphaBits = 0; _glfwWinHints.AuxBuffers = 0; _glfwWinHints.Stereo = 0; _glfwWinHints.WindowNoResize = 0; _glfwWinHints.Samples = 0; // Get window parameters (such as color buffer bits etc) _glfwPlatformRefreshWindowParams(); // Get OpenGL version glfwGetGLVersion( &_glfwWin.GLVerMajor, &_glfwWin.GLVerMinor, &x ); // Do we have non-power-of-two textures? _glfwWin.Has_GL_ARB_texture_non_power_of_two = glfwExtensionSupported( "GL_ARB_texture_non_power_of_two" ); // Do we have automatic mipmap generation? _glfwWin.Has_GL_SGIS_generate_mipmap = (_glfwWin.GLVerMajor >= 2) || (_glfwWin.GLVerMinor >= 4) || glfwExtensionSupported( "GL_SGIS_generate_mipmap" ); // If full-screen mode was requested, disable mouse cursor if( mode == GLFW_FULLSCREEN ) { glfwDisable( GLFW_MOUSE_CURSOR ); } return GL_TRUE; }
int main () { // Initialize GLFW if ( !glfwInit()) { std::cerr << "Failed to initialize GLFW! I'm out!" << std::endl; exit(-1); } // Use OpenGL 3.2 core profile /* glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); */ // Open a window and attach an OpenGL rendering context to the window surface if( !glfwOpenWindow(800, 600, 8, 8, 8, 0, 0, 0, GLFW_WINDOW)) { std::cerr << "Failed to open a window! I'm out!" << std::endl; glfwTerminate(); exit(-1); } // Register a callback function for window resize events glfwSetWindowSizeCallback( window_resized ); // Register a callback function for keyboard pressed events glfwSetKeyCallback(keyboard); // Print the OpenGL version int major, minor, rev; glfwGetGLVersion(&major, &minor, &rev); std::cout << "OpenGL - " << major << "." << minor << "." << rev << std::endl; // Initialize GLEW glewExperimental = GL_TRUE; if(glewInit() != GLEW_OK) { std::cerr << "Failed to initialize GLEW! I'm out!" << std::endl; glfwTerminate(); exit(-1); } GLuint buffer; // Test if the new OpenGL functionality is available, without GLEW the next line will // generate an error on Linux and Windows glGenBuffers(1, &buffer); // Create a rendering loop int running = GL_TRUE; while(running) { // Use red to clear the screen glClearColor(1, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); // Swap front and back buffers glfwSwapBuffers(); // Pool for events glfwPollEvents(); // Check if the window was closed running = glfwGetWindowParam(GLFW_OPENED); } // Terminate GLFW glfwTerminate(); return 0; }
void initComponents() { int a, b, c, i, j, k; glfwGetVersion(&a, &b, &c); glfwGetGLVersion(&i, &j, &k); ostringstream ss; ss << "GLFW Version: " << a << "." << b << "." << c << " | "; ss << "OpenGL Version: " << i << "." << j << "." << k << " | "; ss << "FSAA_SAMPLES: " << glfwGetWindowParam(GLFW_FSAA_SAMPLES); button = new Button(); label1 = new Label(); label2 = new Label(); ipanel1 = new Panel(); label1->setLocation(20, 0); label2->setLocation(20, 690); label1->setText("0"); // label2->setAutoDimension(false); label2->setDimension(400, 200); label2->setAlign(Label::MiddleCenter); label2->setText(ss.str()); // image = Image::loadImage("/home/paulocanedo/Pictures/netbeans.png"); // label1->setImage(image); // label1->setDimension(200, 200); // label1->setAlign(Component::ComponentAlign::TopCenter); // label1->setAlign(Component::ComponentAlign::MiddleCenter); // label1->setAlign(Component::ComponentAlign::BottomCenter); // label1->setForegroundColor(pcglYellow); // label1->setBackgroundColor(pcglBootstrapBlue); int y = 80; int gap = 2; button->setLocation(20, 30); // button->setAutoDimension(false); // button->setDimension(300, 80); CustomAction *caction = new CustomAction(); button->setAction(caction); button->setText("Button 1"); rbutton1 = new RadioButton(); rbutton1->setLocation(20, y); rbutton1->setText("RadioButton 1"); y += rbutton1->getDimension().h + gap; rbutton2 = new RadioButton(); rbutton2->setLocation(20, y); rbutton2->setText("RadioButton 2"); y += rbutton1->getDimension().h + gap; rbutton3 = new RadioButton(); rbutton3->setLocation(20, y); rbutton3->setText("RadioButton 3"); y += rbutton1->getDimension().h + gap; rbutton4 = new RadioButton(); rbutton4->setLocation(20, y); rbutton4->setText("RadioButton 4"); y += rbutton1->getDimension().h + gap; rbutton5 = new RadioButton(); rbutton5->setLocation(0, 0); rbutton5->setText("RadioButton 5"); rbutton1->setGroupId(1); rbutton2->setGroupId(1); rbutton3->setGroupId(1); rbutton4->setGroupId(1); cbbutton1 = new CheckBoxButton(); cbbutton1->setText("CheckBox 1"); cbbutton1->setLocation(200, 80); cbbutton2 = new CheckBoxButton(); cbbutton2->setText("CheckBox 2"); cbbutton2->setLocation(200, 105); panel = new Panel(); panel->setDimension(1920 * 4, 1080 * 4); ipanel1->setLocation(100, 300); ipanel1->setDimension(500, 300); ipanel1->setBackgroundColor(pcglLightGray); ipanel1->add(rbutton5); panel->add(label1); panel->add(label2); panel->add(rbutton1); panel->add(rbutton2); panel->add(rbutton3); panel->add(rbutton4); panel->add(cbbutton1); panel->add(cbbutton2); panel->add(button); panel->add(ipanel1); rootc->add(panel); }
bool Window::open() { // Initialise GLFW if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); return false; } glfwOpenWindowHint(GLFW_FSAA_SAMPLES, ANTIALIASING); // 4x antialiasing glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); // We want OpenGL 4.1 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL // Open a window and create its OpenGL context if( !glfwOpenWindow( WINDOW_WIDTH, WINDOW_HEIGHT, 8,8,8,8, 0,0, WINDOW_MODE ) ) { fprintf( stderr, "Failed to open GLFW window\n" ); glfwTerminate(); return false; } int w,h; glfwGetWindowSize(&w,&h); glViewport(0,0,w,h); glfwEnable(GLFW_AUTO_POLL_EVENTS); // set window callback for when the window is resized glfwSetWindowSizeCallback((GLFWwindowsizefun)resize); // set window position glfwSetWindowPos(WINDOW_WIDTH/4,WINDOW_HEIGHT/4); // Initialize GLEW glewExperimental=true; // Needed in core profile if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); return false; } glfwSetWindowTitle( WINDOW_TITLE ); int version_major, version_minor, version_revision; glfwGetGLVersion(&version_major, &version_minor, &version_revision); printf("Using OpenGL version %d.%d\n",version_major,version_minor); printf("width %u height %u mode %d aa %u\n",WINDOW_WIDTH,WINDOW_HEIGHT,WINDOW_MODE,ANTIALIASING); printf("Window opened successfully\n"); // Ensure we can capture the escape key being pressed below glfwEnable( GLFW_STICKY_KEYS ); // set clear color glClearColor(0,0,0,0); // set clear depth glClearDepth(1); // set clear stencil buffer glClearStencil(0); //glViewport(0, 0, WINDOW_HEIGHT, WINDOW_WIDTH); // aspect ratio 1:1.333 //glOrtho(0.5f, -0.5f, -0.666f, 0.666f, -1.0f, 1.0f); // matching aspect ratio with 0,0 centered glScalef(1.0f, 1.0f, 1.0f); // Create vertex array object glGenVertexArrays(1, &vaoID); glBindVertexArray(vaoID); return true; }
int main(int argc, char** argv) { int ch, profile = 0, major = 1, minor = 1, revision; GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE; GLint flags, mask; while ((ch = getopt(argc, argv, "dfhlm:n:p:")) != -1) { switch (ch) { case 'd': debug = GL_TRUE; break; case 'f': forward = GL_TRUE; break; case 'h': usage(); exit(0); case 'l': list = GL_TRUE; break; case 'm': major = atoi(optarg); break; case 'n': minor = atoi(optarg); break; case 'p': if (strcasecmp(optarg, "core") == 0) profile = GLFW_OPENGL_CORE_PROFILE; else if (strcasecmp(optarg, "compat") == 0) profile = GLFW_OPENGL_COMPAT_PROFILE; else { usage(); exit(1); } break; default: usage(); exit(1); } } argc -= optind; argv += optind; if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(1); } if (major != 1 || minor != 1) { glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, minor); } if (debug) glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); if (forward) glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); if (profile != 0) glfwOpenWindowHint(GLFW_OPENGL_PROFILE, profile); // We assume here that we stand a better chance of success by leaving all // possible details of pixel format selection to GLFW if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) { glfwTerminate(); fprintf(stderr, "Failed to open GLFW window\n"); exit(1); } // Report GLFW version glfwGetVersion(&major, &minor, &revision); printf("GLFW header version: %u.%u.%u\n", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION); printf("GLFW library version: %u.%u.%u\n", major, minor, revision); if (major != GLFW_VERSION_MAJOR || minor != GLFW_VERSION_MINOR || revision != GLFW_VERSION_REVISION) printf("*** WARNING: GLFW version mismatch! ***\n"); // Report OpenGL version printf("OpenGL context version string: \"%s\"\n", glGetString(GL_VERSION)); glfwGetGLVersion(&major, &minor, &revision); printf("OpenGL context version parsed by GLFW: %u.%u.%u\n", major, minor, revision); // Report OpenGL context properties if (major >= 3) { glGetIntegerv(GL_CONTEXT_FLAGS, &flags); printf("OpenGL context flags:"); if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) puts(" forward-compatible"); else puts(" none"); } if (major > 3 || (major == 3 && minor >= 2)) { glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); printf("OpenGL profile mask: 0x%08x (%s)\n", mask, get_profile_name(mask)); } printf("OpenGL context renderer string: \"%s\"\n", glGetString(GL_RENDERER)); printf("OpenGL context vendor string: \"%s\"\n", glGetString(GL_VENDOR)); if (major > 1) { printf("OpenGL context shading language version: \"%s\"\n", glGetString(GL_SHADING_LANGUAGE_VERSION)); } // Report OpenGL extensions if (list) list_extensions(major, minor); glfwTerminate(); exit(0); }