# LWJGL Using gl_VertexID properly?

I've gotten back to making lwjgl games, and I'm trying to make a sort of wave type vertex shader. I call this to make it wave:

    // t is a float that gets updated every frame.

fac = sin(t+gl_VertexID);

gl_Position = gl_ModelViewProjectionMatrix * ( gl_Vertex + vec4(0.0, fac/10, 0.0, 0.0)  );



When I run the program, though, it outputs like this:

The individual vertices are moving, which is great, what I want, but they aren't connected to eachother, so each triangle is separated from one another. How do I fix this without changing the GL11.glBegin(GL11.GL_TRIANGLES) to GL11.glBegin(GL11.GL_TRIANGLE_STRIP)? Or do I have to?

• If you want this to behave as a wave, would you not want to use the vertex position as the offset to the sine function's phase, rather than its ID? Sep 16 at 1:38
• @DMGregory if I use gl_Vertex.y, it controls all y values of the vertices, but only changes it by one singular value, which is the sine functions value in the phase Sep 16 at 3:38
• Right, and then you add time to make the wave move. If that's not your desired outcome, you may want to explain what output you want in more detail than "wave type vertex shader" Sep 16 at 10:57
• @DMGregory I don't want it to wave like that, but rather wave like a vertex displacement, move the vertices in a way where it will look like this. Do I have to use GL_TRIANGLE_STRIP instead of GL_TRIANGLES? Sep 16 at 18:17
• No, that will not make different vertices share the same ID. Vertex ID is not what you want here. You might instead be looking for some type of noise function acting on the vertex position in world space. That way all vertices that coincide at a specific location get the same noise value output. Sep 16 at 18:36