mirror of
https://github.com/guilhermewerner/opengl
synced 2025-06-16 13:24:19 +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;
|
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 */
|
/* Loop until the user closes the window */
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
/* Render here */
|
/* Render here */
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glBegin(GL_TRIANGLES);
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
glVertex2f(-0.5f, -0.5f);
|
|
||||||
glVertex2f(0.0f, 0.5f);
|
|
||||||
glVertex2f(0.5f, -0.5f);
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
/* Swap front and back buffers */
|
/* Swap front and back buffers */
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
Reference in New Issue
Block a user