I am trying to draw a small box (a Handle) around each of the vertices for shape (in my case another box) (e.g. PowerPoint’s resize handles). I am using a vertex shader to position and scale the main shape and that is working fine.
That shader is
uniform mat4 u_transform;
void main() {
gl_Position = gl_ProjectionMatrix * u_transform * gl_Vertex;
}
I am struggling with try to layout the small box / handle at each of the vertices using a shader. I want the handle to be a fixed size in screen space and centered around each vertex of the main shape.
I naively tried.
A Triangle Fan with coordinates of [(-5, -5), (-5, 5), (5, 5), (5, -5 )]
#version 120
uniform mat4 u_transform;
uniform vec2 u_position; // The vertex from the original shape (untransformed)
void main() {
// Center in SCREEN
vec4 center = gl_ProjectionMatrix * u_transform * vec4(u_position, 0, 1);
// Vertex in SCREEN
vec4 offsetFromCenter = gl_ProjectionMatrix * gl_Vertex;
//OFFSET VERTEX
gl_Position = center + offsetFromCenter;
}
And I also tried
#version 120
uniform mat4 u_transform;
uniform vec2 u_position;
void main() {
// Center in SCREEN
vec4 center = gl_ProjectionMatrix * u_transform * vec4(u_position, 0, 1);
vec3 centerN = center.xyz/center.w;
// Vertex in SCREEN
vec4 offsetFromCenter = gl_ProjectionMatrix * gl_Vertex;
vec3 offsetFromCenterN = offsetFromCenter.xyz/offsetFromCenter.w;
//OFFSET VERTEX
vec3 sum = centerN + offsetFromCenterN;
gl_Position = vec4(sum,offsetFromCenter.w);
}
What am I missing?