mirror of
https://github.com/guilhermewerner/opengl
synced 2025-06-15 13:04:17 +00:00
Draw Triangle with Modern OpenGL
This commit is contained in:
@ -29,17 +29,27 @@ int main()
|
||||
|
||||
std::cout << glGetString(GL_VERSION) << std::endl;
|
||||
|
||||
float positions[6] = {
|
||||
-0.5f, -0.5f,
|
||||
0.0f, 0.5f,
|
||||
0.5f, -0.5f
|
||||
};
|
||||
|
||||
unsigned int buffer;
|
||||
glGenBuffers(1, &buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float), positions, GL_STATIC_DRAW);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
|
||||
|
||||
/* Loop until the user closes the window */
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
/* Render here */
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
glVertex2f(-0.5f, -0.5f);
|
||||
glVertex2f(0.0f, 0.5f);
|
||||
glVertex2f(0.5f, -0.5f);
|
||||
glEnd();
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
/* Swap front and back buffers */
|
||||
glfwSwapBuffers(window);
|
||||
|
Reference in New Issue
Block a user