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
aff3787b
Commit
aff3787b
authored
Jul 04, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed drawing circles and semicircles using display lists.
parent
af5a695c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
38 deletions
+40
-38
opengl_gal.cpp
common/gal/opengl/opengl_gal.cpp
+31
-26
opengl_gal.h
include/gal/opengl/opengl_gal.h
+9
-12
No files found.
common/gal/opengl/opengl_gal.cpp
View file @
aff3787b
...
@@ -66,7 +66,6 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
...
@@ -66,7 +66,6 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
SetCursorColor
(
COLOR4D
(
1.0
,
1.0
,
1.0
,
1.0
)
);
SetCursorColor
(
COLOR4D
(
1.0
,
1.0
,
1.0
,
1.0
)
);
// Initialize the flags
// Initialize the flags
isCreated
=
false
;
isDeleteSavedPixels
=
true
;
isDeleteSavedPixels
=
true
;
isGlewInitialized
=
false
;
isGlewInitialized
=
false
;
isFrameBufferInitialized
=
false
;
isFrameBufferInitialized
=
false
;
...
@@ -114,14 +113,8 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
...
@@ -114,14 +113,8 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
InitTesselatorCallbacks
(
tesselator
);
InitTesselatorCallbacks
(
tesselator
);
gluTessProperty
(
tesselator
,
GLU_TESS_WINDING_RULE
,
GLU_TESS_WINDING_POSITIVE
);
gluTessProperty
(
tesselator
,
GLU_TESS_WINDING_RULE
,
GLU_TESS_WINDING_POSITIVE
);
// Buffered semicircle & circle vertices
// Compute unit semicircle & circle vertices and store them in a buffer for faster drawing
// (3 vertices per triangle) * (number of points to draw a circle)
computeCircleVbo
();
precomputedContainer
=
new
VBO_CONTAINER
(
3
*
CIRCLE_POINTS
);
// Compute the unit circles, used for speed up of the circle drawing
verticesCircle
=
new
VBO_ITEM
(
precomputedContainer
);
computeUnitCircle
();
verticesCircle
->
Finish
();
}
}
...
@@ -129,6 +122,11 @@ OPENGL_GAL::~OPENGL_GAL()
...
@@ -129,6 +122,11 @@ OPENGL_GAL::~OPENGL_GAL()
{
{
glFlush
();
glFlush
();
if
(
glIsList
(
displayListSemiCircle
)
)
glDeleteLists
(
displayListSemiCircle
,
1
);
if
(
glIsList
(
displayListCircle
)
)
glDeleteLists
(
displayListCircle
,
1
);
delete
verticesCircle
;
delete
verticesCircle
;
delete
precomputedContainer
;
delete
precomputedContainer
;
...
@@ -331,6 +329,7 @@ void OPENGL_GAL::initGlew()
...
@@ -331,6 +329,7 @@ void OPENGL_GAL::initGlew()
}
}
initVertexBufferObjects
();
initVertexBufferObjects
();
computeCircleDisplayLists
();
isGlewInitialized
=
true
;
isGlewInitialized
=
true
;
}
}
...
@@ -1502,12 +1501,11 @@ void OPENGL_GAL::ChangeGroupDepth( int aGroupNumber, int aDepth )
...
@@ -1502,12 +1501,11 @@ void OPENGL_GAL::ChangeGroupDepth( int aGroupNumber, int aDepth )
}
}
void
OPENGL_GAL
::
compute
UnitCircle
()
void
OPENGL_GAL
::
compute
CircleVbo
()
{
{
displayListCircle
=
glGenLists
(
1
);
// (3 vertices per triangle) * (number of points to draw a circle)
glNewList
(
displayListCircle
,
GL_COMPILE
);
precomputedContainer
=
new
VBO_CONTAINER
(
3
*
CIRCLE_POINTS
);
verticesCircle
=
new
VBO_ITEM
(
precomputedContainer
);
glBegin
(
GL_TRIANGLES
);
// Compute the circle points for a given number of segments
// Compute the circle points for a given number of segments
// Insert in a display list and a vector
// Insert in a display list and a vector
...
@@ -1526,29 +1524,38 @@ void OPENGL_GAL::computeUnitCircle()
...
@@ -1526,29 +1524,38 @@ void OPENGL_GAL::computeUnitCircle()
0.0
f
// z
0.0
f
// z
};
};
glVertex2d
(
0
,
0
);
verticesCircle
->
PushVertex
(
&
v0
);
verticesCircle
->
PushVertex
(
&
v0
);
glVertex2d
(
v1
.
x
,
v1
.
y
);
verticesCircle
->
PushVertex
(
&
v1
);
verticesCircle
->
PushVertex
(
&
v1
);
glVertex2d
(
v2
.
x
,
v2
.
y
);
verticesCircle
->
PushVertex
(
&
v2
);
verticesCircle
->
PushVertex
(
&
v2
);
}
}
glEnd
();
verticesCircle
->
Finish
();
glEndList
();
}
}
void
OPENGL_GAL
::
compute
UnitSemiCircle
()
void
OPENGL_GAL
::
compute
CircleDisplayLists
()
{
{
// Circle display list
displayListCircle
=
glGenLists
(
1
);
glNewList
(
displayListCircle
,
GL_COMPILE
);
glBegin
(
GL_TRIANGLES
);
for
(
int
i
=
0
;
i
<
CIRCLE_POINTS
;
++
i
)
{
glVertex2d
(
0.0
,
0.0
);
glVertex2d
(
cos
(
2.0
*
M_PI
/
CIRCLE_POINTS
*
i
),
sin
(
2.0
*
M_PI
/
CIRCLE_POINTS
*
i
)
);
glVertex2d
(
cos
(
2.0
*
M_PI
/
CIRCLE_POINTS
*
(
i
+
1
)
),
sin
(
2.0
*
M_PI
/
CIRCLE_POINTS
*
(
i
+
1
)
)
);
}
glEnd
();
glEndList
();
// Semicircle display list
displayListSemiCircle
=
glGenLists
(
1
);
displayListSemiCircle
=
glGenLists
(
1
);
glNewList
(
displayListSemiCircle
,
GL_COMPILE
);
glNewList
(
displayListSemiCircle
,
GL_COMPILE
);
glBegin
(
GL_TRIANGLES
);
glBegin
(
GL_TRIANGLES
);
for
(
int
i
=
0
;
i
<
CIRCLE_POINTS
/
2
;
++
i
)
for
(
int
i
=
0
;
i
<
CIRCLE_POINTS
/
2
;
++
i
)
{
{
glVertex2d
(
0.0
,
0.0
);
glVertex2d
(
0.0
,
0.0
);
...
@@ -1557,9 +1564,7 @@ void OPENGL_GAL::computeUnitSemiCircle()
...
@@ -1557,9 +1564,7 @@ void OPENGL_GAL::computeUnitSemiCircle()
glVertex2d
(
cos
(
2.0
*
M_PI
/
CIRCLE_POINTS
*
(
i
+
1
)
),
glVertex2d
(
cos
(
2.0
*
M_PI
/
CIRCLE_POINTS
*
(
i
+
1
)
),
sin
(
2.0
*
M_PI
/
CIRCLE_POINTS
*
(
i
+
1
)
)
);
sin
(
2.0
*
M_PI
/
CIRCLE_POINTS
*
(
i
+
1
)
)
);
}
}
glEnd
();
glEnd
();
glEndList
();
glEndList
();
}
}
...
...
include/gal/opengl/opengl_gal.h
View file @
aff3787b
...
@@ -337,10 +337,10 @@ private:
...
@@ -337,10 +337,10 @@ private:
wxEvtHandler
*
mouseListener
;
wxEvtHandler
*
mouseListener
;
wxEvtHandler
*
paintListener
;
wxEvtHandler
*
paintListener
;
//
Display lists (used in shaderless
mode)
//
VBO buffers & display lists (used in immediate
mode)
VBO_CONTAINER
*
precomputedContainer
;
///< Container for storing display lists
VBO_CONTAINER
*
precomputedContainer
;
///< Container for storing display lists
VBO_ITEM
*
verticesCircle
;
///< Buffer for circle & semicircle vertices
GLuint
displayListCircle
;
///< Circle display list
GLuint
displayListCircle
;
///< Circle display list
VBO_ITEM
*
verticesCircle
;
GLuint
displayListSemiCircle
;
///< Semi circle display list
GLuint
displayListSemiCircle
;
///< Semi circle display list
// Vertex buffer objects related fields
// Vertex buffer objects related fields
...
@@ -391,7 +391,6 @@ private:
...
@@ -391,7 +391,6 @@ private:
GLuint
textureBackup
;
///< Backup texture handle
GLuint
textureBackup
;
///< Backup texture handle
// Internal flags
// Internal flags
bool
isCreated
;
bool
isGlewInitialized
;
///< Is GLEW initialized?
bool
isGlewInitialized
;
///< Is GLEW initialized?
bool
isFrameBufferInitialized
;
///< Are the frame buffers initialized?
bool
isFrameBufferInitialized
;
///< Are the frame buffers initialized?
bool
isVboInitialized
;
bool
isVboInitialized
;
...
@@ -412,14 +411,12 @@ private:
...
@@ -412,14 +411,12 @@ private:
void
drawFilledSemiCircle
(
const
VECTOR2D
&
aCenterPoint
,
double
aRadius
,
double
aAngle
);
void
drawFilledSemiCircle
(
const
VECTOR2D
&
aCenterPoint
,
double
aRadius
,
double
aAngle
);
void
drawStrokedSemiCircle
(
const
VECTOR2D
&
aCenterPoint
,
double
aRadius
,
double
aAngle
);
void
drawStrokedSemiCircle
(
const
VECTOR2D
&
aCenterPoint
,
double
aRadius
,
double
aAngle
);
/// Compute the points of a
unit circle
.
/// Compute the points of a
n unit circle & semicircle and store them in VBO
.
void
compute
UnitCircle
();
void
compute
CircleVbo
();
/// Compute the points of a unit semi circle.
/// Compute the points of an unit circle & semicircle and store them in display lists
void
computeUnitSemiCircle
();
/// for drawing in immediate mode.
void
computeCircleDisplayLists
();
/// Compute the points of a unit arc.
// void computeUnitArcs(); // TODO not used
// Event handling
// Event handling
/**
/**
...
...
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