0% found this document useful (0 votes)
11 views

Float: / Loop Until The User Closes The Window

This code defines vertex position and index data for two triangles. It generates and binds a buffer, enables and sets vertex attributes. It parses and compiles a shader program. The main loop clears the screen and draws the triangles with glDrawArrays before swapping buffers and polling events. Upon completion it deletes the program and terminates GLFW.

Uploaded by

iDenis
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Float: / Loop Until The User Closes The Window

This code defines vertex position and index data for two triangles. It generates and binds a buffer, enables and sets vertex attributes. It parses and compiles a shader program. The main loop clears the screen and draws the triangles with glDrawArrays before swapping buffers and polling events. Upon completion it deletes the program and terminates GLFW.

Uploaded by

iDenis
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

float positions[] = {

0.0f, 0.5f,
-0.5f, -0.5f,
0.5f, -0.5f
};

unsigned int indices[] = {


0, 1, 3,
1, 2, 3
};

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, 2 * sizeof(float), 0);

ShaderProgramSource source = ParseShader("res/shaders/Basic.shader");


std::cout << source.VertexSource << std::endl;
std::cout << source.FragmentSource << std::endl;

unsigned int shader = CreateShader(source.VertexSource, source.FragmentSource);


glUseProgram(shader);

/* Loop until the user closes the window */


while (!glfwWindowShouldClose(window))
{
/* Render here */
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
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);

/* Poll for and process events */


glfwPollEvents();
}

glDeleteProgram(shader);

glfwTerminate();
return 0;
}

You might also like