Files
OpenGL_practice/Window_practice/src/Main.cpp

66 lines
1.6 KiB
C++
Raw Normal View History

2021-05-30 18:46:27 +02:00
#include <GL/glew.h>
2021-05-30 18:08:20 +02:00
#include <GLFW/glfw3.h>
#include <iostream>
int main(void){
2021-05-31 13:07:53 +02:00
// GLFW init
2021-05-30 18:08:20 +02:00
if (!glfwInit()) {
std::cout << "GLFW could not be initialized!" << std::endl;
return -1;
}
2021-05-31 14:18:46 +02:00
//Main window creation
2021-05-31 13:07:53 +02:00
GLFWwindow* window;
2021-05-30 18:08:20 +02:00
window = glfwCreateWindow(640, 480, "OpenGl practice", NULL, NULL);
if (!window){
std::cout << "Window could not be created!" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
2021-05-31 13:07:53 +02:00
//GLEW init
2021-05-30 18:46:27 +02:00
if (glewInit() != GLEW_OK) {
std::cout << "GLEW Error" << std::endl;
return -1;
}
std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
2021-05-31 13:07:53 +02:00
//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);
2021-05-31 14:18:46 +02:00
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0); //unbinding the buffer
2021-05-30 18:08:20 +02:00
//Main loop
while (!glfwWindowShouldClose(window)){
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
2021-05-31 13:07:53 +02:00
glDrawArrays(GL_TRIANGLES, 0, 3); //without index buffer
2021-05-30 18:08:20 +02:00
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}