PDA

View Full Version : Drawing rectangle with border



gorkir
02-25-2016, 05:19 AM
Hello, i need to draw rectangle with border. I want to make function like this:

drawRectangle(float width, float height, float backgroundR, float backgroundG, float backgroundB, float borderSize, float borderR, float borderG, float borderB)I will often change function parameters, so i need good performance. And i want rotate it too. My first idea was do it in fragment shader with gl_FragCoord, but what if i will want to rotate it? My next idea was render it to texture and it then map on two triangles, but is it fast enough? How can i do it? I am using OpenGL 3.3. Sorry for my bad english. :)

gorkir
02-26-2016, 01:40 AM
This is my working solution with shader. :)


#version 150
in vec3 position;
out vec4 Position;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(position, 1.0);
Position = vec4(position, 1.0);
}


#version 150
out vec4 outColor;
in vec4 Position;
void main()
{
outColor = vec4(1, 0, 0, 1);
if(Position.x > -0.4 && Position.x < 0.4 && Position.y > -0.4 && Position.y < 0.4)
{
outColor = vec4(1, 1, 1, 1);
}
}