Created vertex buffer

This commit is contained in:
Tom
2021-05-31 13:07:53 +02:00
parent 67acb61b2c
commit cac26262b4
7 changed files with 19 additions and 8 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -3,14 +3,15 @@
#include <iostream> #include <iostream>
int main(void){ int main(void){
GLFWwindow* window; // GLFW init
// Library inits
if (!glfwInit()) { if (!glfwInit()) {
std::cout << "GLFW could not be initialized!" << std::endl; std::cout << "GLFW could not be initialized!" << std::endl;
return -1; return -1;
} }
//Main window
GLFWwindow* window;
//Window creation //Window creation
window = glfwCreateWindow(640, 480, "OpenGl practice", NULL, NULL); window = glfwCreateWindow(640, 480, "OpenGl practice", NULL, NULL);
if (!window){ if (!window){
@@ -21,6 +22,7 @@ int main(void){
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
//GLEW init
if (glewInit() != GLEW_OK) { if (glewInit() != GLEW_OK) {
std::cout << "GLEW Error" << std::endl; std::cout << "GLEW Error" << std::endl;
return -1; return -1;
@@ -28,16 +30,25 @@ int main(void){
std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
//vertex positions
float positions[6] = {
-0.5f, -0.5f, //Vertex2f
0.0f, 0.5f, //Vertex2f
0.5f, -0.5f //Vertex2f
};
//Vertex buffer(s)
unsigned int buffer;
glGenBuffers(1, &buffer); //number of buffer to generate
glBindBuffer(GL_ARRAY_BUFFER, buffer); //binding the buffer
glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float), positions, GL_STATIC_DRAW);
//Main loop //Main loop
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); //without index buffer
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);