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
Thomas Pitiot
CGoGN
Commits
dc3f8938
Commit
dc3f8938
authored
Jan 09, 2013
by
Thery Sylvain
Browse files
add texture sticker
parent
e3191ce5
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/Utils/textureSticker.h
0 → 100644
View file @
dc3f8938
/*******************************************************************************
* 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_TEXTURESTICKER_H_
#define _CGOGN_TEXTURESTICKER_H_
#include
"Utils/vbo.h"
#include
"Utils/Shaders/shaderSimpleTexture.h"
#include
"Utils/Shaders/shaderTextureDepth.h"
#include
"Utils/gl_def.h"
namespace
CGoGN
{
namespace
Utils
{
/**
* Static class that can be used to "stick" textures easily on the screen.
*/
class
TextureSticker
{
private
:
/**
* Constructor (not accesssible since the class is static).
*/
TextureSticker
();
/**
* Destructor (not accesssible since the class is static).
*/
~
TextureSticker
();
public
:
/**
* Sticks a texture on the whole screen.
* \param texId Id of the texture
*/
static
void
fullScreenTexture
(
CGoGNGLuint
texId
);
/**
* Sticks a texture on the whole screen.
* \param texId Id of the texture
* \param dtexId Id of the depth texture
*/
static
void
fullScreenTextureDepth
(
CGoGNGLuint
texId
,
CGoGNGLuint
dtexId
);
/**
* Draw a fullscreen quad with the specified shader.\n
* Uniforms other than matrices must have been sent to the shader before the call to this function.\n
* \param shader Shader that will be used to render the quad
*/
static
void
fullScreenShader
(
Utils
::
GLSLShader
*
shader
);
/**
* Get the Vbo of the vertices positions of the fullscreen quad.
* \returns Fullscreen quad vertices positions Vbo
*/
static
VBO
*
getPositionsVbo
();
/**
* Get the Vbo of the vertices tex coords of the fullscreen quad.
* \returns Fullscreen quad vertices tex coords Vbo
*/
static
VBO
*
getTexCoordsVbo
();
private
:
/**
* Initializes static elements of the class.\n
* Automatically called when it's needed.\n
*/
static
void
initializeElements
();
/// Indicates wether the static elements of the class were already initialized or not.
static
bool
sm_isInitialized
;
/// Vbo of the vertices positions of the fullscreen quad.
static
Utils
::
VBO
*
sm_quadPositionsVbo
;
/// Vbo of the vertices texture coords of the fullscreen quad.
static
Utils
::
VBO
*
sm_quadTexCoordsVbo
;
/// Shader for mapping the texture on the fullscreen quad.
static
Utils
::
ShaderSimpleTexture
*
sm_textureMappingShader
;
static
Utils
::
ShaderTextureDepth
*
sm_depthtextureMappingShader
;
};
}
// namespace Utils
}
// namespace CGoGN
#endif
src/Utils/textureSticker.cpp
0 → 100644
View file @
dc3f8938
/*******************************************************************************
* 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/textureSticker.h"
#include
"glm/glm.hpp"
#include
"glm/gtc/matrix_projection.hpp"
namespace
CGoGN
{
namespace
Utils
{
// Initialize static variables and constants
bool
TextureSticker
::
sm_isInitialized
=
false
;
Utils
::
VBO
*
TextureSticker
::
sm_quadPositionsVbo
=
NULL
;
Utils
::
VBO
*
TextureSticker
::
sm_quadTexCoordsVbo
=
NULL
;
Utils
::
ShaderSimpleTexture
*
TextureSticker
::
sm_textureMappingShader
=
NULL
;
Utils
::
ShaderTextureDepth
*
TextureSticker
::
sm_depthtextureMappingShader
=
NULL
;
TextureSticker
::
TextureSticker
()
{
}
TextureSticker
::~
TextureSticker
()
{
if
(
sm_textureMappingShader
!=
NULL
)
delete
sm_textureMappingShader
;
if
(
sm_depthtextureMappingShader
!=
NULL
)
delete
sm_depthtextureMappingShader
;
}
void
TextureSticker
::
fullScreenTexture
(
CGoGNGLuint
texId
)
{
glClear
(
GL_COLOR_BUFFER_BIT
);
// Check if TextureSticker's elements have been initialized before
if
(
!
sm_isInitialized
)
{
initializeElements
();
sm_isInitialized
=
true
;
}
// Check if depth test is enabled
GLboolean
wasDepthTestEnabled
=
glIsEnabled
(
GL_DEPTH_TEST
);
// Disable depth test if it was enabled
if
(
wasDepthTestEnabled
==
GL_TRUE
)
glDisable
(
GL_DEPTH_TEST
);
// Bind texture mapping shader
sm_textureMappingShader
->
bind
();
// Set texture uniform
sm_textureMappingShader
->
setTextureUnit
(
GL_TEXTURE0
);
sm_textureMappingShader
->
activeTexture
(
texId
);
// Set matrices uniforms
glm
::
mat4
projMatrix
=
glm
::
ortho
(
-
1.0
f
,
1.0
f
,
-
1.0
f
,
1.0
f
,
-
1.0
f
,
1.0
f
);
glm
::
mat4
viewMatrix
(
1.0
f
);
sm_textureMappingShader
->
updateMatrices
(
projMatrix
,
viewMatrix
);
// Draw quad
sm_textureMappingShader
->
enableVertexAttribs
();
glDrawArrays
(
GL_QUADS
,
0
,
4
);
sm_textureMappingShader
->
disableVertexAttribs
();
// Unbind texture mapping shader
sm_textureMappingShader
->
unbind
();
// Re-enable depth test if it was enabled before
if
(
wasDepthTestEnabled
==
GL_TRUE
)
glEnable
(
GL_DEPTH_TEST
);
}
void
TextureSticker
::
fullScreenTextureDepth
(
CGoGNGLuint
texId
,
CGoGNGLuint
dtexId
)
{
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
// Check if TextureSticker's elements have been initialized before
if
(
!
sm_isInitialized
)
{
initializeElements
();
sm_isInitialized
=
true
;
}
// Check if depth test is enabled
GLboolean
wasDepthTestEnabled
=
glIsEnabled
(
GL_DEPTH_TEST
);
// Disable depth test if it was enabled
// if (wasDepthTestEnabled == GL_TRUE)
// glDisable(GL_DEPTH_TEST);
// Bind texture mapping shader
sm_depthtextureMappingShader
->
bind
();
// Set texture uniform
sm_depthtextureMappingShader
->
setTextureUnit
(
GL_TEXTURE0
);
sm_depthtextureMappingShader
->
activeTexture
(
texId
);
sm_depthtextureMappingShader
->
setDepthTextureUnit
(
GL_TEXTURE1
);
sm_depthtextureMappingShader
->
activeDepthTexture
(
dtexId
);
// Set matrices uniforms
glm
::
mat4
projMatrix
=
glm
::
ortho
(
-
1.0
f
,
1.0
f
,
-
1.0
f
,
1.0
f
,
-
1.0
f
,
1.0
f
);
glm
::
mat4
viewMatrix
(
1.0
f
);
sm_depthtextureMappingShader
->
updateMatrices
(
projMatrix
,
viewMatrix
);
// Draw quad
sm_depthtextureMappingShader
->
enableVertexAttribs
();
glDrawArrays
(
GL_QUADS
,
0
,
4
);
sm_depthtextureMappingShader
->
disableVertexAttribs
();
// Unbind texture mapping shader
sm_depthtextureMappingShader
->
unbind
();
// Re-enable depth test if it was enabled before
// if (wasDepthTestEnabled == GL_TRUE)
// glEnable(GL_DEPTH_TEST);
}
void
TextureSticker
::
fullScreenShader
(
Utils
::
GLSLShader
*
shader
)
{
// Check if TextureSticker's elements have been initialized before
if
(
!
sm_isInitialized
)
{
initializeElements
();
sm_isInitialized
=
true
;
}
// Check if depth test is enabled
GLboolean
wasDepthTestEnabled
=
glIsEnabled
(
GL_DEPTH_TEST
);
// Disable depth test if it was enabled
if
(
wasDepthTestEnabled
==
GL_TRUE
)
glDisable
(
GL_DEPTH_TEST
);
// Bind shader
shader
->
bind
();
// Set matrices uniforms
glm
::
mat4
projMatrix
=
glm
::
ortho
(
-
1.0
f
,
1.0
f
,
-
1.0
f
,
1.0
f
,
-
1.0
f
,
1.0
f
);
glm
::
mat4
viewMatrix
(
1.0
f
);
shader
->
updateMatrices
(
projMatrix
,
viewMatrix
);
// Draw quad
shader
->
enableVertexAttribs
();
glDrawArrays
(
GL_QUADS
,
0
,
4
);
shader
->
disableVertexAttribs
();
// Unbind shader
shader
->
unbind
();
// Re-enable depth test if it was enabled before
if
(
wasDepthTestEnabled
==
GL_TRUE
)
glEnable
(
GL_DEPTH_TEST
);
}
VBO
*
TextureSticker
::
getPositionsVbo
()
{
// Check if TextureSticker's elements have been initialized before
if
(
!
sm_isInitialized
)
{
initializeElements
();
sm_isInitialized
=
true
;
// return NULL;
}
return
sm_quadPositionsVbo
;
}
VBO
*
TextureSticker
::
getTexCoordsVbo
()
{
// Check if TextureSticker's elements have been initialized before
if
(
!
sm_isInitialized
)
{
initializeElements
();
sm_isInitialized
=
true
;
// return NULL;
}
return
sm_quadTexCoordsVbo
;
}
void
TextureSticker
::
initializeElements
()
{
// Initialize positions and texture coords Vbos
sm_quadPositionsVbo
=
new
Utils
::
VBO
();
sm_quadTexCoordsVbo
=
new
Utils
::
VBO
();
sm_quadPositionsVbo
->
setDataSize
(
3
);
sm_quadTexCoordsVbo
->
setDataSize
(
2
);
sm_quadPositionsVbo
->
allocate
(
4
);
sm_quadTexCoordsVbo
->
allocate
(
4
);
GLfloat
positions
[]
=
{
-
1.0
f
,
-
1.0
f
,
0.0
f
,
+
1.0
f
,
-
1.0
f
,
0.0
f
,
+
1.0
f
,
+
1.0
f
,
0.0
f
,
-
1.0
f
,
+
1.0
f
,
0.0
f
};
GLfloat
texCoords
[]
=
{
0.0
f
,
0.0
f
,
1.0
f
,
0.0
f
,
1.0
f
,
1.0
f
,
0.0
f
,
1.0
f
};
GLfloat
*
positionsPtr
=
(
GLfloat
*
)
sm_quadPositionsVbo
->
lockPtr
();
memcpy
(
positionsPtr
,
positions
,
3
*
4
*
sizeof
(
GLfloat
));
sm_quadPositionsVbo
->
releasePtr
();
GLfloat
*
texCoordsPtr
=
(
GLfloat
*
)
sm_quadTexCoordsVbo
->
lockPtr
();
memcpy
(
texCoordsPtr
,
texCoords
,
2
*
4
*
sizeof
(
GLfloat
));
sm_quadTexCoordsVbo
->
releasePtr
();
// Initialize simple texture mapping shader
sm_textureMappingShader
=
new
Utils
::
ShaderSimpleTexture
();
sm_textureMappingShader
->
setAttributePosition
(
sm_quadPositionsVbo
);
sm_textureMappingShader
->
setAttributeTexCoord
(
sm_quadTexCoordsVbo
);
sm_depthtextureMappingShader
=
new
Utils
::
ShaderTextureDepth
();
sm_depthtextureMappingShader
->
setAttributePosition
(
sm_quadPositionsVbo
);
sm_depthtextureMappingShader
->
setAttributeTexCoord
(
sm_quadTexCoordsVbo
);
}
}
// 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