-
Notifications
You must be signed in to change notification settings - Fork 5
PEN_2_2
#define numVAOs 1: Defines the number of Vertex Array Objects (VAOs) to be used in the program. In this case, only one is used.
GLuint renderingProgram; Global variable to store the ID of the shader program that will be used for rendering.
GLuint vao[numVAOs]; Array to store the IDs of the VAOs. In this case, the array has a single element, corresponding to the number of VAOs defined.
GLuint glCreateShaderProgram() { ... } This function creates a shader program in OpenGL.
-
const char *vshaderSource = "...";Contains the source code for the vertex shader. In this case, the shader simply assigns a fixed position to all vertices. -
const char *fshaderSource = "...";Contains the source code for the fragment shader. Here, the shader assigns a blue color to all fragments. -
GLuint vShader = glCreateShader(GL_VERTEX_SHADER);Creates a shader object for the vertex shader. -
GLuint fShader = glCreateShader(GL_FRAGMENT_SHADER);Creates a shader object for the fragment shader. -
glShaderSource(vShader, 1, &vshaderSource, NULL);Attaches the vertex shader source code to the shader object. -
glShaderSource(fShader, 1, &fshaderSource, NULL);Attaches the fragment shader source code to the shader object. -
glCompileShader(vShader);Compiles the vertex shader. -
glCompileShader(fShader);Compiles the fragment shader. -
GLint vfProgram = glCreateProgram();Creates a shader program. -
glAttachShader(vfProgram, vShader);Attaches the vertex shader to the shader program. -
glAttachShader(vfProgram, fShader);Attaches the fragment shader to the shader program. -
glLinkProgram(vfProgram);Links the shader program, combining the shaders into a single executable program. -
return vfProgram;Returns the ID of the created shader program.
void init(GLFWwindow *window) { ... } This function handles the initialization of the program.
-
renderingProgram = glCreateShaderProgram();Calls the glCreateShaderProgram function to create a shader program and stores the ID in the renderingProgram variable. -
glGenVertexArrays(numVAOs, vao);Generates the VAOs specified by numVAOs and stores their IDs in the vao array. -
glBindVertexArray(vao[0]);Binds the first VAO from the array to the OpenGL state machine.
void displaw(GLFWwindow* window, double currentTime) { ... } This function handles rendering the scene.
-
glUseProgram(renderingProgram);Activates the shader program for rendering. -
glPointSize(50.0f);Sets the size of the point to be drawn. -
glDrawArrays(GL_POINTS, 0, 1);Draws a point using the data from the current VAO.
glfwSwapInterval(1); Enables vertical synchronization (V-Sync), which limits the window's update rate to the monitor's refresh rate. This helps to avoid screen tearing.
while (!glfwWindowShouldClose(window)) { ... } Loop that runs until the window is closed.
-
displaw(window, glfwGetTime());Calls the displaw function to render the scene. -
glfwSwapBuffers(window);Swaps the window's buffers, showing the updated content.