Jump to content

  • Log In with Google      Sign In   
  • Create Account

glVertexPointer, glNormalPointer, and glTexCoordPointer deprecated? Correct use?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 mv348   Members   -  Reputation: 253

Like
0Likes
Like

Posted 17 August 2012 - 12:56 PM

I am trying to keep shader use optional in my application for debuging purposes.

I read in a few places that glVertexPointer, glNormalPointer, and glTexCoordPointer are deprecated and we are supposed to use glVertexAttribPointer instead.

So:
glBindBuffer(GL_ARRAY_BUFFER, positionVBO);
	glVertexPointer(VERTEX_STRIDE, GL_FLOAT, 0, 0);
	glEnableClientState(GL_VERTEX_ARRAY);

becomes:

glBindBuffer(GL_ARRAY_BUFFER, positionVBO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, VERTEX_STRIDE, GL_FLOAT, GL_FALSE, 0, 0);

So the position is associated with the attribute index 0.

Thats all well and good, but how would OpenGL know that the position is at attribute index 0 without a shader enabled? Is it really bad practice to use glVertexPointer, glNormalPointer, and glTexCoordPointer? Is it okay to mix these two styles?

Edited by mv348, 17 August 2012 - 12:57 PM.


Sponsor:

#2 Lazy Foo   Members   -  Reputation: 1105

Like
2Likes
Like

Posted 17 August 2012 - 01:28 PM

glVertexPointer, glNormalPointer, and glTexCoordPointer don't even exist in modern OpenGL as is all the fixed pipeline. Everything is shader based now.

When shaders and custom attributes came along they realized that vertex positions, normals, texture coordinates, etc were all just vectors. Rather than put in attributes that the programmer may or may not use, they just let you define what you needed with custom vertex attributes.

I have an OpenGL tutorial series designed to help people transition from the old fixed function pipeline to modern OpenGL. All you really need to know since you know shaders is that there aren't those built in attributes anymore and you have to make them again yourself. It's pretty each for the most part.

If you want to have a fixed function fallback, you can create pseudo shader. I have a shader class architecture where ShaderProgram is the base for PlainPolygonProgram. I then have a set of classes like PlainPolygonProgram21 PlainPolygonProgram30 PlainPolygonProgram15 PlainPolygonProgram11 that inherit from PlainPolygonProgram and support OpenGL version 2.1, 3.0, 1.5, and 1.1 respectively. On the outside the all work the same but the internals of which GLSL version is used and how the vertex data is sent changes depending on what the version supports.

Edited by Lazy Foo, 17 August 2012 - 01:46 PM.

Learn to make games with my SDL 2 Tutorials


#3 mv348   Members   -  Reputation: 253

Like
0Likes
Like

Posted 17 August 2012 - 03:10 PM

Thank you so much for your response. I will definitely read through your tutorial.

In the meantime, since you seem to know a lot about modern opengl...

The tutorial I was reading placed both position data, and color data in one float array, and placed that array in one buffer. Then set up the attribute pointers to find the appropriate data.

That's pretty nifty, but in my case, I need both int data, and float data associated with each vertex. So I don't know if I can just put it all in one buffer. Is it still possible to put vertex data in separate buffers?

#4 LordSputnik   Members   -  Reputation: 132

Like
0Likes
Like

Posted 17 August 2012 - 04:15 PM

As far as I know there's no way of mixing int and float data. You, can certainly use two different arrays though. You can't however just use 0 and 1 as your array handles - you need to use glGetAttribLocation with the name of your attribute variable in the shader to be able to upload the data.

For example:

In vertex shader (GLSL):
attribute vec4 position;
attribute ivec4 some_other_attrib;

//do some stuff in main

In C/C++:
GLint pos_id = glGetAttribLocation(shader_program_id,"position");
GLint other_id = glGetAttribLocation(shader_program_id,"some_other_attrib");

glBindBuffer(GL_ARRAY_BUFFER, positionVBO);
glEnableVertexAttribArray(pos_id);
glVertexAttribPointer(pos_id, VERTEX_STRIDE, GL_FLOAT, GL_FALSE, 0, 0);

glBindBuffer(GL_ARRAY_BUFFER, intVBO);
glEnableVertexAttribArray(other_id);
glVertexAttribPointer(other_id, VERTEX_STRIDE, GL_INT, ..., 0);

If you can, try not to ever use the fixed function pipeline anymore. Shaders are supported on all modern cards and have been for ages, and allow you to do a lot more than FFP. If a card doesn't support vertex and fragment shaders, well, that's the end user's fault for not upgrading their machine in 8 years.

Note: I've used similar code to this in a project recently, but I only really learnt it for that, so if something's wrong, someone correct me! ;)

#5 Lazy Foo   Members   -  Reputation: 1105

Like
0Likes
Like

Posted 17 August 2012 - 11:29 PM

in my case, I need both int data, and float data associated with each vertex. So I don't know if I can just put it all in one buffer. Is it still possible to put vertex data in separate buffers?


I've never tried that before, but I don't see why it wouldn't work. glBufferData() just asks for bytes not data type. The glVertexAttribPointer() function just cares about a starting address, size, and stride in between each occurrence of the attribute.

Try it, see if it works.

Learn to make games with my SDL 2 Tutorials


#6 dpadam450   Members   -  Reputation: 946

Like
0Likes
Like

Posted 17 August 2012 - 11:58 PM

You can. That is why it asks for the type as well as stride for the attribute. The stride is in bytes so that you can "jump" over an arbitrary bytes and then interpret the new pointer as the type you provided.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS