PDA

View Full Version : manipulating one coordinate of vertices



paccuu
07-13-2015, 12:52 AM
I am learning OpenGL 2.0 from wikibooks: https://en.wikibooks.org/wiki/OpenGL_Programming

I am animating a 2D plot. The x-coordinates of all the vertices are set once. I have the y-coordinates stored in a std::vector. Redrawing every few hundred frames.
Would it be possible to update only the y-coordinate information in the vertex shader? The number of y-coordinates (size of vector) is a variable.
Another option is passing both the x and y coordinates, but keeping them in separate structures.

GClements
07-13-2015, 04:55 AM
Would it be possible to update only the y-coordinate information in the vertex shader?
Yes. The vertex shader needs to set gl_Position for each vertex, but can do so however you wish. So you can have separate 1-component attributes for the X and Y coordinates.

If the X coordinates are equally spaced, there's no need to supply the individual values. You can just supply the offset and spacing via uniforms and derive the values from gl_VertexID.

paccuu
07-13-2015, 06:45 AM
Thank you. What would the types of these attributes be? The most natural type for me would be vec1, but i can't see such a thing.

Alfonse Reinheart
07-13-2015, 07:55 AM
The type would be `float`.