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
Model registry
Operate
Environments
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
Glow
glow-extras
Commits
22266479
Commit
22266479
authored
5 years ago
by
Philip Trettner
Browse files
Options
Downloads
Patches
Plain Diff
working on 2D api
parent
59b0f707
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
vector/glow-extras/vector/graphics2D.hh
+63
-1
63 additions, 1 deletion
vector/glow-extras/vector/graphics2D.hh
vector/glow-extras/vector/image2D.hh
+19
-0
19 additions, 0 deletions
vector/glow-extras/vector/image2D.hh
with
82 additions
and
1 deletion
vector/glow-extras/vector/graphics2D.hh
+
63
−
1
View file @
22266479
...
...
@@ -2,7 +2,7 @@
#include
"image2D.hh"
#include
<typed-geometry/tg
-lean
.hh>
#include
<typed-geometry/tg.hh>
namespace
glow
{
...
...
@@ -13,19 +13,81 @@ struct stroke2D
{
tg
::
color4
color
;
float
width
=
1.0
f
;
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
)
{}
};
struct
fill2D
{
tg
::
color4
color
;
fill2D
()
=
default
;
fill2D
(
tg
::
color4
const
&
c
)
:
color
(
c
)
{}
fill2D
(
tg
::
color3
const
&
c
)
:
color
(
c
)
{}
};
/// High-level API for writing to images
/// See Vector2DSample in glow-samples
///
/// Usage:
/// auto g = graphics(img);
/// g.draw(<tg-obj>, <stroke>);
/// g.fill(<tg-obj>, <fill>);
///
/// Example:
/// g.draw(tg::pos3{...}, {1, 0, 0}); // 1px red dot
/// g.draw(tg::segment3{...}, {tg::color3::blue, 5.0f}); // 5px blue segment
struct
graphics2D
{
explicit
graphics2D
(
image2D
&
img
)
:
img
(
img
)
{}
// drawing
public
:
void
draw
(
tg
::
pos2
const
&
p
,
stroke2D
const
&
stroke
)
{
img
.
begin_path
();
img
.
rect
({
p
-
.5
f
,
p
+
.5
f
});
perform_draw
(
stroke
);
}
void
draw
(
tg
::
segment2
const
&
s
,
stroke2D
const
&
stroke
)
{
img
.
begin_path
();
img
.
move_to
(
s
.
pos0
);
img
.
line_to
(
s
.
pos1
);
perform_draw
(
stroke
);
}
void
draw
(
tg
::
aabb2
const
&
r
,
stroke2D
const
&
stroke
)
{
img
.
begin_path
();
img
.
rect
(
r
);
perform_draw
(
stroke
);
}
// filling
public
:
void
fill
(
tg
::
aabb2
const
&
r
,
fill2D
const
&
fill
)
{
img
.
begin_path
();
img
.
rect
(
r
);
perform_fill
(
fill
);
}
private
:
void
perform_draw
(
stroke2D
const
&
s
)
{
img
.
set_stroke_color
(
s
.
color
);
img
.
set_stroke_width
(
s
.
width
);
img
.
stroke
();
}
void
perform_fill
(
fill2D
const
&
f
)
{
img
.
set_fill_color
(
f
.
color
);
img
.
fill
();
}
image2D_low_level_api
img
;
};
...
...
This diff is collapsed.
Click to expand it.
vector/glow-extras/vector/image2D.hh
+
19
−
0
View file @
22266479
...
...
@@ -7,6 +7,7 @@
#include
"cmd2D.hh"
#include
<typed-geometry/common/assert.hh>
#include
<typed-geometry/tg-lean.hh>
namespace
glow
{
...
...
@@ -83,6 +84,24 @@ struct image2D_low_level_api
void
clip_rect
(
float
x
,
float
y
,
float
w
,
float
h
)
{
img
<<
cmd2D
::
clip_rect
<<
x
<<
y
<<
w
<<
h
;
}
void
reset_clip
()
{
img
<<
cmd2D
::
reset_clip
;
}
// tg versions:
void
move_to
(
tg
::
pos2
const
&
p
)
{
move_to
(
p
.
x
,
p
.
y
);
}
void
line_to
(
tg
::
pos2
const
&
p
)
{
line_to
(
p
.
x
,
p
.
y
);
}
void
bezier_to
(
tg
::
pos2
const
&
c1
,
tg
::
pos2
const
&
c2
,
tg
::
pos2
const
&
p
)
{
bezier_to
(
c1
.
x
,
c1
.
y
,
c2
.
x
,
c2
.
y
,
p
.
x
,
p
.
y
);
}
void
quad_to
(
tg
::
pos2
const
&
c
,
tg
::
pos2
const
&
p
)
{
quad_to
(
c
.
x
,
c
.
y
,
p
.
x
,
p
.
y
);
}
void
arc_to
(
tg
::
pos2
const
&
p1
,
tg
::
pos2
const
&
p2
,
float
radius
)
{
arc_to
(
p1
.
x
,
p1
.
y
,
p2
.
x
,
p2
.
y
,
radius
);
}
// TODO: arc, rounded_rect_varying, ellipse
void
rect
(
tg
::
aabb2
const
&
r
)
{
rect
(
r
.
min
.
x
,
r
.
min
.
y
,
r
.
max
.
x
-
r
.
min
.
x
,
r
.
max
.
y
-
r
.
min
.
y
);
}
void
rounded_rect
(
tg
::
aabb2
const
&
r
,
float
radius
)
{
rounded_rect
(
r
.
min
.
x
,
r
.
min
.
y
,
r
.
max
.
x
-
r
.
min
.
x
,
r
.
max
.
y
-
r
.
min
.
y
,
radius
);
}
void
circle
(
tg
::
pos2
const
&
p
,
float
r
)
{
circle
(
p
.
x
,
p
.
y
,
r
);
}
void
set_stroke_color
(
tg
::
color4
const
&
c
)
{
set_stroke_color
(
c
.
r
,
c
.
g
,
c
.
b
,
c
.
a
);
}
void
set_fill_color
(
tg
::
color4
const
&
c
)
{
set_fill_color
(
c
.
r
,
c
.
g
,
c
.
b
,
c
.
a
);
}
void
clip_rect
(
tg
::
aabb2
const
&
r
)
{
clip_rect
(
r
.
min
.
x
,
r
.
min
.
y
,
r
.
max
.
x
-
r
.
min
.
x
,
r
.
max
.
y
-
r
.
min
.
y
);
}
private
:
image2D
&
img
;
};
...
...
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