Can I use the same vertices to render multiple things? I'm passing my vertex shader a bunch of vertices and color data. I would like to first render the triangles and then render a point at each vertex. The triangles render fine, but I can't think of a way to render the triangles and the points without making and calling a whole new method for rendering points, which I guess I could do, but I'd like to know if there is some shader magic that accomplish it for me.

Thanks in advance!

This is my vs:

#version 120

uniform mat4 projection;

void main() {

gl_Position = projection * ftransform();
gl_PointSize = 1.0;
gl_FrontColor = gl_Color;

}


This is my fs:

#version 120

#define point_color vec3(1,1,1)

void main() {

vec4 color = gl_Color;
gl_FragColor = vec4(color);

}


This is the code behind it. I'm using lwjgl.

public void render() {

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnable(GL_PROGRAM_POINT_SIZE);

    glBindBuffer(GL_ARRAY_BUFFER, VBO_id);
    glVertexPointer(3, GL_FLOAT, 0, 0);

    glBindBuffer(GL_ARRAY_BUFFER, c_id);
    glColorPointer(4, GL_FLOAT, 0, 0);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_id);
    glDrawElements(GL_TRIANGLES, draw_count, GL_UNSIGNED_INT, 0);

    glDrawArrays(GL_POINTS, 0, draw_count_v);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisable(GL_PROGRAM_POINT_SIZE);
}
If your intention is to render some textured or colored triangles and points colored diferently at the same time at vertex postions with one draw call:

glDrawElements(GL_TRIANGLES, draw_count, GL_UNSIGNED_INT, 0);


In order to access vertex data in vertex shader, you can create vertex array object which references to vertex buffer object with data you provided (vertices) for example at index 0.

then in vertex shader you have:

layout (location = 0) in vec3 vPosition; //positions for each vertex


You might then do something like that (vertex shader):

flat out vec3 fpos; //not interpolated vertices
out vec3 pos; //interpolated vertices (for default)
void main(void)
{
  pos = vPosition;
  fpos = vPosition;
}


And then in fragment shader:

if(length(fpos-pos)&lt;threshold) //small threshold
 fragColor = pointColor;
else
 fragColor = triangleColor;