Commit b0c1b97f authored by Maciej Suminski's avatar Maciej Suminski

Fixed stroked circles width issue with OpenGL shaders.

parent aa6a5ab6
......@@ -795,7 +795,7 @@ void OPENGL_GAL::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius )
aCenterPoint.y - aRadius, layerDepth ); // v0
setShader( SHADER_FILLED_CIRCLE, 2.0 );
vertex3( aCenterPoint.x + aRadius * sqrt( 3.0f ),
vertex3( aCenterPoint.x + aRadius* sqrt( 3.0f ),
aCenterPoint.y - aRadius, layerDepth ); // v1
setShader( SHADER_FILLED_CIRCLE, 3.0 );
......@@ -816,16 +816,17 @@ void OPENGL_GAL::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius )
//\\
v0 /_\/_\ v1
*/
double outerRadius = aRadius + ( lineWidth / 2 );
setShader( SHADER_STROKED_CIRCLE, 1.0, aRadius, lineWidth );
vertex3( aCenterPoint.x - aRadius * sqrt( 3.0f ),
aCenterPoint.y - aRadius, layerDepth ); // v0
vertex3( aCenterPoint.x - outerRadius * sqrt( 3.0f ),
aCenterPoint.y - outerRadius, layerDepth ); // v0
setShader( SHADER_STROKED_CIRCLE, 2.0, aRadius, lineWidth );
vertex3( aCenterPoint.x + aRadius * sqrt( 3.0f ),
aCenterPoint.y - aRadius, layerDepth ); // v1
vertex3( aCenterPoint.x + outerRadius * sqrt( 3.0f ),
aCenterPoint.y - outerRadius, layerDepth ); // v1
setShader( SHADER_STROKED_CIRCLE, 3.0, aRadius, lineWidth );
vertex3( aCenterPoint.x, aCenterPoint.y + aRadius * 2.0f, layerDepth ); // v2
vertex3( aCenterPoint.x, aCenterPoint.y + outerRadius * 2.0f, layerDepth ); // v2
}
return;
......@@ -964,6 +965,8 @@ void OPENGL_GAL::drawStrokedSemiCircle( const VECTOR2D& aCenterPoint, double aRa
{
if( isUseShader )
{
double outerRadius = aRadius + ( lineWidth / 2 );
Save();
Translate( aCenterPoint );
Rotate( aAngle );
......@@ -979,13 +982,13 @@ void OPENGL_GAL::drawStrokedSemiCircle( const VECTOR2D& aCenterPoint, double aRa
v0 //__\\ v1
*/
setShader( SHADER_STROKED_CIRCLE, 4.0f, aRadius, lineWidth );
vertex3( -aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0
vertex3( -outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0
setShader( SHADER_STROKED_CIRCLE, 5.0f, aRadius, lineWidth );
vertex3( aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1
vertex3( outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1
setShader( SHADER_STROKED_CIRCLE, 6.0f, aRadius, lineWidth );
vertex3( 0.0f, aRadius * 2.0f, layerDepth ); // v2
vertex3( 0.0f, outerRadius * 2.0f, layerDepth ); // v2
Restore();
}
......
......@@ -27,9 +27,9 @@
#version 120
// Shader types
const float SHADER_LINE = 1.0;
const float SHADER_FILLED_CIRCLE = 2.0;
const float SHADER_STROKED_CIRCLE = 3.0;
const float SHADER_LINE = 1.0f;
const float SHADER_FILLED_CIRCLE = 2.0f;
const float SHADER_STROKED_CIRCLE = 3.0f;
varying vec4 shaderParams;
varying vec2 circleCoords;
......@@ -45,11 +45,11 @@ void filledCircle( vec2 aCoord )
void strokedCircle( vec2 aCoord, float aRadius, float aWidth )
{
float outerRadius = aRadius;
float innerRadius = aRadius - aWidth;
float outerRadius = aRadius + ( aWidth / 2 );
float innerRadius = aRadius - ( aWidth / 2 );
float relWidth = innerRadius / outerRadius;
if( ( dot( aCoord, aCoord ) < 1.0 ) &&
if( ( dot( aCoord, aCoord ) < 1.0f ) &&
( dot( aCoord, aCoord ) > relWidth * relWidth ) )
gl_FragColor = gl_Color;
else
......
......@@ -27,12 +27,12 @@
#version 120
// Shader types
const float SHADER_LINE = 1.0;
const float SHADER_FILLED_CIRCLE = 2.0;
const float SHADER_STROKED_CIRCLE = 3.0;
const float SHADER_LINE = 1.0f;
const float SHADER_FILLED_CIRCLE = 2.0f;
const float SHADER_STROKED_CIRCLE = 3.0f;
// Minimum line width
const float MIN_WIDTH = 1.0;
const float MIN_WIDTH = 1.0f;
attribute vec4 attrShaderParams;
varying vec4 shaderParams;
......@@ -51,9 +51,9 @@ void main()
// Make lines appear to be at least 1 pixel wide
if( worldScale * lineWidth < MIN_WIDTH )
scale = 1.0 / ( worldScale * lineWidth );
scale = 1.0f / ( worldScale * lineWidth );
else
scale = 1.0;
scale = 1.0f;
gl_Position = gl_ModelViewProjectionMatrix *
( gl_Vertex + vec4( shaderParams.yz * scale, 0.0, 0.0 ) );
......@@ -81,7 +81,6 @@ void main()
// Make the line appear to be at least 1 pixel wide
float lineWidth = shaderParams[3];
float worldScale = gl_ModelViewMatrix[0][0];
float scale;
// Make lines appear to be at least 1 pixel width
if( worldScale * lineWidth < MIN_WIDTH )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment