Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
70769d5d
Commit
70769d5d
authored
Apr 09, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed drawing of circles in certain circumstances using OpenGL.
parent
05e3ae64
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
84 deletions
+46
-84
opengl_gal.cpp
common/gal/opengl/opengl_gal.cpp
+46
-84
No files found.
common/gal/opengl/opengl_gal.cpp
View file @
70769d5d
...
...
@@ -437,6 +437,7 @@ inline void OPENGL_GAL::selectShader( int aIndex )
}
}
void
OPENGL_GAL
::
drawRoundedSegment
(
VECTOR2D
aStartPoint
,
VECTOR2D
aEndPoint
,
double
aWidth
,
bool
aStroke
,
bool
aGlBegin
)
{
...
...
@@ -863,99 +864,56 @@ void OPENGL_GAL::DrawCircle( VECTOR2D aCenterPoint, double aRadius )
return
;
}
switch
(
m_drawMode
)
{
// Draw the middle of the circle (not anti-aliased)
case
DRAW_MODE_NORMAL
:
{
// Compute the factors for the unit circle
double
outerScale
=
lineWidth
/
aRadius
/
2
;
double
innerScale
=
-
outerScale
;
outerScale
+=
1.0
;
innerScale
+=
1.0
;
if
(
isUseShader
)
{
innerScale
*=
1.0
/
cos
(
M_PI
/
CIRCLE_POINTS
);
}
if
(
isStrokeEnabled
)
{
if
(
innerScale
<
outerScale
)
{
// Draw the outline
glColor4d
(
strokeColor
.
r
,
strokeColor
.
g
,
strokeColor
.
b
,
strokeColor
.
a
);
glPushMatrix
();
glTranslated
(
aCenterPoint
.
x
,
aCenterPoint
.
y
,
0.0
);
glScaled
(
aRadius
,
aRadius
,
1.0
);
glBegin
(
GL_QUAD_STRIP
);
for
(
std
::
deque
<
VECTOR2D
>::
const_iterator
it
=
unitCirclePoints
.
begin
();
it
!=
unitCirclePoints
.
end
();
it
++
)
{
glVertex3d
(
it
->
x
*
innerScale
,
it
->
y
*
innerScale
,
layerDepth
);
glVertex3d
(
it
->
x
*
outerScale
,
it
->
y
*
outerScale
,
layerDepth
);
}
glEnd
();
// Compute the factors for the unit circle
double
outerScale
=
lineWidth
/
aRadius
/
2
;
double
innerScale
=
-
outerScale
;
outerScale
+=
1.0
;
innerScale
+=
1.0
;
glPopMatrix
();
}
}
if
(
isUseShader
)
{
innerScale
*=
1.0
/
cos
(
M_PI
/
CIRCLE_POINTS
);
}
// Filled circles are easy to draw by using the stored display list, scaling and translating
if
(
isFillEnabled
)
if
(
isStrokeEnabled
)
{
if
(
innerScale
<
outerScale
)
{
glColor4d
(
fillColor
.
r
,
fillColor
.
g
,
fillColor
.
b
,
fillColor
.
a
);
// Draw the outline
glColor4d
(
strokeColor
.
r
,
strokeColor
.
g
,
strokeColor
.
b
,
strokeColor
.
a
);
glPushMatrix
();
glTranslated
(
aCenterPoint
.
x
,
aCenterPoint
.
y
,
layerDepth
);
glTranslated
(
aCenterPoint
.
x
,
aCenterPoint
.
y
,
0.0
);
glScaled
(
aRadius
,
aRadius
,
1.0
);
glBegin
(
GL_TRIANGLE_FAN
);
glVertex3d
(
0
,
0
,
0
);
glCallList
(
displayListCircle
);
glBegin
(
GL_QUAD_STRIP
);
for
(
std
::
deque
<
VECTOR2D
>::
const_iterator
it
=
unitCirclePoints
.
begin
();
it
!=
unitCirclePoints
.
end
();
it
++
)
{
glVertex3d
(
it
->
x
*
innerScale
,
it
->
y
*
innerScale
,
layerDepth
);
glVertex3d
(
it
->
x
*
outerScale
,
it
->
y
*
outerScale
,
layerDepth
);
}
glEnd
();
glPopMatrix
();
}
glColor4d
(
strokeColor
.
r
,
strokeColor
.
g
,
strokeColor
.
b
,
strokeColor
.
a
);
}
break
;
// Prepare / draw anti-aliased edges
case
DRAW_MODE_PREPARE_EDGES
:
case
DRAW_MODE_DRAW_EDGES
:
if
(
isUseShader
)
{
// Set the color
// Now we enable the shader program for the circle
// the shader requires the screen size as uniform argument
shaderList
[
0
].
Use
();
shaderList
[
0
].
SetParameter
(
0
,
screenSize
.
x
/
2
);
shaderList
[
0
].
SetParameter
(
1
,
screenSize
.
y
/
2
);
glBegin
(
GL_LINES
);
if
(
isStrokeEnabled
)
{
glColor4d
(
strokeColor
.
r
,
strokeColor
.
g
,
strokeColor
.
b
,
strokeColor
.
a
);
glVertex3d
(
aCenterPoint
.
x
,
aCenterPoint
.
y
,
layerDepth
);
glVertex3d
(
aRadius
-
lineWidth
/
2
,
aRadius
+
lineWidth
/
2
,
0
);
}
else
{
glColor4d
(
fillColor
.
r
,
fillColor
.
g
,
fillColor
.
b
,
fillColor
.
a
);
glVertex3d
(
aCenterPoint
.
x
,
aCenterPoint
.
y
,
layerDepth
);
glVertex3d
(
0
,
aRadius
,
0
);
}
glEnd
();
shaderList
[
0
].
Deactivate
();
}
break
;
default
:
break
;
// Filled circles are easy to draw by using the stored display list, scaling and translating
if
(
isFillEnabled
)
{
glColor4d
(
fillColor
.
r
,
fillColor
.
g
,
fillColor
.
b
,
fillColor
.
a
);
glPushMatrix
();
glTranslated
(
aCenterPoint
.
x
,
aCenterPoint
.
y
,
layerDepth
);
glScaled
(
aRadius
,
aRadius
,
1.0
);
glCallList
(
displayListCircle
);
glPopMatrix
();
}
}
...
...
@@ -970,9 +928,7 @@ void OPENGL_GAL::drawSemiCircle( VECTOR2D aCenterPoint, double aRadius, double a
glScaled
(
aRadius
,
aRadius
,
1.0
);
glRotated
(
aAngle
*
360.0
/
(
2
*
M_PI
),
0
,
0
,
1
);
glBegin
(
GL_TRIANGLE_FAN
);
glCallList
(
displayListSemiCircle
);
glEnd
();
glPopMatrix
();
}
...
...
@@ -1362,15 +1318,18 @@ void OPENGL_GAL::computeUnitCircle()
displayListCircle
=
glGenLists
(
1
);
glNewList
(
displayListCircle
,
GL_COMPILE
);
glBegin
(
GL_TRIANGLE_FAN
);
glVertex2d
(
0
,
0
);
// Compute the circle points for a given number of segments
// Insert in a display list and a vector
for
(
int
i
=
0
;
i
<
CIRCLE_POINTS
+
1
;
i
++
)
{
double
valueX
=
cos
(
2
*
M_PI
/
CIRCLE_POINTS
*
i
);
double
valueY
=
sin
(
2
*
M_PI
/
CIRCLE_POINTS
*
i
);
glVertex
3d
(
valueX
,
valueY
,
0
);
double
valueX
=
cos
(
2
.0
*
M_PI
/
CIRCLE_POINTS
*
i
);
double
valueY
=
sin
(
2
.0
*
M_PI
/
CIRCLE_POINTS
*
i
);
glVertex
2d
(
valueX
,
valueY
);
unitCirclePoints
.
push_back
(
VECTOR2D
(
valueX
,
valueY
)
);
}
glEnd
();
glEndList
();
}
...
...
@@ -1381,10 +1340,13 @@ void OPENGL_GAL::computeUnitSemiCircle()
displayListSemiCircle
=
glGenLists
(
1
);
glNewList
(
displayListSemiCircle
,
GL_COMPILE
);
glBegin
(
GL_TRIANGLE_FAN
);
glVertex2d
(
0
,
0
);
for
(
int
i
=
0
;
i
<
CIRCLE_POINTS
/
2
+
1
;
i
++
)
{
glVertex
3d
(
cos
(
2
*
M_PI
/
CIRCLE_POINTS
*
i
),
sin
(
2
*
M_PI
/
CIRCLE_POINTS
*
i
),
0
);
glVertex
2d
(
cos
(
2.0
*
M_PI
/
CIRCLE_POINTS
*
i
),
sin
(
2.0
*
M_PI
/
CIRCLE_POINTS
*
i
)
);
}
glEnd
();
glEndList
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment