Building an OpenGL application using C++ and XCode
I compiled a minimal OpenGL on my M1 MacBook Air.
I used GLFW (a cross platform library for OpenGL).
Overview
I used GLFW to create an application window with a given width and height and the title "Hello World". In a loop, the SwapBuffers function is called until the window is closed.
main.cpp
C++
1#include <GLFW/glfw3.h> 2 3int main(void) 4{ 5 GLFWwindow* window; 6 7 /* Initialize the library */ 8 if (!glfwInit()) 9 return -1; 10 11 /* Create a windowed mode window and its OpenGL context */ 12 window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); 13 if (!window) 14 { 15 glfwTerminate(); 16 return -1; 17 } 18 19 /* Make the window's context current */ 20 glfwMakeContextCurrent(window); 21 22 /* Loop until the user closes the window */ 23 while (!glfwWindowShouldClose(window)) 24 { 25 /* Render here */ 26 glClear(GL_COLOR_BUFFER_BIT); 27 28 /* Swap front and back buffers */ 29 glfwSwapBuffers(window); 30 31 /* Poll for and process events */ 32 glfwPollEvents(); 33 } 34 35 glfwTerminate(); 36 return 0; 37}


















