Fixed stroked circles width issue with OpenGL shaders.
This commit is contained in:
parent
aa6a5ab671
commit
b0c1b97ff3
|
@ -816,16 +816,17 @@ void OPENGL_GAL::DrawCircle( const VECTOR2D& aCenterPoint, double aRadius )
|
||||||
//\\
|
//\\
|
||||||
v0 /_\/_\ v1
|
v0 /_\/_\ v1
|
||||||
*/
|
*/
|
||||||
|
double outerRadius = aRadius + ( lineWidth / 2 );
|
||||||
setShader( SHADER_STROKED_CIRCLE, 1.0, aRadius, lineWidth );
|
setShader( SHADER_STROKED_CIRCLE, 1.0, aRadius, lineWidth );
|
||||||
vertex3( aCenterPoint.x - aRadius * sqrt( 3.0f ),
|
vertex3( aCenterPoint.x - outerRadius * sqrt( 3.0f ),
|
||||||
aCenterPoint.y - aRadius, layerDepth ); // v0
|
aCenterPoint.y - outerRadius, layerDepth ); // v0
|
||||||
|
|
||||||
setShader( SHADER_STROKED_CIRCLE, 2.0, aRadius, lineWidth );
|
setShader( SHADER_STROKED_CIRCLE, 2.0, aRadius, lineWidth );
|
||||||
vertex3( aCenterPoint.x + aRadius * sqrt( 3.0f ),
|
vertex3( aCenterPoint.x + outerRadius * sqrt( 3.0f ),
|
||||||
aCenterPoint.y - aRadius, layerDepth ); // v1
|
aCenterPoint.y - outerRadius, layerDepth ); // v1
|
||||||
|
|
||||||
setShader( SHADER_STROKED_CIRCLE, 3.0, aRadius, lineWidth );
|
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;
|
return;
|
||||||
|
@ -964,6 +965,8 @@ void OPENGL_GAL::drawStrokedSemiCircle( const VECTOR2D& aCenterPoint, double aRa
|
||||||
{
|
{
|
||||||
if( isUseShader )
|
if( isUseShader )
|
||||||
{
|
{
|
||||||
|
double outerRadius = aRadius + ( lineWidth / 2 );
|
||||||
|
|
||||||
Save();
|
Save();
|
||||||
Translate( aCenterPoint );
|
Translate( aCenterPoint );
|
||||||
Rotate( aAngle );
|
Rotate( aAngle );
|
||||||
|
@ -979,13 +982,13 @@ void OPENGL_GAL::drawStrokedSemiCircle( const VECTOR2D& aCenterPoint, double aRa
|
||||||
v0 //__\\ v1
|
v0 //__\\ v1
|
||||||
*/
|
*/
|
||||||
setShader( SHADER_STROKED_CIRCLE, 4.0f, aRadius, lineWidth );
|
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 );
|
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 );
|
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();
|
Restore();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,9 @@
|
||||||
#version 120
|
#version 120
|
||||||
|
|
||||||
// Shader types
|
// Shader types
|
||||||
const float SHADER_LINE = 1.0;
|
const float SHADER_LINE = 1.0f;
|
||||||
const float SHADER_FILLED_CIRCLE = 2.0;
|
const float SHADER_FILLED_CIRCLE = 2.0f;
|
||||||
const float SHADER_STROKED_CIRCLE = 3.0;
|
const float SHADER_STROKED_CIRCLE = 3.0f;
|
||||||
|
|
||||||
varying vec4 shaderParams;
|
varying vec4 shaderParams;
|
||||||
varying vec2 circleCoords;
|
varying vec2 circleCoords;
|
||||||
|
@ -45,11 +45,11 @@ void filledCircle( vec2 aCoord )
|
||||||
|
|
||||||
void strokedCircle( vec2 aCoord, float aRadius, float aWidth )
|
void strokedCircle( vec2 aCoord, float aRadius, float aWidth )
|
||||||
{
|
{
|
||||||
float outerRadius = aRadius;
|
float outerRadius = aRadius + ( aWidth / 2 );
|
||||||
float innerRadius = aRadius - aWidth;
|
float innerRadius = aRadius - ( aWidth / 2 );
|
||||||
float relWidth = innerRadius / outerRadius;
|
float relWidth = innerRadius / outerRadius;
|
||||||
|
|
||||||
if( ( dot( aCoord, aCoord ) < 1.0 ) &&
|
if( ( dot( aCoord, aCoord ) < 1.0f ) &&
|
||||||
( dot( aCoord, aCoord ) > relWidth * relWidth ) )
|
( dot( aCoord, aCoord ) > relWidth * relWidth ) )
|
||||||
gl_FragColor = gl_Color;
|
gl_FragColor = gl_Color;
|
||||||
else
|
else
|
||||||
|
|
|
@ -27,12 +27,12 @@
|
||||||
#version 120
|
#version 120
|
||||||
|
|
||||||
// Shader types
|
// Shader types
|
||||||
const float SHADER_LINE = 1.0;
|
const float SHADER_LINE = 1.0f;
|
||||||
const float SHADER_FILLED_CIRCLE = 2.0;
|
const float SHADER_FILLED_CIRCLE = 2.0f;
|
||||||
const float SHADER_STROKED_CIRCLE = 3.0;
|
const float SHADER_STROKED_CIRCLE = 3.0f;
|
||||||
|
|
||||||
// Minimum line width
|
// Minimum line width
|
||||||
const float MIN_WIDTH = 1.0;
|
const float MIN_WIDTH = 1.0f;
|
||||||
|
|
||||||
attribute vec4 attrShaderParams;
|
attribute vec4 attrShaderParams;
|
||||||
varying vec4 shaderParams;
|
varying vec4 shaderParams;
|
||||||
|
@ -51,9 +51,9 @@ void main()
|
||||||
|
|
||||||
// Make lines appear to be at least 1 pixel wide
|
// Make lines appear to be at least 1 pixel wide
|
||||||
if( worldScale * lineWidth < MIN_WIDTH )
|
if( worldScale * lineWidth < MIN_WIDTH )
|
||||||
scale = 1.0 / ( worldScale * lineWidth );
|
scale = 1.0f / ( worldScale * lineWidth );
|
||||||
else
|
else
|
||||||
scale = 1.0;
|
scale = 1.0f;
|
||||||
|
|
||||||
gl_Position = gl_ModelViewProjectionMatrix *
|
gl_Position = gl_ModelViewProjectionMatrix *
|
||||||
( gl_Vertex + vec4( shaderParams.yz * scale, 0.0, 0.0 ) );
|
( 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
|
// Make the line appear to be at least 1 pixel wide
|
||||||
float lineWidth = shaderParams[3];
|
float lineWidth = shaderParams[3];
|
||||||
float worldScale = gl_ModelViewMatrix[0][0];
|
float worldScale = gl_ModelViewMatrix[0][0];
|
||||||
float scale;
|
|
||||||
|
|
||||||
// Make lines appear to be at least 1 pixel width
|
// Make lines appear to be at least 1 pixel width
|
||||||
if( worldScale * lineWidth < MIN_WIDTH )
|
if( worldScale * lineWidth < MIN_WIDTH )
|
||||||
|
|
Loading…
Reference in New Issue