Ejemplo n.º 1
0
int main(int argc, char** argv)
{
    int ch;
    GLFWwindow window;

    while ((ch = getopt(argc, argv, "h")) != -1)
    {
        switch (ch)
        {
            case 'h':
                usage();
                exit(EXIT_SUCCESS);

            default:
                usage();
                exit(EXIT_FAILURE);
        }
    }

    glfwSetErrorCallback(error_callback);

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

    window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Clipboard Test", NULL);
    if (!window)
    {
        glfwTerminate();

        fprintf(stderr, "Failed to open GLFW window\n");
        exit(EXIT_FAILURE);
    }

    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 (glfwIsWindow(window))
    {
        glClear(GL_COLOR_BUFFER_BIT);

        glColor3f(0.8f, 0.2f, 0.4f);
        glRectf(-0.5f, -0.5f, 0.5f, 0.5f);

        glfwSwapBuffers();
        glfwWaitEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Ejemplo n.º 2
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.º 3
0
Archivo: boing.c Proyecto: BSVino/glfw
int main( void )
{
   int running;
   GLFWwindow window;

   /* Init GLFW */
   if( !glfwInit() )
   {
      fprintf( stderr, "Failed to initialize GLFW\n" );
      exit( EXIT_FAILURE );
   }

   glfwOpenWindowHint(GLFW_DEPTH_BITS, 16);

   window = glfwOpenWindow( 400, 400, GLFW_WINDOWED, "Boing (classic Amiga demo)", NULL );
   if (!window)
   {
       fprintf( stderr, "Failed to open GLFW window\n" );
       glfwTerminate();
       exit( EXIT_FAILURE );
   }

   glfwSetWindowSizeCallback( reshape );
   glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
   glfwSwapInterval( 1 );
   glfwSetTime( 0.0 );

   init();

   /* Main loop */
   do
   {
       /* Timing */
       t = glfwGetTime();
       dt = t - t_old;
       t_old = t;

       /* Draw one frame */
       display();

       /* Swap buffers */
       glfwSwapBuffers();
       glfwPollEvents();

       /* Check if we are still running */
       running = glfwIsWindow(window) && !glfwGetKey( window, GLFW_KEY_ESCAPE );
   }
   while( running );

   glfwTerminate();
   exit( EXIT_SUCCESS );
}
Ejemplo n.º 4
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.º 5
0
int main(int argc, char* argv[])
{
    GLFWwindow window;
    double t, dt_total, t_old;

    if (!glfwInit())
    {
        fprintf(stderr, "GLFW initialization failed\n");
        exit(EXIT_FAILURE);
    }

    window = glfwOpenWindow(640, 480, GLFW_WINDOWED, "Wave Simulation", NULL);
    if (!window)
    {
        fprintf(stderr, "Could not open window\n");
        exit(EXIT_FAILURE);
    }

    glfwSwapInterval(1);

    // Keyboard handler
    glfwSetKeyCallback(key_callback);
    glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);

    // Window resize handler
    glfwSetWindowSizeCallback(window_resize_callback);
    glfwSetMouseButtonCallback(mouse_button_callback);
    glfwSetMousePosCallback(mouse_position_callback);
    glfwSetScrollCallback(scroll_callback);

    // Initialize OpenGL
    init_opengl();

    // Initialize simulation
    init_vertices();
    init_grid();
    adjust_grid();

    // Initialize timer
    t_old = glfwGetTime() - 0.01;

    while (running)
    {
        t = glfwGetTime();
        dt_total = t - t_old;
        t_old = t;

        // Safety - iterate if dt_total is too large
        while (dt_total > 0.f)
        {
            // Select iteration time step
            dt = dt_total > MAX_DELTA_T ? MAX_DELTA_T : dt_total;
            dt_total -= dt;

            // Calculate wave propagation
            calc_grid();
        }

        // Compute height of each vertex
        adjust_grid();

        // Draw wave grid to OpenGL display
        draw_scene();

        glfwPollEvents();

        // Still running?
        running = running && glfwIsWindow(window);
    }

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

    // Initialise GLFW
    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW\n");
        exit(EXIT_FAILURE);
    }

    // Open a window and create its OpenGL context
    window = glfwOpenWindow(640, 480, GLFW_WINDOWED, "Spinning Triangle", NULL);
    if (!window)
    {
        fprintf(stderr, "Failed to open GLFW window\n");
        exit(EXIT_FAILURE);
    }

    // Ensure we can capture the escape key being pressed below
    glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

    // Enable vertical sync (on cards that support it)
    glfwSwapInterval(1);

    do
    {
        double t = glfwGetTime();
        glfwGetMousePos(window, &x, NULL);

        // Get window size (may be different than the requested size)
        glfwGetWindowSize(window, &width, &height);

        // Special case: avoid division by zero below
        height = height > 0 ? height : 1;

        glViewport(0, 0, width, height);

        // Clear color buffer to black
        glClearColor(0.f, 0.f, 0.f, 0.f);
        glClear(GL_COLOR_BUFFER_BIT);

        // Select and setup the projection matrix
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(65.f, (GLfloat) width / (GLfloat) height, 1.f, 100.f);

        // Select and setup the modelview matrix
        glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();
        gluLookAt(0.f, 1.f, 0.f,    // Eye-position
                  0.f, 20.f, 0.f,   // View-point
                  0.f, 0.f, 1.f);   // Up-vector

        // Draw a rotating colorful triangle
        glTranslatef(0.f, 14.f, 0.f);
        glRotatef(0.3f * (GLfloat) x + (GLfloat) t * 100.f, 0.f, 0.f, 1.f);

        glBegin(GL_TRIANGLES);
        glColor3f(1.f, 0.f, 0.f);
        glVertex3f(-5.f, 0.f, -4.f);
        glColor3f(0.f, 1.f, 0.f);
        glVertex3f(5.f, 0.f, -4.f);
        glColor3f(0.f, 0.f, 1.f);
        glVertex3f(0.f, 0.f, 6.f);
        glEnd();

        // Swap buffers
        glfwSwapBuffers();
        glfwPollEvents();

    } // Check if the ESC key was pressed or the window was closed
    while (glfwIsWindow(window) &&
           glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS);

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

    exit(EXIT_SUCCESS);
}
Ejemplo n.º 7
0
bool CApplication::IsOpen()
{
	return !!glfwIsWindow((GLFWwindow)m_pWindow) && m_bIsOpen;
}
Ejemplo n.º 8
0
 bool Window::IsWindowClosed() const
 {
     return ( !glfwIsWindow( m_window ) ||
             glfwGetKey( m_window, GLFW_KEY_ESCAPE ) == GLFW_PRESS ||
             glfwGetKey( m_window, 'Q' )             == GLFW_PRESS );
 }
Ejemplo n.º 9
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);
}