Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Hurstel
CGoGN
Commits
7b603570
Commit
7b603570
authored
Jul 11, 2014
by
Sylvain Thery
Browse files
wall paper shader
parent
735e431d
Changes
9
Hide whitespace changes
Inline
Side-by-side
Apps/Examples/texturesExample.cpp
View file @
7b603570
...
...
@@ -58,15 +58,22 @@ void TexView::cb_initGL()
m_texture
=
new
Utils
::
Texture
<
2
,
Geom
::
Vec3uc
>
(
GL_UNSIGNED_BYTE
);
m_textureWP
=
new
Utils
::
Texture
<
2
,
Geom
::
Vec3uc
>
(
GL_UNSIGNED_BYTE
);
if
(
m_texture
->
load
(
m_fileNameTex
))
m_texture
->
update
();
else
computeImage
();
// CGoGNerr << "Problem loading image"<< CGoGNendl;
computeImage
();
m_texture
->
setWrapping
(
GL_CLAMP_TO_EDGE
);
m_texture
->
update
();
computeImage
();
m_textureWP
->
setWrapping
(
GL_CLAMP_TO_EDGE
);
m_textureWP
->
update
();
m_shader
=
new
Utils
::
ShaderSimpleTexture
();
m_shader
->
setAttributePosition
(
m_positionVBO
);
m_shader
->
setAttributeTexCoord
(
m_texcoordVBO
);
...
...
@@ -85,6 +92,12 @@ void TexView::cb_initGL()
m_shader2
->
setSpecular
(
Geom
::
Vec4f
(
0.5
));
registerShader
(
m_shader2
);
m_shaderWP
=
new
Utils
::
ShaderWallPaper
();
m_shaderWP
->
setTextureUnit
(
GL_TEXTURE2
);
m_shaderWP
->
setTexture
(
m_textureWP
);
registerShader
(
m_shaderWP
);
glEnable
(
GL_TEXTURE_2D
);
if
(
!
m_obj
.
hasNormals
())
...
...
@@ -104,6 +117,8 @@ void TexView::cb_redraw()
{
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_FILL
);
m_shaderWP
->
draw
();
if
(
m_phong
)
{
m_shader2
->
activeTexture
();
...
...
@@ -187,16 +202,27 @@ void TexView::computeImage()
colorTable
.
push_back
(
Geom
::
Vec3uc
(
0
,
255
,
255
));
colorTable
.
push_back
(
Geom
::
Vec3uc
(
255
,
255
,
255
));
m_texture
->
create
(
Geom
::
Vec2ui
(
512
,
512
));
// m_texture->create(Geom::Vec2ui(512,512));
m_textureWP
->
create
(
Geom
::
Vec2ui
(
512
,
512
));
#define WIDTHCHECKER 20
for
(
unsigned
int
ki
=
0
;
ki
<
m_texture
->
size
()[
0
];
++
ki
)
// for (unsigned int ki = 0; ki < m_texture->size()[0]; ++ki)
// {
// for (unsigned int kj = 0; kj < m_texture->size()[1]; ++kj)
// {
// unsigned int kc = ((kj/WIDTHCHECKER)*m_texture->size()[0] + (ki/WIDTHCHECKER))%7;
// (*m_texture)(ki,kj) =colorTable[kc];
// }
// }
for
(
unsigned
int
ki
=
0
;
ki
<
m_textureWP
->
size
()[
0
];
++
ki
)
{
for
(
unsigned
int
kj
=
0
;
kj
<
m_texture
->
size
()[
1
];
++
kj
)
for
(
unsigned
int
kj
=
0
;
kj
<
m_texture
WP
->
size
()[
1
];
++
kj
)
{
unsigned
int
kc
=
((
kj
/
WIDTHCHECKER
)
*
m_texture
->
size
()[
0
]
+
(
ki
/
WIDTHCHECKER
))
%
7
;
(
*
m_texture
)(
ki
,
kj
)
=
colorTable
[
kc
];
unsigned
int
kc
=
((
kj
/
WIDTHCHECKER
)
*
m_texture
WP
->
size
()[
0
]
+
(
ki
/
WIDTHCHECKER
))
%
7
;
(
*
m_texture
WP
)(
ki
,
kj
)
=
colorTable
[
kc
];
}
}
#undef WIDTHCHECKER
...
...
Apps/Examples/texturesExample.h
View file @
7b603570
...
...
@@ -36,6 +36,8 @@
#include
"Algo/Render/GL2/mapRender.h"
#include
"Algo/Import/importObjTex.h"
#include
"Utils/Shaders/shaderWallPaper.h"
// forward definitions (minimize includes)
namespace
CGoGN
{
namespace
Algo
{
namespace
Render
{
namespace
GL2
{
class
MapRender
;
}}}}
...
...
@@ -74,10 +76,13 @@ public:
unsigned
int
m_nbIndices
;
Utils
::
Texture
<
2
,
Geom
::
Vec3uc
>*
m_texture
;
Utils
::
Texture
<
2
,
Geom
::
Vec3uc
>*
m_textureWP
;
// shader simple texture
Utils
::
ShaderSimpleTexture
*
m_shader
;
Utils
::
ShaderPhongTexture
*
m_shader2
;
Utils
::
ShaderWallPaper
*
m_shaderWP
;
bool
m_phong
;
...
...
Apps/SandBox/CMakeLists.txt
View file @
7b603570
...
...
@@ -41,6 +41,10 @@ QT4_WRAP_CPP(testPlaneCutting_moc testPlaneCutting.h)
add_executable
(
testPlaneCutting testPlaneCutting.cpp
${
testPlaneCutting_ui
}
${
testPlaneCutting_moc
}
)
target_link_libraries
(
testPlaneCutting
${
CGoGN_LIBS_D
}
${
CGoGN_EXT_LIBS
}
)
QT4_WRAP_CPP
(
wallPaper_moc wallPaper.h
)
add_executable
(
wallPaper wallPaper.cpp
${
wallPaper_moc
}
)
target_link_libraries
(
wallPaper
${
CGoGN_LIBS_D
}
${
CGoGN_EXT_LIBS
}
)
# Example with Qt
#
#QT4_WRAP_CPP(tuto1_moc tuto1.h)
...
...
Apps/SandBox/wallPaper.cpp
0 → 100644
View file @
7b603570
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include
"wallPaper.h"
#include
"Algo/Tiling/Surface/square.h"
using
namespace
CGoGN
;
void
MyQT
::
cb_initGL
()
{
position
=
myMap
.
addAttribute
<
PFP
::
VEC3
,
VERTEX
,
MAP
>
(
"position"
);
Algo
::
Surface
::
Tilings
::
Square
::
Cylinder
<
PFP
>
c
(
myMap
,
20
,
20
);
c
.
embedIntoCylinder
(
position
,
0.5
,
0.7
,
1.0
);
Geom
::
BoundingBox
<
PFP
::
VEC3
>
bb
=
Algo
::
Geometry
::
computeBoundingBox
<
PFP
>
(
myMap
,
position
);
float
lWidthObj
=
std
::
max
<
PFP
::
REAL
>
(
std
::
max
<
PFP
::
REAL
>
(
bb
.
size
(
0
),
bb
.
size
(
1
)),
bb
.
size
(
2
));
Geom
::
Vec3f
lPosObj
=
(
bb
.
min
()
+
bb
.
max
())
/
PFP
::
REAL
(
2
);
setParamObject
(
lWidthObj
,
lPosObj
.
data
());
Utils
::
GLSLShader
::
setCurrentOGLVersion
(
2
);
// create the render
m_render
=
new
Algo
::
Render
::
GL2
::
MapRender
();
// create VBO for position
m_positionVBO
=
new
Utils
::
VBO
();
m_positionVBO
->
updateData
(
position
);
m_shader
=
new
Utils
::
ShaderSimpleColor
();
m_shader
->
setAttributePosition
(
m_positionVBO
);
m_shader
->
setColor
(
Geom
::
Vec4f
(
1.0
,
0.0
,
0.0
,
0.
));
m_render
->
initPrimitives
<
PFP
>
(
myMap
,
Algo
::
Render
::
GL2
::
LINES
);
registerShader
(
m_shader
);
// FOR WALL PAPER
m_textureWP
=
new
Utils
::
Texture
<
2
,
Geom
::
Vec3uc
>
(
GL_UNSIGNED_BYTE
);
if
(
!
m_textureWP
->
load
(
"../SCHNApps/resources/cgogn/cgogn2.png"
))
computeTexture
();
m_textureWP
->
update
();
m_textureWP
->
setWrapping
(
GL_CLAMP_TO_EDGE
);
m_shaderWP
=
new
Utils
::
ShaderWallPaper
();
m_shaderWP
->
setTextureUnit
(
GL_TEXTURE0
);
m_shaderWP
->
setTexture
(
m_textureWP
);
registerShader
(
m_shaderWP
);
glEnable
(
GL_TEXTURE_2D
);
}
void
MyQT
::
cb_redraw
()
{
// FOR WALL PAPER
m_render
->
draw
(
m_shader
,
Algo
::
Render
::
GL2
::
LINES
);
m_shaderWP
->
draw
();
}
void
MyQT
::
cb_keyPress
(
int
keycode
)
{
switch
(
keycode
)
{
case
'l'
:
if
(
m_textureWP
->
load
(
"../SCHNApps/resources/cgogn/cgogn2.png"
))
m_textureWP
->
update
();
m_textureWP
->
setWrapping
(
GL_CLAMP_TO_EDGE
);
break
;
case
'c'
:
computeTexture
();
m_textureWP
->
update
();
m_textureWP
->
setWrapping
(
GL_CLAMP_TO_EDGE
);
break
;
}
updateGL
();
}
void
MyQT
::
computeTexture
()
{
std
::
vector
<
Geom
::
Vec3f
>
colorTable
;
colorTable
.
push_back
(
Geom
::
Vec3uc
(
255
,
0
,
0
));
colorTable
.
push_back
(
Geom
::
Vec3uc
(
0
,
255
,
0
));
colorTable
.
push_back
(
Geom
::
Vec3uc
(
0
,
0
,
255
));
colorTable
.
push_back
(
Geom
::
Vec3uc
(
255
,
255
,
0
));
colorTable
.
push_back
(
Geom
::
Vec3uc
(
255
,
0
,
255
));
colorTable
.
push_back
(
Geom
::
Vec3uc
(
0
,
255
,
255
));
colorTable
.
push_back
(
Geom
::
Vec3uc
(
255
,
255
,
255
));
m_textureWP
->
create
(
Geom
::
Vec2ui
(
16
,
16
));
#define WIDTHCHECKER 2
for
(
unsigned
int
ki
=
0
;
ki
<
m_textureWP
->
size
()[
0
];
++
ki
)
{
for
(
unsigned
int
kj
=
0
;
kj
<
m_textureWP
->
size
()[
1
];
++
kj
)
{
unsigned
int
kc
=
((
kj
/
WIDTHCHECKER
)
*
m_textureWP
->
size
()[
0
]
+
(
ki
/
WIDTHCHECKER
))
%
7
;
(
*
m_textureWP
)(
ki
,
kj
)
=
colorTable
[
kc
];
}
}
#undef WIDTHCHECKER
}
int
main
(
int
argc
,
char
**
argv
)
{
// interface:
QApplication
app
(
argc
,
argv
);
MyQT
sqt
;
sqt
.
show
();
return
app
.
exec
();
}
Apps/SandBox/wallPaper.h
0 → 100644
View file @
7b603570
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef TUTO_WALLPAPER_H
#define TUTO_WALLPAPER_H
#include
<iostream>
#include
"Utils/Qt/qtQGLV.h"
#include
"Topology/generic/parameters.h"
#include
"Topology/map/embeddedMap2.h"
#include
"Geometry/vector_gen.h"
#include
"Algo/Geometry/boundingbox.h"
#include
"Algo/Render/GL2/mapRender.h"
#include
"Utils/Shaders/shaderSimpleColor.h"
#include
"Utils/vbo.h"
#include
"Utils/cgognStream.h"
#include
"Utils/Shaders/shaderWallPaper.h"
using
namespace
CGoGN
;
struct
PFP
:
public
PFP_STANDARD
{
// definition of the map
typedef
EmbeddedMap2
MAP
;
};
typedef
PFP
::
MAP
MAP
;
typedef
PFP
::
VEC3
VEC3
;
/**
* A class for a little interface and rendering
*/
class
MyQT
:
public
Utils
::
QT
::
SimpleQGLV
{
Q_OBJECT
public:
MAP
myMap
;
VertexAttribute
<
VEC3
,
MAP
>
position
;
Algo
::
Render
::
GL2
::
MapRender
*
m_render
;
Utils
::
VBO
*
m_positionVBO
;
Utils
::
ShaderSimpleColor
*
m_shader
;
// FOR WALL PAPER
Utils
::
Texture
<
2
,
Geom
::
Vec3uc
>*
m_textureWP
;
Utils
::
ShaderWallPaper
*
m_shaderWP
;
MyQT
()
:
m_render
(
NULL
),
m_positionVBO
(
NULL
),
m_shader
(
NULL
),
m_shaderWP
(
NULL
)
{}
protected:
void
cb_redraw
();
void
cb_initGL
();
void
cb_keyPress
(
int
keycode
);
void
computeTexture
();
};
#endif // TUTO_TILINGS_H
include/Utils/Shaders/shaderWallPaper.frag
0 → 100644
View file @
7b603570
// ShaderWallPaper::fragmentShaderText
PRECISON
;
VARYING_FRAG
vec2
texCoord
;
uniform
sampler2D
textureUnit
;
FRAG_OUT_DEF
;
void
main
()
{
gl_FragColor
=
texture2D
(
textureUnit
,
texCoord
);
}
include/Utils/Shaders/shaderWallPaper.h
0 → 100644
View file @
7b603570
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __CGOGN_SHADER_WALLPAPER__
#define __CGOGN_SHADER_WALLPAPER__
#include
"Geometry/vector_gen.h"
#include
"Utils/GLSLShader.h"
#include
"Utils/clippingShader.h"
#include
"Utils/textures.h"
#include
"Utils/gl_def.h"
namespace
CGoGN
{
namespace
Utils
{
class
ShaderWallPaper
:
public
ClippingShader
{
protected:
// shader sources
static
std
::
string
vertexShaderText
;
static
std
::
string
fragmentShaderText
;
CGoGNGLuint
m_unif_unit
;
int
m_unit
;
Utils
::
GTexture
*
m_tex_ptr
;
VBO
*
m_vboPos
;
VBO
*
m_vboTexCoord
;
void
restoreUniformsAttribs
();
public:
ShaderWallPaper
();
~
ShaderWallPaper
();
/**
* choose the texture unit engine to use for this texture
*/
void
setTextureUnit
(
GLenum
texture_unit
);
/**
* set the texture to use
*/
void
setTexture
(
Utils
::
GTexture
*
tex
);
/**
* activation of texture unit with set texture
*/
void
activeTexture
();
/**
* activation of texture unit with texture id
*/
void
activeTexture
(
CGoGNGLuint
texId
);
/**
* @brief draw the quad as wallpaper
*/
void
draw
();
};
}
// namespace Utils
}
// namespace CGoGN
#endif
/* __CGOGN_SHADER_SIMPLETEXTURE__ */
include/Utils/Shaders/shaderWallPaper.vert
0 → 100644
View file @
7b603570
// ShaderWallPaper::vertexShaderText
ATTRIBUTE
vec3
VertexPosition
;
ATTRIBUTE
vec2
VertexTexCoord
;
VARYING_VERT
vec2
texCoord
;
INVARIANT_POS
;
void
main
()
{
gl_Position
=
vec4
(
VertexPosition
,
1
.
0
);
texCoord
=
VertexTexCoord
;
}
src/Utils/Shaders/shaderWallPaper.cpp
0 → 100644
View file @
7b603570
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include
<GL/glew.h>
#include
"Utils/Shaders/shaderWallPaper.h"
namespace
CGoGN
{
namespace
Utils
{
#include
"shaderWallPaper.vert"
#include
"shaderWallPaper.frag"
ShaderWallPaper
::
ShaderWallPaper
()
:
m_tex_ptr
(
NULL
)
{
std
::
string
glxvert
(
*
GLSLShader
::
DEFINES_GL
);
glxvert
.
append
(
vertexShaderText
);
std
::
string
glxfrag
(
*
GLSLShader
::
DEFINES_GL
);
glxfrag
.
append
(
fragmentShaderText
);
loadShadersFromMemory
(
glxvert
.
c_str
(),
glxfrag
.
c_str
());
m_unif_unit
=
glGetUniformLocation
(
this
->
program_handler
(),
"textureUnit"
);
m_vboPos
=
new
Utils
::
VBO
();
m_vboPos
->
setDataSize
(
3
);
m_vboPos
->
allocate
(
4
);
Geom
::
Vec3f
*
ptrPos
=
reinterpret_cast
<
Geom
::
Vec3f
*>
(
m_vboPos
->
lockPtr
());
ptrPos
[
0
]
=
Geom
::
Vec3f
(
-
1
,
-
1
,
0.9999999
);
ptrPos
[
1
]
=
Geom
::
Vec3f
(
1
,
-
1
,
0.9999999
);
ptrPos
[
2
]
=
Geom
::
Vec3f
(
1
,
1
,
0.9999999
);
ptrPos
[
3
]
=
Geom
::
Vec3f
(
-
1
,
1
,
0.9999999
);
m_vboPos
->
releasePtr
();
bindVA_VBO
(
"VertexPosition"
,
m_vboPos
);
m_vboTexCoord
=
new
Utils
::
VBO
();
m_vboTexCoord
->
setDataSize
(
2
);
m_vboTexCoord
=
new
Utils
::
VBO
();
m_vboTexCoord
->
setDataSize
(
2
);
m_vboTexCoord
->
allocate
(
4
);
Geom
::
Vec2f
*
ptrTex
=
reinterpret_cast
<
Geom
::
Vec2f
*>
(
m_vboTexCoord
->
lockPtr
());
ptrTex
[
0
]
=
Geom
::
Vec2f
(
0.0
,
0.0
);
ptrTex
[
1
]
=
Geom
::
Vec2f
(
1.0
,
0.0
);
ptrTex
[
2
]
=
Geom
::
Vec2f
(
1.0
,
1.0
);
ptrTex
[
3
]
=
Geom
::
Vec2f
(
0.0
,
1.0
);
m_vboTexCoord
->
releasePtr
();
bindVA_VBO
(
"VertexTexCoord"
,
m_vboTexCoord
);
}
ShaderWallPaper
::~
ShaderWallPaper
()
{
delete
m_vboPos
;
delete
m_vboTexCoord
;
}
void
ShaderWallPaper
::
setTextureUnit
(
GLenum
texture_unit
)
{
this
->
bind
();
int
unit
=
texture_unit
-
GL_TEXTURE0
;
glUniform1iARB
(
*
m_unif_unit
,
unit
);
m_unit
=
unit
;
}
void
ShaderWallPaper
::
setTexture
(
Utils
::
GTexture
*
tex
)
{
m_tex_ptr
=
tex
;
}
void
ShaderWallPaper
::
activeTexture
()
{
glActiveTexture
(
GL_TEXTURE0
+
m_unit
);
m_tex_ptr
->
bind
();
}
void
ShaderWallPaper
::
activeTexture
(
CGoGNGLuint
texId
)
{
glActiveTexture
(
GL_TEXTURE0
+
m_unit
);
glBindTexture
(
GL_TEXTURE_2D
,
*
texId
);
}
void
ShaderWallPaper
::
restoreUniformsAttribs
()
{
m_unif_unit
=
glGetUniformLocation
(
this
->
program_handler
(),
"textureUnit"
);
bindVA_VBO
(
"VertexPosition"
,
m_vboPos
);
bindVA_VBO
(
"VertexTexCoord"
,
m_vboTexCoord
);
this
->
bind
();
glUniform1iARB
(
*
m_unif_unit
,
m_unit
);
this
->
unbind
();
}
void
ShaderWallPaper
::
draw
()
{
this
->
activeTexture
();
this
->
enableVertexAttribs
();
glDrawArrays
(
GL_QUADS
,
0
,
4
);
this
->
disableVertexAttribs
();
}
}
// namespace Utils
}
// namespace CGoGN
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment