Created vertex buffer
This commit is contained in:
@@ -3,14 +3,15 @@
|
||||
#include <iostream>
|
||||
|
||||
int main(void){
|
||||
GLFWwindow* window;
|
||||
|
||||
// Library inits
|
||||
// GLFW init
|
||||
if (!glfwInit()) {
|
||||
std::cout << "GLFW could not be initialized!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Main window
|
||||
GLFWwindow* window;
|
||||
|
||||
//Window creation
|
||||
window = glfwCreateWindow(640, 480, "OpenGl practice", NULL, NULL);
|
||||
if (!window){
|
||||
@@ -21,6 +22,7 @@ int main(void){
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
//GLEW init
|
||||
if (glewInit() != GLEW_OK) {
|
||||
std::cout << "GLEW Error" << std::endl;
|
||||
return -1;
|
||||
@@ -28,16 +30,25 @@ int main(void){
|
||||
|
||||
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
|
||||
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); //without index buffer
|
||||
|
||||
/* Swap front and back buffers */
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
Reference in New Issue
Block a user