I want to draw a square from point data using a geometric shader.
In the vertex shader
I emit one dot.
In the geometric shader, I want to create a triangular strip that forms a square.
At the moment, the size does not matter, so the model should have a size of 1
(from (-0.5, -0.5) from the initial position of the point to (+0.5, +0.5).
I need help calculating the position of the emitted vertices, as seen in the code:
#version 330 core layout(points) in; layout(triangle_strip, max_vertices=4) out; out vec2 tex_coord; uniform mat4x4 model; uniform mat4x4 view; uniform mat4x4 projection; void main() { int i; for(i = 0; i < gl_in.length(); ++i) { mat4x4 trans; trans = //??? gl_Position = projection * view * model * trans * gl_in[i].gl_Position; tex_coord = vec2(0, 0); EmitVertex(); trans = //??? gl_Position = projection * view * model * trans * gl_in[i].gl_Position; tex_coord = vec2(1, 0); EmitVertex(); trans = //??? gl_Position = projection * view * model * trans * gl_in[i].gl_Position; tex_coord = vec2(1, 1); EmitVertex(); trans = //??? gl_Position = projection * view * model * trans * gl_in[i].gl_Position; tex_coord = vec2(0, 1)); EmitVertex(); } EndPrimitive(); }
I thought of using trans
to translate the starting point to the desired coordinates. How do I understand that?
Edit for clarity.
I want to generate from one point what else will be given by the vertex buffer; one plane:
float vertex[] { -0.5, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5, -0.5, 0.0, -0.5, -0.5, 0.0 }
Instead, I give only a point in the middle of these points and want to generate real points by subtracting and adding differences to the center (0.5 and -0.5, etc.). I only need to know how to apply this conversion in code (where ???
).