I want to draw a square from point data with the geometry shader.
In the vertex shader
, I emit a single point.
#version 330 core
void main() {
gl_Position = vec4(0, 0, 0, 1.0);
}
In the geometry shader, I want to create a triangle strip forming a square.
The size is irrelevant at the moment so the model should have a size of 1
(ranging from (-0.5, -0.5) from the initial point position to (+0.5, +0.5).
I need help to calculate the position of the emitted vertices, as visible 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 to use trans
to translate the initial point to the desired coordinates. How would I realize this?
Edit for clarity
I want to generate from a single point what else would be given by the vertex buffer; a single 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 the real points by subtracting and adding the differences to the center (0.5 and -0.5 etc.). All I need is to know how to apply this transformation in the code (where the ???
are).