Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
glow-extras
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nils Speetzen
glow-extras
Commits
4a664b55
Commit
4a664b55
authored
5 years ago
by
Philip Trettner
Browse files
Options
Downloads
Patches
Plain Diff
more 2D graphics
parent
22266479
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
vector/glow-extras/vector/graphics2D.hh
+58
-0
58 additions, 0 deletions
vector/glow-extras/vector/graphics2D.hh
with
58 additions
and
0 deletions
vector/glow-extras/vector/graphics2D.hh
+
58
−
0
View file @
4a664b55
...
...
@@ -17,6 +17,7 @@ struct stroke2D
stroke2D
()
=
default
;
stroke2D
(
tg
::
color3
const
&
c
)
:
color
(
c
,
1.0
f
),
width
(
1.0
f
)
{}
stroke2D
(
tg
::
color4
const
&
c
,
float
w
=
1.0
f
)
:
color
(
c
),
width
(
w
)
{}
stroke2D
(
float
r
,
float
g
,
float
b
,
float
a
=
1.0
f
)
:
color
(
r
,
g
,
b
,
a
),
width
(
1.0
f
)
{}
};
struct
fill2D
{
...
...
@@ -25,6 +26,7 @@ struct fill2D
fill2D
()
=
default
;
fill2D
(
tg
::
color4
const
&
c
)
:
color
(
c
)
{}
fill2D
(
tg
::
color3
const
&
c
)
:
color
(
c
)
{}
fill2D
(
float
r
,
float
g
,
float
b
,
float
a
=
1.0
f
)
:
color
(
r
,
g
,
b
,
a
)
{}
};
/// High-level API for writing to images
...
...
@@ -38,6 +40,11 @@ struct fill2D
/// Example:
/// g.draw(tg::pos3{...}, {1, 0, 0}); // 1px red dot
/// g.draw(tg::segment3{...}, {tg::color3::blue, 5.0f}); // 5px blue segment
///
/// TODO:
/// - infinite types like ray and line
/// - vectors
/// - think about customization points
struct
graphics2D
{
explicit
graphics2D
(
image2D
&
img
)
:
img
(
img
)
{}
...
...
@@ -66,6 +73,30 @@ public:
perform_draw
(
stroke
);
}
void
draw
(
tg
::
triangle2
const
&
t
,
stroke2D
const
&
stroke
)
{
img
.
begin_path
();
img
.
move_to
(
t
.
pos0
);
img
.
line_to
(
t
.
pos1
);
img
.
line_to
(
t
.
pos2
);
img
.
line_to
(
t
.
pos0
);
perform_draw
(
stroke
);
}
void
draw
(
tg
::
circle2
const
&
c
,
stroke2D
const
&
stroke
)
{
img
.
begin_path
();
img
.
circle
(
c
.
center
,
c
.
radius
);
perform_draw
(
stroke
);
}
void
draw
(
tg
::
sphere2
const
&
s
,
stroke2D
const
&
stroke
)
{
img
.
begin_path
();
img
.
circle
(
s
.
center
,
s
.
radius
);
perform_draw
(
stroke
);
}
// filling
public
:
void
fill
(
tg
::
aabb2
const
&
r
,
fill2D
const
&
fill
)
...
...
@@ -75,6 +106,33 @@ public:
perform_fill
(
fill
);
}
void
fill
(
tg
::
triangle2
const
&
t
,
fill2D
const
&
fill
)
{
img
.
begin_path
();
img
.
move_to
(
t
.
pos0
);
img
.
line_to
(
t
.
pos1
);
img
.
line_to
(
t
.
pos2
);
img
.
line_to
(
t
.
pos0
);
perform_fill
(
fill
);
}
void
fill
(
tg
::
circle2
const
&
c
,
fill2D
const
&
fill
)
{
img
.
begin_path
();
img
.
circle
(
c
.
center
,
c
.
radius
);
perform_fill
(
fill
);
}
void
fill
(
tg
::
sphere2
const
&
s
,
fill2D
const
&
fill
)
{
img
.
begin_path
();
img
.
circle
(
s
.
center
,
s
.
radius
);
perform_fill
(
fill
);
}
public
:
image2D_low_level_api
&
low_level_api
()
{
return
img
;
}
private
:
void
perform_draw
(
stroke2D
const
&
s
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment