glEnableClientState deprecated - c++

I want to use GL_POINT_SPRITE_ARB + VBO for my particle system rendering.
I've done all preparations with point_sprites, but stuck at VBO.
It seems that glEnableClientState, is not working. I read that it is deprecated in modern openGL. So, what should i use instead?

glEnableClientState is how you tell OpenGL that you're using a vertex array for a particular fixed-function attribute (gl_Vertex, gl_Color, etc). Those are all removed from core contexts. You should use glEnableVertexAttribArray to enable a generic vertex attribute, and you use glVertexAttribPointer to associate that attribute with a buffer object.

Related

gl*Pointer-function for texture-bindings

While I looked at the definitions in gl.h ang glext.h I found GL_TEXTURE_BINDING_ARRAY, I think it has to do with VBOs like GL_TEXTURE_COORD_ARRAY does, to enable the buffer set up with glTexCoordArray.
Is there a vbo-function to bind texture-objects in an VBO like you bind the coordinates of the texture with glTexCoordArray? And how to bind it to a triangle/quad and not a single vertex?
Is there a vbo-function to bind texture-objects in an VBO
No.
The most you could do is employ bindless textures and pass those as 64-bit integer values (which presumably you'll pass to the fragment shader). But that still only provides the value per-vertex, not per-primitive. So you'll still have to deal with provoking vertex issues.

Rendering in opengl 3.1+ without VBO using client side vertex array

I want to know if its possible to draw in opengl 3.1+ core profile using vertex arrays ( client side rendering not immediate mode) without using the VBO. I know in opengl 3.1+ core profile use of VAO is essential. I want to know if its possible to draw without using VBO by using vertex arrays (client side vertex array not immediate mode).
PS I am talking about client side vertex array not immediate mode. I want to know if I can create a VAO without VBO
I read this somewhere in opengl spec Immediate-mode vertex attribute specification, client-side vertex arrays is depricated. Vertex Attributes must be stored in one or more Buffer Objects, or be specified explicitly using glVertexAttrib*()​. Since OpenGL 3.2 using Vertex Array Objects is mandatory. So does this means I can specify vertex array data using the glVertexAttriPointer like this
glBindVertexArray(m_vaoHandle);
glEnableVertexAttribArray(m_attributes[POSITION_HANDLE]);
glVertexAttribPointer(m_attributes[POSITION_HANDLE], 3, GL_FLOAT, false, 0,vertexArray);
glEnableVertexAttribArray(m_attributes[TEXCOORDINATE_HANDLE]);
glVertexAttribPointer(m_attributes[TEXCOORDINATE_HANDLE], 2, GL_FLOAT, false, 0, textureArray);
glBindVertexArray(0);
Here vertexArray and textureArray are two arrays on CPU not VBO. Then while drawing them
glUseProgram(m_Program);
// Explicitly unbind buffer so attrib pointer knows to slurp in array.
glBindBuffer(GL_ARRAY_BUFFER, 0);
//bind vertex array object
glBindVertexArray(m_vaoHandle);
glDrawArrays(mode, 0, numVertices);
glBindVertexArray(0);
If its possible in OpenGL 3.1+, I would also like to know if its possible in OpenGLES 3.0
The core profile of OpenGL 3.2+ removed the ability to use client-side vertex arrays.
OpenGL ES 2.0 does allow the use of client-side vertex arrays, as do all higher versions of ES. However, the vertex shader input variable gl_VertexID (added in GLSL ES 3.00) is undefined when using client-side arrays. Oh, and client-side vertex arrays in ES 3.0 are mentioned in appendix F.1: Legacy Features. About them, it says:
The following features are present to maintain backward compatibility with OpenGL ES 2.0, but their use in not recommended as it is likely for these features to be removed in a future version.
While I wouldn't expect them to ever go away, clearly you are being advised not to use them.
As to the question of whether VAOs can work with client-side pointers at all, yes (when client-side pointers are supported at all, of course). VAOs always store vertex array state, no matter where those arrays come from. Calling glVertexAttribPointer with a client-side pointer will store the pointer inside the current VAO, just like it would store the buffer object+offset inside the VAO.
As an appendix to the accepted answer, you can 'kind of' emulate client arrays with UBO/SSBO.
On the other hand, it should not be too hard to implement your own 'client pointer' implementation via a hidden VBO and glBufferData.

VBO with and without shaders OpenGL C++

Im trying to implement modern OpenGL, but the problem is: most tutorials are based on 3.3+, and talk about GLSL 330, I only have GLSL 130. Therefore, many things are apparently different, since my VBO's do not work.
Could you give me general hints or a tutorial that explains how to use GLSL 130 with VBO's? In my case, I have the vbo loaded, but when I use my shader program, only vertices called with glVertex get rendered, it's like the vbo gets ignored (no input). How to solve this?
And can you use VBO's without shaders? I tried to do that, but it crashed...
Yes, VBOs can still be used in GLSL 130, and can still be used even without shaders. The purpose of the VBO is to hold the vertex attributes for drawing. Most up to date tutorials I've seen have you use the layout position specifier for indicating how to address the different attributes in your shader, i.e.
layout(location = 0) in vec3 Position;
This isn't supported in GLSL 130, so you have to have another way of relating the attribute with the VBO. It's pretty simple... you can use glBindAttribLocation or glGetAttribLocation. Calling glGetAttribLocation will give you the identifier you need to use in glVertexAttribPointer to associate the VBO data with the particular attribute. You can call this at any time after the program has been compiled. In addition, you can call glBindAttribLocation to specifically set the identifier that will be associated with a given attribute name if you call it after you've created the program object but before you link the shaders. This is handy because it lets you decide for yourself what the location should be, just as you would be able to with the layout specifier.
Finally, if you want to use a VBO without using a shader at all, then you still have to find a way of associating the data in the VBO with the various inputs that the fixed function pipeline expects. This is done using a now deprecated method called glEnableClientState() and glVertexPointer(), which together let you tell OpenGL what fixed function pipeline attribute you're going to populate, and how it can find the data in the VBO.

glEnableClientState with modern OpenGL (glVertexAttribPointer etc)

I'd like to lay out some things I think I've learned, but am unsure about:
VBOs are the way to go. They're created with glGenBuffers and glBufferData.
For maximum flexibility, it's best to pass generic vertex attributes to shaders with glVertexAttribPointer, rather than glVertex, glNormal, etc..
glDrawElements can be used with vertex buffers and an index buffer to efficiently render geometry with lots of shared vertices, such as a landscape mesh.
Assuming all of that is correct so far, here's my question. All of the tutorials I've read about modern OpenGL completely omit glEnableClientState. But the OpenGL man pages say that without glEnableClientState, glDrawElements will do nothing:
http://www.opengl.org/sdk/docs/man/xhtml/glDrawElements.xml
The key passage is: "If GL_VERTEX_ARRAY is not enabled, no geometric primitives are constructed."
This leads me to the following questions:
None of the tutorials use glEnableClientState before calling glDrawElements. Does this mean the man page is wrong or outdated?
GL_VERTEX_ARRAY would seem to be the thing you enable if you're going to use glVertexPointer, and likewise you'd use GL_NORMAL_ARRAY with glNormalPointer, and so on. But if I'm not using those functions, and am instead using generic vertex attributes with glVertexAttribPointer, then why would it be necessary to enable GL_VERTEX_ARRAY?
If GL_VERTEX_ARRAY is not enabled, no geometric primitives are constructed.
That's because the man page is wrong. The man page covers GL 2.1 (and it's still wrong for that), and for whatever reason, the people updating the man page refuse to update the older GL versions for bug fixes.
In GL 2.1, you must use either generic attribute index 0 or GL_VERTEX_ARRAY. In GL 3.1+, you don't need to use any specific attribute indices.
This is because, in GL versions before 3.1, all array rendering functions were defined in terms of calls to glArrayElement, which used immediate mode-based rendering. That means that you need something to provoke the vertex. Recall that, in immediate mode, calling glVertex*() not only sets the vertex position, it also causes the vertex to be sent with the other attributes. Calling glVertexAttrib*(0, ...) does the same thing. That's why older versions require you to use either attribute 0 or GL_VERTEX_ARRAY.
In GL 3.1+, once they took out immediate mode, they had to specify array rendering differently. And because of that, they didn't have to limit themselves to using attribute 0.
If you want API docs for core GL 3.3 works, I suggest you look at the actual API docs for core GL 3.3. Though to be honest, I'd just look at the spec if you want accurate information. Those docs have a lot of misinformation in them. And since they're not actually wiki-pages, that information never gets corrected.
Your first 3 points are correct. And to answer your last half of your question, do not use glEnableClientState for modern OpenGL. Start coding!
VBOS are the way to go. They're created with glGenBuffers and
glBufferData.
VBOs are often used in high-performance applications. You might want to do something simpler first. Vertex arrays can be a good way to go to get started quickly. Because VBOs sit on top of vertex arrays anyway, you'll be using much of the same code when you switch to VBOs, and it might be good to run a test using vertex arrays or indexed vertex arrays first.
For maximum flexibility, it's best to pass generic vertex attributes
to shaders with glVertexAttribPointer, rather than glVertex, glNormal,
etc..
That's a good approach.
glDrawElements can be used with vertex buffers and an index buffer to
efficiently render geometry with lots of shared vertices, such as a
landscape mesh.
Perhaps. You have to be sure the vertices truly are shared, though. A vertex that is in the same location but has a different normal (e.g. for flat shading) isn't truly shared.

VBOs or another way?

I've just finished my basic OpenGL model loader, and now I want to move over to VBOs instead of glBegin() and glEnd(). I read in an article that even VBOs are deprecated.
My question is: Are VBOs really deprecated and is there a better way to draw objects in OpenGL? Should I be using display lists perhaps?
Vertex Buffer Objects are not deprecated. In fact, I believe they are the only (non-deprecated) way to render in OpenGL 3.0 and above.
See the OpenGL page on Vertex Buffer Object.
Legacy Note: Versions of OpenGL prior to 3.0 allowed the use of
client-side data for vertex rendering, but GL 3.0 deprecated this.
Core GL 3.1 and greater forbid client-side vertex data, so VBOs are
the only means for rendering.