Ejemplo n.º 1
0
int main(void)
{
    GLFWwindow window;

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "English 日本語 русский язык 官話", NULL);
    if (!window)
    {
        fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    glfwSwapInterval(1);

    glfwSetWindowSizeCallback(window_size_callback);

    while (glfwIsWindow(window) == GL_TRUE)
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers();
        glfwWaitEvents();
    }

    exit(EXIT_SUCCESS);
}
Ejemplo n.º 2
0
int main(void)
{
    int i, result;
    Thread threads[] =
    {
        { NULL, "Red", 1.f, 0.f, 0.f, 0 },
        { NULL, "Green", 0.f, 1.f, 0.f, 0 },
        { NULL, "Blue", 0.f, 0.f, 1.f, 0 }
    };
    const int count = sizeof(threads) / sizeof(Thread);

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n",
                glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    for (i = 0;  i < count;  i++)
    {
        glfwWindowHint(GLFW_POSITION_X, 200 + 250 * i);
        glfwWindowHint(GLFW_POSITION_Y, 200);
        threads[i].window = glfwCreateWindow(200, 200,
                                             GLFW_WINDOWED,
                                             threads[i].title,
                                             NULL);
        if (!threads[i].window)
        {
            fprintf(stderr, "Failed to open GLFW window: %s\n",
                    glfwErrorString(glfwGetError()));
            exit(EXIT_FAILURE);
        }

        if (thrd_create(&threads[i].id, thread_main, threads + i) !=
            thrd_success)
        {
            fprintf(stderr, "Failed to create secondary thread\n");
            exit(EXIT_FAILURE);
        }
    }

    while (running)
    {
        assert(glfwGetCurrentContext() == NULL);

        glfwWaitEvents();

        for (i = 0;  i < count;  i++)
        {
            if (glfwGetWindowParam(threads[i].window, GLFW_CLOSE_REQUESTED))
                running = GL_FALSE;
        }
    }

    for (i = 0;  i < count;  i++)
        thrd_join(threads[i].id, &result);

    exit(EXIT_SUCCESS);
}
Ejemplo n.º 3
0
int main(void)
{
    GLFWwindow window;
    int width, height;

    setlocale(LC_ALL, "");

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    printf("Library initialized\n");

    glfwSetWindowSizeCallback(window_size_callback);
    glfwSetWindowCloseCallback(window_close_callback);
    glfwSetWindowRefreshCallback(window_refresh_callback);
    glfwSetWindowFocusCallback(window_focus_callback);
    glfwSetWindowIconifyCallback(window_iconify_callback);
    glfwSetMouseButtonCallback(mouse_button_callback);
    glfwSetCursorPosCallback(cursor_position_callback);
    glfwSetCursorEnterCallback(cursor_enter_callback);
    glfwSetScrollCallback(scroll_callback);
    glfwSetKeyCallback(key_callback);
    glfwSetCharCallback(char_callback);

    window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Event Linter", NULL);
    if (!window)
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    printf("Window opened\n");

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glfwGetWindowSize(window, &width, &height);
    printf("Window size should be %ix%i\n", width, height);

    printf("Key repeat should be %s\n", keyrepeat ? "enabled" : "disabled");
    printf("System keys should be %s\n", systemkeys ? "enabled" : "disabled");

    printf("Main loop starting\n");

    while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
        glfwWaitEvents();

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Ejemplo n.º 4
0
int main(void)
{
    GLFWwindow window;
    int width, height;

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    window = glfwCreateWindow(window_width, window_height, GLFW_WINDOWED, "", NULL);
    if (!window)
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    glfwSetCursorPosCallback(window, cursor_position_callback);
    glfwSetWindowSizeCallback(window, window_size_callback);
    glfwSetKeyCallback(window, key_callback);

    glfwMakeContextCurrent(window);

    glfwGetWindowSize(window, &width, &height);
    window_size_callback(window, width, height);

    set_swap_interval(window, swap_interval);

    while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
    {
        glClear(GL_COLOR_BUFFER_BIT);

        glBegin(GL_LINES);
        glVertex2f(0.f, (GLfloat) window_height - cursor_y);
        glVertex2f((GLfloat) window_width, (GLfloat) window_height - cursor_y);
        glVertex2f((GLfloat) cursor_x, 0.f);
        glVertex2f((GLfloat) cursor_x, (GLfloat) window_height);
        glEnd();

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Ejemplo n.º 5
0
static GLboolean open_window(int width, int height, int mode)
{
    double base;

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        return GL_FALSE;
    }

    base = glfwGetTime();

    window_handle = glfwCreateWindow(width, height, mode, "Window Re-opener", NULL);
    if (!window_handle)
    {
        fprintf(stderr, "Failed to open %s mode GLFW window: %s\n", get_mode_name(mode), glfwErrorString(glfwGetError()));
        return GL_FALSE;
    }

    glfwMakeContextCurrent(window_handle);
    glfwSwapInterval(1);

    glfwSetWindowSizeCallback(window_handle, window_size_callback);
    glfwSetWindowCloseCallback(window_handle, window_close_callback);
    glfwSetKeyCallback(window_handle, key_callback);

    printf("Opening %s mode window took %0.3f seconds\n",
           get_mode_name(mode),
           glfwGetTime() - base);

    return GL_TRUE;
}
Ejemplo n.º 6
0
int main(void)
{
    GLFWwindow window;

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    window = glfwOpenWindow(window_width, window_height, GLFW_WINDOWED, "Cursor Inaccuracy Detector", NULL);
    if (!window)
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    glfwSetCursorPosCallback(cursor_position_callback);
    glfwSetWindowSizeCallback(window_size_callback);
    glfwSwapInterval(1);

    while (glfwIsWindow(window))
    {
        glClear(GL_COLOR_BUFFER_BIT);

        glBegin(GL_LINES);
        glVertex2f(0.f, (GLfloat) window_height - cursor_y);
        glVertex2f((GLfloat) window_width, (GLfloat) window_height - cursor_y);
        glVertex2f((GLfloat) cursor_x, 0.f);
        glVertex2f((GLfloat) cursor_x, (GLfloat) window_height);
        glEnd();

        glfwSwapBuffers();
        glfwPollEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Ejemplo n.º 7
0
int main(void)
{
    GLFWwindow window;

    memset(joysticks, 0, sizeof(joysticks));

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    window = glfwCreateWindow(640, 480, GLFW_WINDOWED, "Joystick Test", NULL);
    if (!window)
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    glfwSetWindowSizeCallback(window, window_size_callback);

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
    {
        glClear(GL_COLOR_BUFFER_BIT);

        refresh_joysticks();
        draw_joysticks(window);

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Ejemplo n.º 8
0
int main(void)
{
    double start;
    double t;
    double update;

    /* Initialise GLFW */
    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    printf("The program will work for 20 seconds and display every seconds the state of the joysticks\n");
    printf("Your computer is going to be very slow as the program is doing an active loop .....\n");

    start = glfwGetTime();
    update = start;

    /* print the initial state of all joysticks */
    updateJoysticksState();
    printf("\n");
    displayJoysticksState();

    running = GL_TRUE;

    /* Main loop */
    while (running)
    {
        /* Get time */
        t = glfwGetTime();

        /* Display the state of all connected joysticks every secons */
        if ((t - update) > 1.0)
        {
            update = t;
            printf("\n");
            updateJoysticksState();
            printf("\n");
            displayJoysticksState();
        }

        /* Check if the window was closed */
        if ((t - start) > 20.0)
            running = GL_FALSE;
    }

    /* Close OpenGL window and terminate GLFW */
    glfwTerminate();

    return 0;
}
Ejemplo n.º 9
0
int main(void)
{
    GLFWwindow window;

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    window = glfwCreateWindow(640, 480, GLFW_FULLSCREEN, "Fullscreen focus", NULL);
    if (!window)
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);

    glfwSetWindowFocusCallback(window_focus_callback);
    glfwSetKeyCallback(window_key_callback);
    glfwSetWindowCloseCallback(window_close_callback);

    while (running)
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers(window);
        glfwWaitEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Ejemplo n.º 10
0
    bool        Window::Create     ( )
    {
        assert( s_instance == nullptr );
        s_instance = new Window();

        s32 error;
        
        //
        // Initialise GLFW
        //
        
        glfwInit( );
        error = glfwGetError( );
        if ( error != GLFW_NO_ERROR )
        {
            std::cerr << "GLFW initialization failed: " << glfwErrorString( error ) << std::endl;
            Destroy(); 
            return false;
        }

         glfwOpenWindowHint( GLFW_DEPTH_BITS, 32 );

         glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 );
         glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 2 );
         glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
        
        s_instance->m_window = glfwOpenWindow( INIT_WIDTH, INIT_HEIGHT, GLFW_WINDOWED, INIT_WINDOW_TITLE, nullptr );
        if ( !s_instance->m_window )
        {
            std::cerr << "GLFW window creation failed: " << glfwErrorString( error ) << std::endl;
            Destroy(); 
            return false;
        }
        
        glfwGetWindowSize( s_instance->m_window, &s_instance->m_width, &s_instance->m_height );

        glfwEnable( s_instance->m_window, GLFW_STICKY_KEYS );
        glEnable( GL_TEXTURE_2D );
        glDisable( GL_DEPTH_TEST );
        
        glfwSwapInterval( 1 );

        return true;
    }
Ejemplo n.º 11
0
int main(int argc, char** argv)
{
    int ch, profile = 0, strategy = 0, major = 1, minor = 0, revision;
    GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE;
    GLint flags, mask;
    GLFWwindow window;

    while ((ch = getopt(argc, argv, "dfhlm:n:p:r:")) != -1)
    {
        switch (ch)
        {
            case 'd':
                debug = GL_TRUE;
                break;
            case 'f':
                forward = GL_TRUE;
                break;
            case 'h':
                usage();
                exit(EXIT_SUCCESS);
            case 'l':
                list = GL_TRUE;
                break;
            case 'm':
                major = atoi(optarg);
                break;
            case 'n':
                minor = atoi(optarg);
                break;
            case 'p':
                if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0)
                    profile = GLFW_OPENGL_CORE_PROFILE;
                else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0)
                    profile = GLFW_OPENGL_COMPAT_PROFILE;
                else if (strcasecmp(optarg, PROFILE_NAME_ES2) == 0)
                    profile = GLFW_OPENGL_ES2_PROFILE;
                else
                {
                    usage();
                    exit(EXIT_FAILURE);
                }
                break;
            case 'r':
                if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0)
                    strategy = GLFW_OPENGL_NO_RESET_NOTIFICATION;
                else if (strcasecmp(optarg, STRATEGY_NAME_LOSE) == 0)
                    strategy = GLFW_OPENGL_LOSE_CONTEXT_ON_RESET;
                else
                {
                    usage();
                    exit(EXIT_FAILURE);
                }
                break;
            default:
                usage();
                exit(EXIT_FAILURE);
        }
    }

    argc -= optind;
    argv += optind;

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    if (major != 1 || minor != 0)
    {
        glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
        glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, minor);
    }

    if (debug)
        glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);

    if (forward)
        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    if (profile != 0)
        glfwWindowHint(GLFW_OPENGL_PROFILE, profile);

    if (strategy)
        glfwWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy);

    // We assume here that we stand a better chance of success by leaving all
    // possible details of pixel format selection to GLFW

    window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Version", NULL);
    if (!window)
        exit(EXIT_FAILURE);

    glfwMakeContextCurrent(window);

    // 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");
    }

    printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());

    // Report OpenGL version

    printf("OpenGL context version string: \"%s\"\n", glGetString(GL_VERSION));

    major = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MAJOR);
    minor = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MINOR);
    revision = glfwGetWindowParam(window, GLFW_OPENGL_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 (0x%08x):", flags);

        if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
            printf(" forward-compatible");
        if (flags & 0)
            printf(" debug");
        putchar('\n');

        printf("OpenGL context flags parsed by GLFW:");

        if (glfwGetWindowParam(window, GLFW_OPENGL_FORWARD_COMPAT))
            printf(" forward-compatible");
        if (glfwGetWindowParam(window, GLFW_OPENGL_DEBUG_CONTEXT))
            printf(" debug");
        putchar('\n');
    }

    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 profile mask parsed by GLFW: %s\n",
               get_glfw_profile_name(glfwGetWindowParam(window, GLFW_OPENGL_PROFILE)));
    }

    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(EXIT_SUCCESS);
}
Ejemplo n.º 12
0
Archivo: main.cpp Proyecto: roxlu/jadi
// APPLICATION ENTRY
// -----------------
int main() {
  int width = 1024;
  int height = 768;
  demo_ptr = NULL;
  is_running = true;

  //// init
  glfwSetErrorCallback(error_callback);
  if(!glfwInit()) {
    fprintf(stderr, "GLFW Error: %d\n", glfwGetError());
    exit(EXIT_FAILURE);
  }

  glfwWindowHint(GLFW_DEPTH_BITS, 16);
  glfwWindowHint(GLFW_FSAA_SAMPLES, 4);

  //#if JADI_PLATFORM != JADI_OSX
  // doesn't work if we specify 3.2 - errors on line 78 of DepthOfField.cpp (GL_INVALID_ENUM)
  //glfwWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 );
  //glfwWindowHint( GLFW_OPENGL_VERSION_MINOR, 2 );
  //glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
  //#endif

  GLFWwindow window = glfwCreateWindow(width, height, GLFW_WINDOWED, "Simulation", NULL);
  if(!window) {
    printf("ERROR: cannot open window.\n");
    exit(EXIT_FAILURE);
  }
  
  glfwSetWindowSizeCallback(window, window_size_callback);
  glfwSetWindowCloseCallback(window, window_close_callback);
  glfwSetMouseButtonCallback(window, mouse_button_callback);
  glfwSetCursorPosCallback(window, cursor_callback);
  glfwSetScrollCallback(window, scroll_callback);
  glfwSetKeyCallback(window, key_callback);
  glfwSetCharCallback(window, char_callback);

  glfwMakeContextCurrent(window);

  #if JADI_PLATFORM==JADI_OSX
    glewExperimental = true;
  #endif

  GLenum err = glewInit();
  if (GLEW_OK != err) {
	  fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
	  exit(EXIT_FAILURE);
  }


  Demo demo;
  demo.mouse_x = demo.mouse_y = demo.prev_mouse_x = demo.prev_mouse_y = 0;
  demo.pressed_mouse_button = 0;
  demo.is_mouse_down = false;
  demo_ptr = &demo;
  demo.window = &window;
  demo.setup();
  
  while(is_running) {
    glfwPollEvents();

    demo.update();
    demo.draw();

    glfwSwapBuffers(window);
  }

  demo_ptr->onWindowClose();

  glfwTerminate();
  exit(EXIT_SUCCESS);
};
Ejemplo n.º 13
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);
        }
    }

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    if (mode == GLFW_FULLSCREEN)
    {
        GLFWvidmode mode;
        glfwGetDesktopMode(&mode);
        width = mode.width;
        height = mode.height;
    }
    else
    {
        width = 0;
        height = 0;
    }

    window = glfwCreateWindow(width, height, mode, "Gamma Test", NULL);
    if (!window)
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    set_gamma(1.f);

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glfwSetKeyCallback(key_callback);
    glfwSetWindowSizeCallback(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 (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
    {
        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);
}
Ejemplo n.º 14
0
int main(int argc, char** argv)
{
    int width, height, ch;
    int mode = GLFW_WINDOWED;
    GLboolean active = -1, iconified = -1;
    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);
        }
    }

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    if (mode == GLFW_FULLSCREEN)
    {
        GLFWvidmode mode;
        glfwGetDesktopMode(&mode);
        width = mode.width;
        height = mode.height;
    }
    else
    {
        width = 0;
        height = 0;
    }

    window = glfwOpenWindow(width, height, mode, "Iconify", NULL);
    if (!window)
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    glfwSwapInterval(1);
    glfwSetKeyCallback(key_callback);
    glfwSetWindowSizeCallback(size_callback);

    glEnable(GL_SCISSOR_TEST);

    while (glfwIsWindow(window))
    {
        int width, height;

        if (iconified != glfwGetWindowParam(window, GLFW_ICONIFIED) ||
                active != glfwGetWindowParam(window, GLFW_ACTIVE))
        {
            iconified = glfwGetWindowParam(window, GLFW_ICONIFIED);
            active = glfwGetWindowParam(window, GLFW_ACTIVE);

            printf("%0.2f %s %s\n",
                   glfwGetTime(),
                   iconified ? "Iconified" : "Restored",
                   active ? "Active" : "Inactive");
        }

        glfwGetWindowSize(window, &width, &height);

        glScissor(0, 0, width, height);
        glClearColor(0, 0, 0, 0);
        glClear(GL_COLOR_BUFFER_BIT);

        glScissor(0, 0, 640, 480);
        glClearColor(1, 1, 1, 0);
        glClear(GL_COLOR_BUFFER_BIT);

        glfwSwapBuffers();
        glfwPollEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Ejemplo n.º 15
0
Archivo: fsaa.c Proyecto: eledot/Plum
int main(int argc, char** argv)
{
    int ch, samples = 4;
    GLFWwindow window;

    while ((ch = getopt(argc, argv, "hs:")) != -1)
    {
        switch (ch)
        {
            case 'h':
                usage();
                exit(EXIT_SUCCESS);
            case 's':
                samples = atoi(optarg);
                break;
            default:
                usage();
                exit(EXIT_FAILURE);
        }
    }

    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    if (samples)
        printf("Requesting FSAA with %i samples\n", samples);
    else
        printf("Requesting that FSAA not be available\n");

    glfwWindowHint(GLFW_FSAA_SAMPLES, samples);

    window = glfwCreateWindow(800, 400, GLFW_WINDOWED, "Aliasing Detector", NULL);
    if (!window)
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
        exit(EXIT_FAILURE);
    }

    glfwSetKeyCallback(window, key_callback);
    glfwSetWindowSizeCallback(window, window_size_callback);

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    if (!glfwExtensionSupported("GL_ARB_multisample"))
    {
        glfwTerminate();

        fprintf(stderr, "Context reports GL_ARB_multisample is not supported\n");
        exit(EXIT_FAILURE);
    }

    glGetIntegerv(GL_SAMPLES_ARB, &samples);
    if (samples)
        printf("Context reports FSAA is available with %i samples\n", samples);
    else
        printf("Context reports FSAA is unavailable\n");

    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0.f, 1.f, 0.f, 0.5f);
    glMatrixMode(GL_MODELVIEW);

    while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
    {
        GLfloat time = (GLfloat) glfwGetTime();

        glClear(GL_COLOR_BUFFER_BIT);

        glLoadIdentity();
        glTranslatef(0.25f, 0.25f, 0.f);
        glRotatef(time, 0.f, 0.f, 1.f);

        glDisable(GL_MULTISAMPLE_ARB);
        glRectf(-0.15f, -0.15f, 0.15f, 0.15f);

        glLoadIdentity();
        glTranslatef(0.75f, 0.25f, 0.f);
        glRotatef(time, 0.f, 0.f, 1.f);

        glEnable(GL_MULTISAMPLE_ARB);
        glRectf(-0.15f, -0.15f, 0.15f, 0.15f);

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}