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
Sauvage
CGoGN
Commits
d268a9bb
Commit
d268a9bb
authored
Feb 15, 2011
by
Sylvain Thery
Browse files
ajout tuto opengl3
parent
9b6604cf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Apps/Tuto/tuto_ogl3.cpp
0 → 100644
View file @
d268a9bb
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, 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: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include
<iostream>
#include
"Utils/glutwingl3.h"
#include
"Topology/generic/parameters.h"
#include
"Topology/map/map2.h"
#include
"Topology/generic/embeddedMap2.h"
#include
"Algo/Geometry/boundingbox.h"
#include
"Algo/Render/gl3mapRender.h"
#include
"Algo/Modelisation/polyhedron.h"
#include
"Geometry/vector_gen.h"
#include
"Algo/Geometry/normal.h"
using
namespace
CGoGN
;
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct
PFP
:
public
PFP_STANDARD
{
// definition of the type of the map
typedef
EmbeddedMap2
<
Map2
>
MAP
;
};
const
unsigned
int
GL_ATTRIB_POSITION
=
0
;
const
unsigned
int
GL_ATTRIB_NORMAL
=
1
;
/**
* A class for a little interface and rendering
*/
class
MyGlutWin
:
public
Utils
::
SimpleGlutWinGL3
{
public:
void
myRedraw
();
void
initGLAttribs
();
void
renderColor
();
void
renderPhong
();
PFP
::
REAL
gWidthObj
;
PFP
::
VEC3
gPosObj
;
Algo
::
Render
::
GL3
::
MapRender
*
m_render
;
Utils
::
GLSLShader
*
current_shader
;
Utils
::
GLSLShader
shaders
[
4
];
MyGlutWin
(
int
*
argc
,
char
**
argv
,
int
winX
,
int
winY
)
:
SimpleGlutWinGL3
(
argc
,
argv
,
winX
,
winY
)
{
shaders
[
0
].
loadShaders
(
"color_gl3.vert"
,
"color_gl3.frag"
);
shaders
[
1
].
loadShaders
(
"phong_gl3.vert"
,
"phong_gl3.frag"
);
current_shader
=
&
shaders
[
1
];
setCurrentShader
(
current_shader
);
}
~
MyGlutWin
()
{
delete
m_render
;
}
};
void
MyGlutWin
::
initGLAttribs
()
{
shaders
[
0
].
bindAttrib
(
GL_ATTRIB_POSITION
,
"VertexPosition"
);
shaders
[
1
].
bindAttrib
(
GL_ATTRIB_POSITION
,
"VertexPosition"
);
shaders
[
1
].
bindAttrib
(
GL_ATTRIB_NORMAL
,
"VertexNormal"
);
}
void
MyGlutWin
::
renderColor
()
{
current_shader
=
&
shaders
[
0
];
// setModelViewProjectionMatrix(current_shader);
setCurrentShader
(
current_shader
);
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_FILL
);
glDisable
(
GL_LIGHTING
);
current_shader
->
bind
();
float
colorLine
[]
=
{
1.0
f
,
1.0
f
,
0.0
f
,
0.0
f
};
float
colorFace
[]
=
{
0.0
f
,
1.0
f
,
0.0
f
,
0.0
f
};
// draw the lines
glLineWidth
(
2.0
f
);
current_shader
->
setuniformf
<
4
>
(
"Color"
,
colorLine
);
m_render
->
draw
(
Algo
::
Render
::
GL3
::
LINES
);
// draw the faces
glEnable
(
GL_POLYGON_OFFSET_FILL
);
glPolygonOffset
(
1.0
f
,
1.0
f
);
current_shader
->
setuniformf
<
4
>
(
"Color"
,
colorFace
);
m_render
->
draw
(
Algo
::
Render
::
GL3
::
TRIANGLES
);
glDisable
(
GL_POLYGON_OFFSET_FILL
);
}
void
MyGlutWin
::
renderPhong
()
{
current_shader
=
&
shaders
[
1
];
setCurrentShader
(
current_shader
);
// setModelViewProjectionMatrix(current_shader);
float
diffuse
[]
=
{
0.0
f
,
1.0
f
,
0.0
f
,
0.0
f
};
float
specular
[]
=
{
0.3
f
,
0.3
f
,
1.0
f
,
0.0
f
};
float
ambient
[]
=
{
0.1
f
,
0.03
f
,
0.03
f
,
0.0
f
};
float
shininess
=
100.0
f
;
float
lightPos
[]
=
{
100.0
,
300.0
,
1000.0
f
};
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_FILL
);
glEnable
(
GL_LIGHTING
);
current_shader
->
bind
();
current_shader
->
setuniformf
<
4
>
(
"materialDiffuse"
,
diffuse
);
current_shader
->
setuniformf
<
4
>
(
"materialSpecular"
,
specular
);
current_shader
->
setuniformf
<
4
>
(
"materialAmbient"
,
ambient
);
current_shader
->
setuniformf
<
1
>
(
"shininess"
,
&
shininess
);
current_shader
->
setuniformf
<
3
>
(
"LightPosition"
,
lightPos
);
m_render
->
draw
(
Algo
::
Render
::
GL3
::
TRIANGLES
);
}
void
MyGlutWin
::
myRedraw
()
{
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
// oglPushModelViewMatrix();
renderPhong
();
// oglPopModelViewMatrix();
}
int
main
(
int
argc
,
char
**
argv
)
{
// instanciation of the interface
MyGlutWin
mgw
(
&
argc
,
argv
,
800
,
800
);
// declaration of the map
PFP
::
MAP
myMap
;
AttributeHandler
<
PFP
::
VEC3
>
position
=
myMap
.
addAttribute
<
PFP
::
VEC3
>
(
VERTEX_ORBIT
,
"position"
);
AttributeHandler
<
PFP
::
VEC3
>
normal
=
myMap
.
addAttribute
<
PFP
::
VEC3
>
(
VERTEX_ORBIT
,
"normal"
);
Algo
::
Modelisation
::
Polyhedron
<
PFP
>
prim3
(
myMap
,
position
);
prim3
.
tore_topo
(
16
,
32
);
prim3
.
embedTore
(
30.0
f
,
10.0
f
);
Algo
::
Geometry
::
computeNormalVertices
<
PFP
>
(
myMap
,
position
,
normal
);
mgw
.
init
();
// computation of the bounding box
Geom
::
BoundingBox
<
PFP
::
VEC3
>
bb
=
Algo
::
Geometry
::
computeBoundingBox
<
PFP
>
(
myMap
,
position
);
mgw
.
gWidthObj
=
std
::
max
<
PFP
::
REAL
>
(
std
::
max
<
PFP
::
REAL
>
(
bb
.
size
(
0
),
bb
.
size
(
1
)),
bb
.
size
(
2
));
mgw
.
gPosObj
=
(
bb
.
min
()
+
bb
.
max
())
/
PFP
::
REAL
(
2
);
mgw
.
setParamObject
(
mgw
.
gWidthObj
,
mgw
.
gPosObj
.
data
());
// instanciation of the renderer (here using VBOs)
mgw
.
m_render
=
new
Algo
::
Render
::
GL3
::
MapRender
();
// update the renderer (primitives and geometry)
SelectorTrue
allDarts
;
mgw
.
m_render
->
initPrimitives
<
PFP
>
(
myMap
,
allDarts
,
Algo
::
Render
::
GL3
::
TRIANGLES
);
mgw
.
m_render
->
initPrimitives
<
PFP
>
(
myMap
,
allDarts
,
Algo
::
Render
::
GL3
::
LINES
);
mgw
.
m_render
->
initPrimitives
<
PFP
>
(
myMap
,
allDarts
,
Algo
::
Render
::
GL3
::
POINTS
);
mgw
.
m_render
->
updateData
(
GL_ATTRIB_POSITION
,
position
);
mgw
.
m_render
->
updateData
(
GL_ATTRIB_NORMAL
,
normal
);
mgw
.
initGLAttribs
();
mgw
.
mainLoop
();
return
0
;
}
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