How to make this simple OpenGL code (works in profile "lenient" 3.3 and 4.2) work in strict profile 3.2 and 4.2?

I had some 3D code, which, as I noticed, will not be displayed in a strict key profile, but perfectly in the context of a "regular" (not explicitly requested as soon as the kernel) profile. To isolate the problem, I wrote the smallest simplest possible OpenGL program, drawing only a triangle and a rectangle:

enter image description here

I published this OpenGL program as a Gist here .

When using the useStrictCoreProfile variable to false, the program does not display error messages on the console and draws a square and a triangle in accordance with the screenshot above, both on Intel HD OpenGL 3.3 and on GeForce with OpenGL 4.2.

However , when using the useStrictCoreProfile parameter set to true, it clears the background color, but does not display three or four, console output:

GLCONN: OpenGL 3.2.0 @ NVIDIA Corporation GeForce GT 640M LE/PCIe/SSE2 (GLSL: 1.50 NVIDIA via Cg compiler) LASTERR: OpenGL error at step 'render.VertexAttribPointer()': GL_INVALID_OPERATION LASTERR: OpenGL error at step 'render.DrawArrays()': GL_INVALID_OPERATION LASTERR: OpenGL error at step 'render.VertexAttribPointer()': GL_INVALID_OPERATION LASTERR: OpenGL error at step 'render.DrawArrays()': GL_INVALID_OPERATION LASTERR: OpenGL error at step '(post loop)': GL_INVALID_OPERATION EXIT 

... if 4.2 requires a strict core profile instead of 3.2, the same thing. Applies to 3 different nvidia GPUs, so I assume that I am not responding to a strict kernel profile properly. What have I been doing wrong, and how can I fix it?

Please note: you will not find the call to glEnableVertexAttribArray in the Gist above, since inside the glutil package I import - but this is called as the last step in gist compileShaders () func.

+7
source share
1 answer

You do not create / bind a vertex array object with glGenVertexArrays () and glBindVertexArray () . VAOs encapsulate a bunch of vertex attribute state, including attributes that include attribute details, etc. They were optional when the function was originally introduced, but now they are required in strict / basic contexts according to section 10.4 of the OpenGL kernel specification :

The INVALID_OPERATION error is generated by any commands that modify, retrieve, or query the state of the vertex array when the vertex array is not bound. This occurs in the initial state of GL and may result from a BindVertexArray or a side effect of DeleteVertexArrays.

Here's a very crude example of using VAO:

 // At initialization time: GLuint vao = 0; glGenVertexArrays(1, &vao); glBindVertexArray(vao); // Set up your vertex attribute state: // - glBindBuffer(GL_ARRAY_BUFFER,...); // - glEnableVertexAttribArray(...); // - glVertexAttribPointer(...); // - etc. -- Refer to OpenGL docs to see what is/isn't included in the VAO! glBindVertexArray(0); // unbinds vao // At draw time: glBindVertexArray(vao); // automatically sets up previously-bound vertex attribute state glDrawArrays(...); glBindVertexArray(0); // unbinds vao 
+14
source

All Articles