0
votes

Is it possible to draw in OpenGL 4+ just using glVertexAttrib3f calls? The following works in legacy OpenGL mode but when I switch to OpenGL 4 nothing gets rendered.

glBegin(GL_TRIANGLES);
glVertexAttrib3f(1,  0, 0, -1);
glVertexAttrib3f(0, -0.5, -0.5, -0.5 );
glVertexAttrib3f(0, -0.5,  0.5, -0.5 );
glVertexAttrib3f(0,  0.5,  0.5, -0.5 );

glVertexAttrib3f(1,  0, 0, 1);
glVertexAttrib3f(0,  0.5, -0.5, 0.5 );
glVertexAttrib3f(0,  0.5,  0.5, 0.5 );
glVertexAttrib3f(0, -0.5,  0.5, 0.5 );
....
glEnd();

I suppose I should get rid of those glBegin() glEnd() functions and maybe call glDrawArrays() but haven't got it to work.

2
glBegin and glEnd do not exist in OpenGL 4.user253751
I believe this should still work in the compatibility profile. Obviously not with a core profile context.Reto Koradi

2 Answers

1
votes

glBegin/glEnd are deprecated legacy functionality and they are not the part of the OpenGL core profiles since version 3.1. In short they shouldn't be used anymore. If you want to use them in spite of that, you can, but in that case you must use the compatibility profile in your OpenGL context, otherwise they are unsupported.

If you use GLFW for context and window creation, you can set the compatibility profile at the context creation with the following hint:

glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);

I would strongly recommend the following tutorial sites

to learn about modern OpenGL functionality and usage.

0
votes

In OpenGL 3.3 and greater (maybe even just 3.0 and greater?) you cannot draw anything without specifying a shader program explicitly.

Also, in OpenGL ES 2.0 you need this.

OpenGL: What's the deal with deprecation?

Does OpenGL ES 2.0 require a shader for any vertex rendering?