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
CGoGN
CGoGN
Commits
47c6a626
Commit
47c6a626
authored
Jul 28, 2011
by
Kenneth Vanhoey
Browse files
rm texture.h*
parent
19782a24
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/Utils/texture.h
deleted
100644 → 0
View file @
19782a24
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef TEXTURE_RENDER
#define TEXTURE_RENDER
#include
<GL/gl.h>
#include
<IL/ilu.h>
/**
* A set of function that allow the creation of rendering
* object using Vertex-Buffer-Object.
* Function are made for dual-2-map and can be used on
* any subset of a dual-N-map which is a 2-map
*/
namespace
CGoGN
{
namespace
Utils
{
template
<
typename
T
>
class
Texture
{
protected:
/**
* buffer of texture image
*/
T
*
m_data
;
/**
* width of texture
*/
int
m_width
;
/**
* height of image
*/
int
m_height
;
/**
* number of component by pixel
*/
int
m_cpp
;
/**
* name of DevIL image
*/
ILuint
m_ilName
;
/**
* name of OGL texture
*/
GLuint
m_texName
;
/**
* uniform variable for texture name in shader
*/
GLuint
m_uniform_tex
;
public:
/**
* constructor
*/
Texture
();
/**
* constructor
*/
~
Texture
();
/**
* constructor from image filename
* @param filename name of an image file (all format accepted: png, jpg, ....)
*/
Texture
(
std
::
string
fileName
);
/**
* constructor from data
* @param prt pointer on data
* @param w width in pixels
* @param h height in pixels
* @param cpp cnumber of components per pixel
*/
Texture
(
T
*
ptr
,
int
w
,
int
h
,
int
cpp
);
/**
* loaf an image filename
* @param filename name of an image file (all format accepted: png, jpg, ....)
*/
void
load
(
std
::
string
fileName
);
/**
* set data
* @param prt pointer on data
* @param w width in pixels
* @param h height in pixels
* @param cpp cnumber of components per pixel
*/
void
setData
(
T
*
ptr
,
int
w
,
int
h
,
int
cpp
);
/**
* get the width of texture
* @return width of texture
*/
int
getWidth
()
{
return
m_width
;
}
/**
* get the height of texture
* @return height of texture
*/
int
getHeight
()
{
return
m_height
;
}
/**
* get the number of component per pixel
* @return component per pixel
*/
int
getCPP
()
{
return
m_cpp
;
}
/**
* get a pointer on texture image
*/
T
*
getPtr
()
{
return
m_data
;
}
/**
* get texture name
*/
GLuint
getTextureName
()
{
return
m_texName
;
}
/**
* initialisation GL
* @param filter filter parameter GL_NEAREST,GL_LINEAR,...
* @param format format of texture GL_RGB,GL_RGBA,GL_LUMINANCE,...
* @param prg shader program handler
*/
void
initGL
(
GLint
filter
,
GLenum
format
,
const
char
*
uniformName
,
GLuint
prg
);
/**
* fonction to call before drawing
* @param textureEngineIndex index of multitexture engine (0,1, ...
*/
void
useGL
(
unsigned
int
textureEngineIndex
);
};
}
// namespace utils
}
// namespace CGoGN
#include
"texture.hpp"
#endif
include/Utils/texture.hpp
deleted
100644 → 0
View file @
19782a24
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include
<vector>
#include
<typeinfo>
#include
"Utils/os_spec.h"
namespace
CGoGN
{
namespace
Utils
{
template
<
typename
T
>
Texture
<
T
>::
Texture
()
{
m_data
=
NULL
;
m_width
=
0
;
m_height
=
0
;
m_cpp
=
0
;
m_ilName
=
0
;
m_texName
=
0
;
}
template
<
typename
T
>
Texture
<
T
>::
Texture
(
std
::
string
fileName
)
{
ilInit
();
iluInit
();
ilOriginFunc
(
IL_ORIGIN_LOWER_LEFT
);
ilEnable
(
IL_ORIGIN_SET
);
ilGenImages
(
1
,
&
m_ilName
);
ilBindImage
(
m_ilName
);
ilLoadImage
(
fileName
.
c_str
());
// get the info of image
m_width
=
ilGetInteger
(
IL_IMAGE_WIDTH
);
m_height
=
ilGetInteger
(
IL_IMAGE_HEIGHT
);
m_cpp
=
ilGetInteger
(
IL_IMAGE_BYTES_PER_PIXEL
)
/
sizeof
(
T
);
m_data
=
reinterpret_cast
<
T
*>
(
ilGetData
());
m_texName
=
0
;
}
template
<
typename
T
>
Texture
<
T
>::
Texture
(
T
*
ptr
,
int
w
,
int
h
,
int
cpp
)
{
m_data
=
new
T
[
w
*
h
*
cpp
];
m_width
=
w
;
m_height
=
h
;
m_cpp
=
cpp
;
m_ilName
=
0
;
m_texName
=
0
;
}
template
<
typename
T
>
void
Texture
<
T
>::
load
(
std
::
string
fileName
)
{
if
(
m_ilName
!=
0
)
ilDeleteImages
(
1
,
&
m_ilName
);
else
if
(
m_data
!=
0
)
delete
[]
m_data
;
if
(
m_texName
!=
0
)
glDeleteTextures
(
1
,
&
m_texName
);
ilInit
();
iluInit
();
ilOriginFunc
(
IL_ORIGIN_LOWER_LEFT
);
ilEnable
(
IL_ORIGIN_SET
);
ilGenImages
(
1
,
&
m_ilName
);
ilBindImage
(
m_ilName
);
ilLoadImage
(
fileName
.
c_str
());
// get the info of image
m_width
=
ilGetInteger
(
IL_IMAGE_WIDTH
);
m_height
=
ilGetInteger
(
IL_IMAGE_HEIGHT
);
m_cpp
=
ilGetInteger
(
IL_IMAGE_BYTES_PER_PIXEL
)
/
sizeof
(
T
);
m_data
=
reinterpret_cast
<
T
*>
(
ilGetData
());
m_texName
=
0
;
}
template
<
typename
T
>
void
Texture
<
T
>::
setData
(
T
*
ptr
,
int
w
,
int
h
,
int
cpp
)
{
if
(
m_ilName
!=
0
)
ilDeleteImages
(
1
,
&
m_ilName
);
else
if
(
m_data
!=
0
)
delete
[]
m_data
;
if
(
m_texName
!=
0
)
glDeleteTextures
(
1
,
&
m_texName
);
m_data
=
new
T
[
w
*
h
*
cpp
];
m_width
=
w
;
m_height
=
h
;
m_cpp
=
cpp
;
m_ilName
=
0
;
m_texName
=
0
;
}
template
<
typename
T
>
Texture
<
T
>::~
Texture
()
{
if
(
m_ilName
!=
0
)
ilDeleteImages
(
1
,
&
m_ilName
);
else
if
(
m_data
!=
0
)
delete
[]
m_data
;
if
(
m_texName
!=
0
)
glDeleteTextures
(
1
,
&
m_texName
);
}
template
<
typename
T
>
void
Texture
<
T
>::
initGL
(
GLint
filter
,
GLenum
format
,
const
char
*
uniformName
,
GLuint
prg
)
{
// allocate a texture name
glGenTextures
(
1
,
&
m_texName
);
// select our current texture
glBindTexture
(
GL_TEXTURE_2D
,
m_texName
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
filter
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
filter
);
// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
GLenum
ptype
;
if
(
typeid
(
T
)
==
typeid
(
unsigned
char
))
ptype
=
GL_UNSIGNED_BYTE
;
if
(
typeid
(
T
)
==
typeid
(
unsigned
short
))
ptype
=
GL_UNSIGNED_SHORT
;
if
(
typeid
(
T
)
==
typeid
(
unsigned
int
))
ptype
=
GL_UNSIGNED_INT
;
if
(
typeid
(
T
)
==
typeid
(
float
))
ptype
=
GL_FLOAT
;
switch
(
format
)
{
case
GL_RGB
:
if
(
m_cpp
!=
3
)
CGoGNout
<<
"Warning using GL_RGB with image not in RGB format"
<<
CGoGNendl
;
break
;
case
GL_LUMINANCE
:
if
(
m_cpp
!=
1
)
CGoGNout
<<
"Warning using GL_LUMINANCE with image not in grey level format"
<<
CGoGNendl
;
break
;
}
glPixelStorei
(
GL_UNPACK_ALIGNMENT
,
1
);
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
m_cpp
,
m_width
,
m_height
,
0
,
format
,
ptype
,
m_data
);
// glTexImage2D (GL_TEXTURE_2D, 0, m_cpp, m_width, m_height, 0 , GL_RGB, GL_UNSIGNED_BYTE , m_data);
m_uniform_tex
=
glGetUniformLocationARB
(
prg
,
uniformName
);
}
template
<
typename
T
>
void
Texture
<
T
>::
useGL
(
unsigned
int
textureEngineIndex
)
{
glActiveTextureARB
(
GL_TEXTURE0_ARB
+
textureEngineIndex
);
glUniform1iARB
(
m_uniform_tex
,
textureEngineIndex
);
glBindTexture
(
GL_TEXTURE_2D
,
m_texName
);
glEnable
(
GL_TEXTURE_2D
);
}
}
// 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