Use geometry shader for widgets.
This commit is contained in:
@@ -13,4 +13,5 @@ uniform Material u_material;
|
||||
void main()
|
||||
{
|
||||
f_color = texture(u_material.texture_diffuse0, v_texCoord);
|
||||
// f_color = vec4(1.0, 0.0, 0.0, 0.5);
|
||||
}
|
||||
|
||||
41
data/shaders/menu.geom
Normal file
41
data/shaders/menu.geom
Normal file
@@ -0,0 +1,41 @@
|
||||
#version 330 core
|
||||
|
||||
layout(points) in;
|
||||
layout(triangle_strip, max_vertices = 4) out;
|
||||
|
||||
struct WidgetData
|
||||
{
|
||||
vec2 position;
|
||||
vec2 dimensions;
|
||||
};
|
||||
uniform WidgetData u_widgetData;
|
||||
|
||||
out vec2 v_texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
float glWidth = u_widgetData.dimensions.x * 2.0f;
|
||||
float glHeight = u_widgetData.dimensions.y * 2.0f;
|
||||
|
||||
vec4 offset = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
gl_Position = gl_in[0].gl_Position + offset;
|
||||
v_texCoord = vec2(0.0, 0.0);
|
||||
EmitVertex();
|
||||
|
||||
offset = vec4(glWidth, 0.0, 0.0, 0.0);
|
||||
gl_Position = gl_in[0].gl_Position + offset;
|
||||
v_texCoord = vec2(1.0, 0.0);
|
||||
EmitVertex();
|
||||
|
||||
offset = vec4(0.0, glHeight, 0.0, 0.0);
|
||||
gl_Position = gl_in[0].gl_Position + offset;
|
||||
v_texCoord = vec2(0.0, 1.0);
|
||||
EmitVertex();
|
||||
|
||||
offset = vec4(glWidth, glHeight, 0.0, 0.0);
|
||||
gl_Position = gl_in[0].gl_Position + offset;
|
||||
v_texCoord = vec2(1.0, 1.0);
|
||||
EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
@@ -1,12 +1,16 @@
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) in vec3 a_position;
|
||||
layout(location = 1) in vec2 a_texCoord;
|
||||
|
||||
out vec2 v_texCoord;
|
||||
struct WidgetData
|
||||
{
|
||||
vec2 position;
|
||||
vec2 dimensions;
|
||||
};
|
||||
uniform WidgetData u_widgetData;
|
||||
|
||||
void main()
|
||||
{
|
||||
v_texCoord = a_texCoord;
|
||||
gl_Position = vec4(a_position, 1.0);
|
||||
float glPosX = u_widgetData.position.x * 2.0f - 1.0f;
|
||||
float glPosY = u_widgetData.position.y * 2.0f - 1.0f;
|
||||
|
||||
gl_Position = vec4(glPosX, glPosY, 0, 1);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
out vec2 v_tex_coords;
|
||||
|
||||
void main() {
|
||||
void main()
|
||||
{
|
||||
float x = -1.0 + float((gl_VertexID & 1) << 2);
|
||||
float y = -1.0 + float((gl_VertexID & 2) << 1);
|
||||
v_tex_coords.x = (x+1.0)*0.5;
|
||||
v_tex_coords.y = (y+1.0)*0.5;
|
||||
v_tex_coords.x = (x + 1.0) * 0.5;
|
||||
v_tex_coords.y = (y + 1.0) * 0.5;
|
||||
gl_Position = vec4(x, y, 0, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user