openGL/GLFW简单demo程序

ubuntu 安装 GLFW :

sudo apt-get install libglfw3*

test-glfw.c

#include 

int main(void)
{
    GLFWwindow* window;
    GLFWwindow* window2;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(480, 320, "Hello World", NULL, NULL);
    window2 = glfwCreateWindow(480, 320, "Hello World2", NULL, NULL);
    if (!window || !window2)
    {
        glfwTerminate();
        return -1;
    }

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
		{
		    glfwMakeContextCurrent(window);
		    /* Draw a triangle */
		    glBegin(GL_TRIANGLES);

		    glColor3f(1.0, 0.0, 0.0);    // Red
		    glVertex3f(0.0, 1.0, 0.0);

		    glColor3f(0.0, 1.0, 0.0);    // Green
		    glVertex3f(-1.0, -1.0, 0.0);

		    glColor3f(0.0, 0.0, 1.0);    // Blue
		    glVertex3f(1.0, -1.0, 0.0);

		    glEnd();
		}
		{
		    glfwMakeContextCurrent(window2);
		    /* Draw a triangle */
		    glBegin(GL_TRIANGLES);

		    glColor3f(1.0, 0.0, 0.0);    // Red
		    glVertex3f(0.0, -1.0, 0.0);

		    glColor3f(0.0, 1.0, 0.0);    // Green
		    glVertex3f(-1.0, 1.0, 0.0);

		    glColor3f(0.0, 0.0, 1.0);    // Blue
		    glVertex3f(1.0, 1.0, 0.0);

		    glEnd();
		}

        /* Swap front and back buffers */
        glfwSwapBuffers(window);
        glfwSwapBuffers(window2);

        /* Poll for and process events */
        //glfwPollEvents();
        glfwWaitEvents();
    }

    glfwTerminate();
    return 0;
}

编译命令:

gcc  test-glfw.c -lOpenGL -lglfw -o testGLFW

你可能感兴趣的:(Linux,openGL)