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() {


    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);


2 Answers 2


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)<threshold) //small threshold
 fragColor = pointColor;
 fragColor = triangleColor;

It's totally possible to re-use vertices. That's why when making a flat rectangle plane with four corners that there can be two triangles rendered to construct the rectangle, and the triangles share two of the vertices.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.