How to create an OpenGL 3.3 context in GLFW 3

I wrote a simple OpenGL 3.3 program that should display a triangle based on this tutorial , except that I use GLFW to create a window and context instead of doing it from scratch. In addition, I use Ubuntu.

The triangle does not display, I just get a black screen. Functions like glClearColor() and glClear() seem to work just as they should, but the code for displaying the triangle does not work. Here are their respective bits:

 #define GLFW_INCLUDE_GL_3 #include <GL/glew.h> #include <GLFW/glfw3.h> int main () { glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); GLFWwindow* window = glfwCreateWindow(800, 600, "GLFW test", NULL, NULL); glfwMakeContextCurrent(window); glewExperimental = GL_TRUE; glewInit(); float vertices[] = {-0.5f, -0.5f, 0.0f, 0.5f, 0.5f, -0.5f}; GLuint VBOid[1]; glClear(GL_COLOR_BUFFER_BIT); glGenBuffers(1, VBOid); glBindBuffer(GL_ARRAY_BUFFER, VBOid[0]); glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float), vertices, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, VBOid[0]); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glDrawArrays(GL_TRIANGLES, 0, 3); ... } 

What am I missing?

+4
source share
1 answer

In the main OpenGL 3.3 profile, you need a shader for rendering. Therefore, you need to compile and link a program containing vertex and fragment shaders.

+8
source

Source: https://habr.com/ru/post/1495836/


All Articles