/* OpenGL IS A very strict language for talking to the GPU: A state machine, A GPU command API, A way to feed data + programs to the GPU OpenGL expects: 1.You describe data -> “Here are vertices” 2.You describe how to process it -> “Here is how to transform them” 3.GPU does the rest -> “Here is how to color pixels” Nothing happens unless everything is provided. OpenGL = Set state -> Issue command */ // the art of adapt #include #include #include /* 1. Describe data -> vertices (VBO) 2. Describe processing -> shaders 3. GPU does the rest -> rasterization + fragment coloring */ int main(void) { GLFWwindow* window; /* Initialize the library */ if (!glfwInit()) return -1; /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); if (!window) { glfwTerminate(); return -1; } /* Make the window's context current */ glfwMakeContextCurrent(window); // -------------------- STEP 1: DESCRIBE DATA -------------------- float vertices[] = { -0.5f, -0.5f, 0.0f, // left 0.5f, -0.5f, 0.0f, // right 0.0f, 0.5f, 0.0f // top }; unsigned int VBO = 0; glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); /* Loop until the user closes the window */ while (!glfwWindowShouldClose(window)) { /* Render here */ glClear(GL_COLOR_BUFFER_BIT); /* Swap front and back buffers */ glfwSwapBuffers(window); /* Poll for and process events */ glfwPollEvents(); } glfwTerminate(); return 0; }