Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CGoGN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
David Cazier
CGoGN
Commits
8433dead
Commit
8433dead
authored
Nov 02, 2012
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add opacity option to String3D & Drawer
parent
00a97596
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
73 additions
and
13 deletions
+73
-13
include/Utils/Shaders/shaderColorPerVertex.frag
include/Utils/Shaders/shaderColorPerVertex.frag
+2
-1
include/Utils/Shaders/shaderColorPerVertex.h
include/Utils/Shaders/shaderColorPerVertex.h
+15
-1
include/Utils/drawer.h
include/Utils/drawer.h
+5
-0
include/Utils/text3d.frag
include/Utils/text3d.frag
+1
-1
include/Utils/text3d.h
include/Utils/text3d.h
+19
-3
src/Utils/Shaders/shaderColorPerVertex.cpp
src/Utils/Shaders/shaderColorPerVertex.cpp
+14
-0
src/Utils/drawer.cpp
src/Utils/drawer.cpp
+1
-1
src/Utils/text3d.cpp
src/Utils/text3d.cpp
+16
-6
No files found.
include/Utils/Shaders/shaderColorPerVertex.frag
View file @
8433dead
...
...
@@ -2,6 +2,7 @@
PRECISON
;
VARYING_FRAG
vec3
color
;
uniform
float
alpha
;
FRAG_OUT_DEF
;
void
main
()
{
...
...
@@ -9,5 +10,5 @@ void main()
if
(
dot
(
color
,
color
)
==
0
.
0
)
discard
;
#endif
gl_FragColor
=
vec4
(
color
,
0
.
0
);
gl_FragColor
=
vec4
(
color
,
alpha
);
}
include/Utils/Shaders/shaderColorPerVertex.h
View file @
8433dead
...
...
@@ -45,14 +45,28 @@ protected:
VBO
*
m_vboPos
;
VBO
*
m_vboCol
;
CGoGNGLuint
m_unif_alpha
;
float
m_opacity
;
void
restoreUniformsAttribs
();
public:
ShaderColorPerVertex
(
bool
black_is_transparent
=
false
);
unsigned
int
setAttributePosition
(
VBO
*
vbo
);
/**
* set the VBO of position (vec3)
*/
unsigned
int
setAttributePosition
(
VBO
*
vbo
);
/**
* set the VBO of color (vec3)
*/
unsigned
int
setAttributeColor
(
VBO
*
vbo
);
/**
* set opacity (0=transparent / 1=opaque)
*/
void
setOpacity
(
float
op
);
};
}
// namespace Utils
...
...
include/Utils/drawer.h
View file @
8433dead
...
...
@@ -131,6 +131,11 @@ public:
*/
void
callList
();
/**
* use as a glCallList
*/
void
callList
(
float
opacity
)
{
m_shader
->
setOpacity
(
opacity
);
callList
();
}
/**
* use as glLineWidth
*/
...
...
include/Utils/text3d.frag
View file @
8433dead
...
...
@@ -2,7 +2,7 @@
VARYING_FRAG
vec2
tex_coord
;
uniform
sampler2D
FontTexture
;
uniform
vec
3
color
;
uniform
vec
4
color
;
FRAG_OUT_DEF
;
void
main
(
void
)
{
...
...
include/Utils/text3d.h
View file @
8433dead
...
...
@@ -69,6 +69,8 @@ protected:
float
m_scale
;
Geom
::
Vec4f
m_color
;
unsigned
int
sendOneStringToVBO
(
const
std
::
string
&
str
,
float
**
buffer
);
CGoGNGLuint
m_idTexture
;
...
...
@@ -126,19 +128,33 @@ public:
* Draw all text stored with their position
* @param color the color of text
*/
void
drawAll
(
const
Geom
::
Vec3f
&
color
);
void
drawAll
(
const
Geom
::
Vec4f
&
color
);
void
drawAll
(
const
Geom
::
Vec3f
&
color
){
drawAll
(
Geom
::
Vec4f
(
color
[
0
],
color
[
1
],
color
[
2
],
1.0
f
));
}
/**
* call once before several draw(id,pos)
* @param color the color of text
*/
void
predraw
(
const
Geom
::
Vec3f
&
color
);
void
predraw
(
const
Geom
::
Vec4f
&
color
);
void
predraw
(
const
Geom
::
Vec3f
&
color
){
predraw
(
Geom
::
Vec4f
(
color
[
0
],
color
[
1
],
color
[
2
],
1.0
f
));
}
/**
* call just before a draw
* @param color the color of text
*/
void
changeColor
(
const
Geom
::
Vec3f
&
color
);
void
changeColor
(
const
Geom
::
Vec4f
&
color
);
void
changeColor
(
const
Geom
::
Vec3f
&
color
){
changeColor
(
Geom
::
Vec4f
(
color
[
0
],
color
[
1
],
color
[
2
],
1.0
f
));
}
/**
* change opacity but keep color (0 is totally transparent 1 is totally opaque)
* @param opacity
*/
void
changeOpacity
(
float
op
);
/**
* call once after several draw(id,pos)
...
...
src/Utils/Shaders/shaderColorPerVertex.cpp
View file @
8433dead
...
...
@@ -73,6 +73,11 @@ ShaderColorPerVertex::ShaderColorPerVertex(bool black_is_transparent)
glxfrag
.
append
(
fragmentShaderText
);
loadShadersFromMemory
(
glxvert
.
c_str
(),
glxfrag
.
c_str
());
*
m_unif_alpha
=
glGetUniformLocation
(
this
->
program_handler
(),
"alpha"
);
glUniform1f
(
*
m_unif_alpha
,
1.0
f
);
m_opacity
=
1.0
f
;
}
unsigned
int
ShaderColorPerVertex
::
setAttributePosition
(
VBO
*
vbo
)
...
...
@@ -92,7 +97,16 @@ void ShaderColorPerVertex::restoreUniformsAttribs()
bind
();
bindVA_VBO
(
"VertexPosition"
,
m_vboPos
);
bindVA_VBO
(
"VertexColor"
,
m_vboCol
);
glUniform1f
(
*
m_unif_alpha
,
m_opacity
);
unbind
();
}
void
ShaderColorPerVertex
::
setOpacity
(
float
op
)
{
bind
();
glUniform1f
(
*
m_unif_alpha
,
op
);
unbind
();
m_opacity
=
op
;
}
}
// namespace Utils
...
...
src/Utils/drawer.cpp
View file @
8433dead
...
...
@@ -166,7 +166,7 @@ void Drawer::updatePositions(unsigned int first, unsigned int nb, const float* P
}
void
Drawer
::
callList
()
void
Drawer
::
callList
(
float
opacity
)
{
if
(
m_begins
.
empty
())
return
;
...
...
src/Utils/text3d.cpp
View file @
8433dead
...
...
@@ -36,7 +36,7 @@ namespace Utils
std
::
string
Strings3D
::
fragmentShaderText2
=
" gl_FragColor =
vec4(color,0.0)
*lum;
\n
"
" gl_FragColor =
color
*lum;
\n
"
"}"
;
...
...
@@ -221,11 +221,12 @@ void Strings3D::sendToVBO()
glUnmapBuffer
(
GL_ARRAY_BUFFER
);
}
void
Strings3D
::
predraw
(
const
Geom
::
Vec
3
f
&
color
)
void
Strings3D
::
predraw
(
const
Geom
::
Vec
4
f
&
color
)
{
m_color
=
color
;
bind
();
glUniform1i
(
*
m_uniform_texture
,
0
);
glUniform
3
fv
(
*
m_uniform_color
,
1
,
color
.
data
());
glUniform
4
fv
(
*
m_uniform_color
,
1
,
color
.
data
());
glActiveTextureARB
(
GL_TEXTURE0_ARB
);
glBindTexture
(
GL_TEXTURE_2D
,
*
m_idTexture
);
...
...
@@ -236,10 +237,18 @@ void Strings3D::predraw(const Geom::Vec3f& color)
enableVertexAttribs
();
}
void
Strings3D
::
changeColor
(
const
Geom
::
Vec
3
f
&
color
)
void
Strings3D
::
changeColor
(
const
Geom
::
Vec
4
f
&
color
)
{
m_color
=
color
;
bind
();
glUniform3fv
(
*
m_uniform_color
,
1
,
color
.
data
());
glUniform4fv
(
*
m_uniform_color
,
1
,
color
.
data
());
}
void
Strings3D
::
changeOpacity
(
float
op
)
{
m_color
[
3
]
=
op
;
bind
();
glUniform4fv
(
*
m_uniform_color
,
1
,
m_color
.
data
());
}
void
Strings3D
::
postdraw
()
...
...
@@ -254,8 +263,9 @@ void Strings3D::draw(unsigned int idSt, const Geom::Vec3f& pos)
glDrawArrays
(
GL_QUADS
,
m_strpos
[
idSt
].
first
,
m_strpos
[
idSt
].
second
);
}
void
Strings3D
::
drawAll
(
const
Geom
::
Vec
3
f
&
color
)
void
Strings3D
::
drawAll
(
const
Geom
::
Vec
4
f
&
color
)
{
m_color
=
color
;
unsigned
int
nb
=
m_strpos
.
size
();
// nothing to do if no string !
if
(
nb
==
0
)
...
...
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