Implement DisplayPacketOutlined & AddPacketDisplacement
This commit is contained in:
parent
ffd0938e1b
commit
f7f6beb3dc
9 changed files with 333 additions and 245 deletions
26
addPacketDisplacement.frag
Normal file
26
addPacketDisplacement.frag
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#version 410
|
||||||
|
#define PI 3.14159265359
|
||||||
|
|
||||||
|
out vec4 Color;
|
||||||
|
|
||||||
|
in Attribs {
|
||||||
|
vec4 Pos;
|
||||||
|
vec4 Att1;
|
||||||
|
vec4 Att2;
|
||||||
|
} In;
|
||||||
|
|
||||||
|
// rasterize wave packet quad
|
||||||
|
// wave packet data:
|
||||||
|
// position vector: x,y = [-1..1], position in envelope
|
||||||
|
// attribute vector: x=amplitude, y=wavelength, z=time phase, w=envelope size
|
||||||
|
// FALSE /!\ attribute2 vector: (x,y)=position of bending point, z=central distance to ref point, 0
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
/* If centerDiff == 0, the wave is straight */
|
||||||
|
float centerDiff = length(In.Pos.zw - vec2(0, In.Att2.x)) - abs(In.Pos.w - In.Att2.x);
|
||||||
|
float phase = -In.Att1.z + (In.Pos.w + centerDiff) * 2 * PI / In.Att1.y;
|
||||||
|
/* ROLL CREDITS ! */
|
||||||
|
vec3 ripple = (1 + cos(In.Pos.x * PI)) * (1 + cos(In.Pos.y * PI)) * In.Att1.x *
|
||||||
|
vec3(0, cos(phase), 0);
|
||||||
|
Color = vec4(ripple, 1);
|
||||||
|
}
|
53
addPacketDisplacement.geom
Normal file
53
addPacketDisplacement.geom
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#version 410
|
||||||
|
#define SCENE_EXTENT 100.0f
|
||||||
|
|
||||||
|
layout(points) in;
|
||||||
|
layout(triangle_strip, max_vertices = 4) out;
|
||||||
|
|
||||||
|
uniform mat4 matrModel;
|
||||||
|
uniform mat4 matrVisu;
|
||||||
|
uniform mat4 matrProj;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
in Attribs {
|
||||||
|
vec4 Pos;
|
||||||
|
vec4 Att1;
|
||||||
|
vec4 Att2;
|
||||||
|
} In[];
|
||||||
|
|
||||||
|
out Attribs {
|
||||||
|
vec4 Pos;
|
||||||
|
vec4 Att1;
|
||||||
|
vec4 Att2;
|
||||||
|
} Out;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
if (In[0].Pos.x < -9000)
|
||||||
|
return;
|
||||||
|
Out.Att1 = In[0].Att1;
|
||||||
|
Out.Att2 = In[0].Att2;
|
||||||
|
float dThickness = In[0].Att1.w;
|
||||||
|
float wThickness = In[0].Att1.w;
|
||||||
|
vec3 center = vec3(In[0].Pos.x, 0, In[0].Pos.y);
|
||||||
|
vec3 wavedir = vec3(In[0].Pos.z, 0, In[0].Pos.w);
|
||||||
|
vec3 wavecrest = vec3(wavedir.z, 0, -wavedir.x); // wave crest, orthogonal to wave direction
|
||||||
|
vec4 p1 = vec4(center - wThickness * wavecrest, 1);
|
||||||
|
vec4 p2 = vec4(center - wThickness * wavecrest - dThickness * wavedir, 1);
|
||||||
|
vec4 p3 = vec4(center + wThickness * wavecrest, 1);
|
||||||
|
vec4 p4 = vec4(center + wThickness * wavecrest - dThickness * wavedir, 1);
|
||||||
|
Out.Pos = vec4(-1, 1, -In[0].Att1.w, 0);
|
||||||
|
gl_Position = matrProj * matrVisu * matrModel * p1;
|
||||||
|
EmitVertex();
|
||||||
|
Out.Pos = vec4(-1, -1, -In[0].Att1.w, -In[0].Att1.w);
|
||||||
|
gl_Position = matrProj * matrVisu * matrModel * p2;
|
||||||
|
EmitVertex();
|
||||||
|
Out.Pos = vec4(1, 1, -In[0].Att1.w, 0);
|
||||||
|
gl_Position = matrProj * matrVisu * matrModel * p3;
|
||||||
|
EmitVertex();
|
||||||
|
Out.Pos = vec4(1, -1, In[0].Att1.w, -In[0].Att1.w);
|
||||||
|
gl_Position = matrProj * matrVisu * matrModel * p4;
|
||||||
|
EmitVertex();
|
||||||
|
}
|
||||||
|
|
27
addPacketDisplacement.vert
Normal file
27
addPacketDisplacement.vert
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#version 410
|
||||||
|
#define SCENE_EXTENT 100.0f
|
||||||
|
|
||||||
|
uniform mat4 matrModel;
|
||||||
|
uniform mat4 matrVisu;
|
||||||
|
uniform mat4 matrProj;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
layout(location=0) in vec4 Pos;
|
||||||
|
layout(location=4) in vec4 Att1;
|
||||||
|
layout(location=8) in vec4 Att2;
|
||||||
|
|
||||||
|
out Attribs {
|
||||||
|
vec4 Pos;
|
||||||
|
vec4 Att1;
|
||||||
|
vec4 Att2;
|
||||||
|
} Out;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
Out.Pos = Pos;
|
||||||
|
Out.Att1 = Att1;
|
||||||
|
Out.Att2 = Att2;
|
||||||
|
gl_PointSize = 5;
|
||||||
|
}
|
||||||
|
|
10
displayPacketOutlined.frag
Normal file
10
displayPacketOutlined.frag
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#version 410
|
||||||
|
|
||||||
|
out vec4 Color;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
Color = vec4(1, 1, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
42
displayPacketOutlined.geom
Normal file
42
displayPacketOutlined.geom
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#version 410
|
||||||
|
#define SCENE_EXTENT 100.0f
|
||||||
|
|
||||||
|
layout(points) in;
|
||||||
|
layout(line_strip, max_vertices = 5) out;
|
||||||
|
|
||||||
|
uniform mat4 matrModel;
|
||||||
|
uniform mat4 matrVisu;
|
||||||
|
uniform mat4 matrProj;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
in Attribs {
|
||||||
|
vec4 Pos;
|
||||||
|
vec4 Att1;
|
||||||
|
vec4 Att2;
|
||||||
|
} In[];
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
if (In[0].Pos.x < -9000)
|
||||||
|
return;
|
||||||
|
float dThickness = In[0].Att1.w;
|
||||||
|
float wThickness = In[0].Att1.w;
|
||||||
|
vec3 center = vec3(In[0].Pos.x, 0, In[0].Pos.y);
|
||||||
|
vec3 wavedir = vec3(In[0].Pos.z, 0, In[0].Pos.w);
|
||||||
|
vec3 wavecrest = vec3(wavedir.z, 0, -wavedir.x); // wave crest, orthogonal to wave direction
|
||||||
|
vec4 p1 = vec4(center - wThickness * wavecrest, 1);
|
||||||
|
vec4 p2 = vec4(center - wThickness * wavecrest - dThickness * wavedir, 1);
|
||||||
|
vec4 p3 = vec4(center + wThickness * wavecrest, 1);
|
||||||
|
vec4 p4 = vec4(center + wThickness * wavecrest - dThickness * wavedir, 1);
|
||||||
|
gl_Position = matrProj * matrVisu * matrModel * p1;
|
||||||
|
EmitVertex();
|
||||||
|
gl_Position = matrProj * matrVisu * matrModel * p2;
|
||||||
|
EmitVertex();
|
||||||
|
gl_Position = matrProj * matrVisu * matrModel * p4;
|
||||||
|
EmitVertex();
|
||||||
|
gl_Position = matrProj * matrVisu * matrModel * p3;
|
||||||
|
EmitVertex();
|
||||||
|
gl_Position = matrProj * matrVisu * matrModel * p1;
|
||||||
|
EmitVertex();
|
||||||
|
}
|
26
displayPacketOutlined.vert
Normal file
26
displayPacketOutlined.vert
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#version 410
|
||||||
|
#define SCENE_EXTENT 100.0f
|
||||||
|
|
||||||
|
uniform mat4 matrModel;
|
||||||
|
uniform mat4 matrVisu;
|
||||||
|
uniform mat4 matrProj;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
layout(location=0) in vec4 Pos;
|
||||||
|
layout(location=4) in vec4 Att1;
|
||||||
|
layout(location=8) in vec4 Att2;
|
||||||
|
|
||||||
|
out Attribs {
|
||||||
|
vec4 Pos;
|
||||||
|
vec4 Att1;
|
||||||
|
vec4 Att2;
|
||||||
|
} Out;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
Out.Pos = Pos;
|
||||||
|
Out.Att1 = Att1;
|
||||||
|
Out.Att2 = Att2;
|
||||||
|
gl_PointSize = 5;
|
||||||
|
}
|
2
makefile
2
makefile
|
@ -8,7 +8,7 @@ DEPDIR := $(BUILDDIR)/deps
|
||||||
#EXE := $(BINDIR)/OPHD
|
#EXE := $(BINDIR)/OPHD
|
||||||
EXE := ripple
|
EXE := ripple
|
||||||
|
|
||||||
CFLAGS := -std=c++11 -g -fopenmp -Wall -Wno-unknown-pragmas -I/usr/include/glm -I/usr/include/eigen3 $(shell pkg-config --cflags glew)
|
CFLAGS := -std=c++11 -O2 -fopenmp -Wall -Wno-unknown-pragmas -I/usr/include/glm -I/usr/include/eigen3 $(shell pkg-config --cflags glew)
|
||||||
CFLAGS += $(shell pkg-config --cflags sdl2)
|
CFLAGS += $(shell pkg-config --cflags sdl2)
|
||||||
LDFLAGS := -fopenmp -lstdc++ -lm -lglfw -lGLEW -lGL
|
LDFLAGS := -fopenmp -lstdc++ -lm -lglfw -lGLEW -lGL
|
||||||
LDFLAGS += $(shell pkg-config --libs sdl2)
|
LDFLAGS += $(shell pkg-config --libs sdl2)
|
||||||
|
|
386
ripple.cpp
386
ripple.cpp
|
@ -4,10 +4,20 @@
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "FBO.h"
|
#include "FBO.h"
|
||||||
#include "Packets.h"
|
#include "Packets.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#define SOL 1
|
#define SOL 1
|
||||||
|
|
||||||
enum {LocAttrib, LocUniform}; /* Shader location type */
|
enum {LocAttrib, LocUniform}; /* Shader location type */
|
||||||
|
enum {
|
||||||
|
RWMP_SHADER,
|
||||||
|
APD_SHADER,
|
||||||
|
DPO_SHADER,
|
||||||
|
DMM_SHADER,
|
||||||
|
DT_SHADER,
|
||||||
|
RAA_SHADER,
|
||||||
|
NB_SHADERS
|
||||||
|
}; /* Shaders stages */
|
||||||
|
|
||||||
// variables pour l'utilisation des nuanceurs
|
// variables pour l'utilisation des nuanceurs
|
||||||
GLuint prog; // votre programme de nuanceurs
|
GLuint prog; // votre programme de nuanceurs
|
||||||
|
@ -34,15 +44,17 @@ GLint locmatrProjRWMP = -1;
|
||||||
GLint locmatrNormaleRWMP = -1;
|
GLint locmatrNormaleRWMP = -1;
|
||||||
GLint locTexRWMP = -1;
|
GLint locTexRWMP = -1;
|
||||||
// Locations for AddPacketDisplacement shader
|
// Locations for AddPacketDisplacement shader
|
||||||
GLuint locVertexADP = -1;
|
GLuint locPosAPD = -1;
|
||||||
GLuint locTexCoordADP = -1;
|
GLuint locAtt1APD = -1;
|
||||||
GLuint locmatrModelADP = -1;
|
GLuint locAtt2APD = -1;
|
||||||
GLuint locmatrVisuADP = -1;
|
GLuint locmatrModelAPD = -1;
|
||||||
GLuint locmatrProjADP = -1;
|
GLuint locmatrVisuAPD = -1;
|
||||||
GLuint locTexADP = -1;
|
GLuint locmatrProjAPD = -1;
|
||||||
|
GLuint locTexAPD = -1;
|
||||||
// Locations for DisplayPacketOutlined shader
|
// Locations for DisplayPacketOutlined shader
|
||||||
GLuint locVertexDPO = -1;
|
GLuint locPosDPO = -1;
|
||||||
GLuint locTexCoordDPO = -1;
|
GLuint locAtt1DPO = -1;
|
||||||
|
GLuint locAtt2DPO = -1;
|
||||||
GLuint locmatrModelDPO = -1;
|
GLuint locmatrModelDPO = -1;
|
||||||
GLuint locmatrVisuDPO = -1;
|
GLuint locmatrVisuDPO = -1;
|
||||||
GLuint locmatrProjDPO = -1;
|
GLuint locmatrProjDPO = -1;
|
||||||
|
@ -80,11 +92,11 @@ GLint locmatrModelBase = -1;
|
||||||
GLint locmatrVisuBase = -1;
|
GLint locmatrVisuBase = -1;
|
||||||
GLint locmatrProjBase = -1;
|
GLint locmatrProjBase = -1;
|
||||||
|
|
||||||
GLuint vao[2];
|
GLuint vao[NB_SHADERS];
|
||||||
GLuint vaoQuad;
|
|
||||||
GLuint vbosQuad[2];
|
|
||||||
GLuint vbo[5];
|
GLuint vbo[5];
|
||||||
GLuint ubo[4];
|
GLuint ubo[4];
|
||||||
|
GLuint vbosQuad[2];
|
||||||
|
GLuint vboPacket;
|
||||||
|
|
||||||
// matrices de du pipeline graphique
|
// matrices de du pipeline graphique
|
||||||
MatricePipeline matrModel;
|
MatricePipeline matrModel;
|
||||||
|
@ -116,7 +128,7 @@ FBO *aaFBO;
|
||||||
|
|
||||||
// Wave Packets
|
// Wave Packets
|
||||||
Packets *packets;
|
Packets *packets;
|
||||||
int packetBudget = MIN_PACKET_BUDGET;
|
int packetBudget = 10000;
|
||||||
/* Wave packets:
|
/* Wave packets:
|
||||||
* vec4: xy = position, zw = direction
|
* vec4: xy = position, zw = direction
|
||||||
* vec4: x = amplitude, y = wavelength, z = phase offset, w = enveloppe size
|
* vec4: x = amplitude, y = wavelength, z = phase offset, w = enveloppe size
|
||||||
|
@ -195,6 +207,11 @@ struct
|
||||||
// copie directe vers le nuanceur où les variables seront bien de type 'bool'. )
|
// copie directe vers le nuanceur où les variables seront bien de type 'bool'. )
|
||||||
|
|
||||||
|
|
||||||
|
/* Forward declarations */
|
||||||
|
void displayPacketOutlined(int count);
|
||||||
|
void addPacketDisplacement(int count);
|
||||||
|
|
||||||
|
|
||||||
void verifierAngles()
|
void verifierAngles()
|
||||||
{
|
{
|
||||||
if ( thetaCam > 360.0 )
|
if ( thetaCam > 360.0 )
|
||||||
|
@ -265,12 +282,18 @@ void updatePackets()
|
||||||
packetChunk += 3; /* The last 3 elements aren't needed */
|
packetChunk += 3; /* The last 3 elements aren't needed */
|
||||||
displayedPackets++;
|
displayedPackets++;
|
||||||
if (packetChunk >= PACKET_GPU_BUFFER_SIZE * 3 * 4) {
|
if (packetChunk >= PACKET_GPU_BUFFER_SIZE * 3 * 4) {
|
||||||
/* TODO Update VBO */
|
glBindBuffer(GL_ARRAY_BUFFER, vboPacket);
|
||||||
|
/* TODO Use Buffer mapping for better performance */
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(packetData), packetData);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
//displayPacketOutlined(packetChunk / 12);
|
||||||
/* TODO EvaluatePackets(packetChunk) */
|
/* TODO EvaluatePackets(packetChunk) */
|
||||||
|
addPacketDisplacement(packetChunk / 12);
|
||||||
packetChunk = 0;
|
packetChunk = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// printf("PacketData[0] = %f , %f\n", packetData[0], packetData[1]);
|
||||||
/* Ghost packets */
|
/* Ghost packets */
|
||||||
for (int i = 0; i < packets->m_usedGhosts; ++i) {
|
for (int i = 0; i < packets->m_usedGhosts; ++i) {
|
||||||
int pk = packets->m_usedGhost[i];
|
int pk = packets->m_usedGhost[i];
|
||||||
|
@ -290,13 +313,21 @@ void updatePackets()
|
||||||
packetChunk += 3; /* The last 3 elements aren't needed */
|
packetChunk += 3; /* The last 3 elements aren't needed */
|
||||||
displayedPackets++;
|
displayedPackets++;
|
||||||
if (packetChunk >= PACKET_GPU_BUFFER_SIZE * 3 * 4) {
|
if (packetChunk >= PACKET_GPU_BUFFER_SIZE * 3 * 4) {
|
||||||
/* TODO Update VBO */
|
glBindBuffer(GL_ARRAY_BUFFER, vboPacket);
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(packetData), packetData);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
//displayPacketOutlined();
|
||||||
/* TODO EvaluatePackets(packetChunk) */
|
/* TODO EvaluatePackets(packetChunk) */
|
||||||
|
addPacketDisplacement(packetChunk / 12);
|
||||||
packetChunk = 0;
|
packetChunk = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* TODO Update VBO */
|
glBindBuffer(GL_ARRAY_BUFFER, vboPacket);
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(packetData), packetData);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
//displayPacketOutlined(packetChunk / 12);
|
||||||
/* TODO EvaluatePackets(packetChunk) */
|
/* TODO EvaluatePackets(packetChunk) */
|
||||||
|
addPacketDisplacement(packetChunk / 12);
|
||||||
/* TODO DisplayScene */
|
/* TODO DisplayScene */
|
||||||
/* TODO Get camera center */
|
/* TODO Get camera center */
|
||||||
}
|
}
|
||||||
|
@ -406,61 +437,6 @@ void chargerNuanceurs()
|
||||||
locmatrProjBase = getloc( progBase, "matrProj", LocUniform );
|
locmatrProjBase = getloc( progBase, "matrProj", LocUniform );
|
||||||
}
|
}
|
||||||
|
|
||||||
// charger le nuanceur de ce TP
|
|
||||||
{
|
|
||||||
// créer le programme
|
|
||||||
const GLchar *shaders[3] = {"nuanceurSommetsSolution.glsl", "nuanceurGeometrieSolution.glsl", "nuanceurFragmentsSolution.glsl"};
|
|
||||||
prog = createShader(shaders);
|
|
||||||
|
|
||||||
// demander la "Location" des variables
|
|
||||||
locVertex = getloc( prog, "Vertex", LocAttrib );
|
|
||||||
locNormal = getloc( prog, "Normal", LocAttrib );
|
|
||||||
locTexCoord = getloc( prog, "TexCoord", LocAttrib );
|
|
||||||
locmatrModel = getloc( prog, "matrModel" , LocUniform);
|
|
||||||
locmatrVisu = getloc( prog, "matrVisu" , LocUniform);
|
|
||||||
locmatrProj = getloc( prog, "matrProj" , LocUniform);
|
|
||||||
locmatrNormale = getloc( prog, "matrNormale" , LocUniform);
|
|
||||||
loclaTexture = getloc( prog, "laTexture" , LocUniform);
|
|
||||||
if ( ( indLightSource = glGetUniformBlockIndex( prog, "LightSourceParameters" ) ) == GL_INVALID_INDEX ) std::cerr << "!!! pas trouvé l'\"index\" de LightSource" << std::endl;
|
|
||||||
if ( ( indFrontMaterial = glGetUniformBlockIndex( prog, "MaterialParameters" ) ) == GL_INVALID_INDEX ) std::cerr << "!!! pas trouvé l'\"index\" de FrontMaterial" << std::endl;
|
|
||||||
if ( ( indLightModel = glGetUniformBlockIndex( prog, "LightModelParameters" ) ) == GL_INVALID_INDEX ) std::cerr << "!!! pas trouvé l'\"index\" de LightModel" << std::endl;
|
|
||||||
if ( ( indvarsUnif = glGetUniformBlockIndex( prog, "varsUnif" ) ) == GL_INVALID_INDEX ) std::cerr << "!!! pas trouvé l'\"index\" de varsUnif" << std::endl;
|
|
||||||
|
|
||||||
// charger les ubo
|
|
||||||
{
|
|
||||||
glBindBuffer( GL_UNIFORM_BUFFER, ubo[0] );
|
|
||||||
glBufferData( GL_UNIFORM_BUFFER, sizeof(LightSource), &LightSource, GL_DYNAMIC_COPY );
|
|
||||||
glBindBuffer( GL_UNIFORM_BUFFER, 0 );
|
|
||||||
const GLuint bindingIndex = 0;
|
|
||||||
glBindBufferBase( GL_UNIFORM_BUFFER, bindingIndex, ubo[0] );
|
|
||||||
glUniformBlockBinding( prog, indLightSource, bindingIndex );
|
|
||||||
}
|
|
||||||
{
|
|
||||||
glBindBuffer( GL_UNIFORM_BUFFER, ubo[1] );
|
|
||||||
glBufferData( GL_UNIFORM_BUFFER, sizeof(FrontMaterial), &FrontMaterial, GL_DYNAMIC_COPY );
|
|
||||||
glBindBuffer( GL_UNIFORM_BUFFER, 0 );
|
|
||||||
const GLuint bindingIndex = 1;
|
|
||||||
glBindBufferBase( GL_UNIFORM_BUFFER, bindingIndex, ubo[1] );
|
|
||||||
glUniformBlockBinding( prog, indFrontMaterial, bindingIndex );
|
|
||||||
}
|
|
||||||
{
|
|
||||||
glBindBuffer( GL_UNIFORM_BUFFER, ubo[2] );
|
|
||||||
glBufferData( GL_UNIFORM_BUFFER, sizeof(LightModel), &LightModel, GL_DYNAMIC_COPY );
|
|
||||||
glBindBuffer( GL_UNIFORM_BUFFER, 0 );
|
|
||||||
const GLuint bindingIndex = 2;
|
|
||||||
glBindBufferBase( GL_UNIFORM_BUFFER, bindingIndex, ubo[2] );
|
|
||||||
glUniformBlockBinding( prog, indLightModel, bindingIndex );
|
|
||||||
}
|
|
||||||
{
|
|
||||||
glBindBuffer( GL_UNIFORM_BUFFER, ubo[3] );
|
|
||||||
glBufferData( GL_UNIFORM_BUFFER, sizeof(varsUnif), &varsUnif, GL_DYNAMIC_COPY );
|
|
||||||
glBindBuffer( GL_UNIFORM_BUFFER, 0 );
|
|
||||||
const GLuint bindingIndex = 3;
|
|
||||||
glBindBufferBase( GL_UNIFORM_BUFFER, bindingIndex, ubo[3] );
|
|
||||||
glUniformBlockBinding( prog, indvarsUnif, bindingIndex );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load RasterizeWaveMeshPosition shader
|
// Load RasterizeWaveMeshPosition shader
|
||||||
{
|
{
|
||||||
// créer le programme
|
// créer le programme
|
||||||
|
@ -481,20 +457,22 @@ void chargerNuanceurs()
|
||||||
const GLchar *shaders[3] = {"addPacketDisplacement.vert", "addPacketDisplacement.geom", "addPacketDisplacement.frag"};
|
const GLchar *shaders[3] = {"addPacketDisplacement.vert", "addPacketDisplacement.geom", "addPacketDisplacement.frag"};
|
||||||
progAddPacketDisplacement = createShader(shaders);
|
progAddPacketDisplacement = createShader(shaders);
|
||||||
// demander la "Location" des variables
|
// demander la "Location" des variables
|
||||||
locVertexADP = getloc( progAddPacketDisplacement, "Vertex" , LocAttrib);
|
locPosAPD = getloc( progAddPacketDisplacement, "Pos" , LocAttrib);
|
||||||
locTexCoordADP = getloc( progAddPacketDisplacement, "TexCoord" , LocAttrib);
|
locAtt1APD = getloc( progAddPacketDisplacement, "Att1" , LocAttrib);
|
||||||
locmatrModelADP = getloc( progAddPacketDisplacement, "matrModel" , LocUniform);
|
locAtt2APD = getloc( progAddPacketDisplacement, "Att2" , LocAttrib);
|
||||||
locmatrVisuADP = getloc( progAddPacketDisplacement, "matrVisu" , LocUniform);
|
locmatrModelAPD = getloc( progAddPacketDisplacement, "matrModel" , LocUniform);
|
||||||
locmatrProjADP = getloc( progAddPacketDisplacement, "matrProj" , LocUniform);
|
locmatrVisuAPD = getloc( progAddPacketDisplacement, "matrVisu" , LocUniform);
|
||||||
locTexADP = getloc( progAddPacketDisplacement, "tex" , LocUniform);
|
locmatrProjAPD = getloc( progAddPacketDisplacement, "matrProj" , LocUniform);
|
||||||
|
locTexAPD = getloc( progAddPacketDisplacement, "tex" , LocUniform);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load DisplayPacketOutlined shader
|
// Load DisplayPacketOutlined shader
|
||||||
{
|
{
|
||||||
const GLchar *shaders[3] = {"displayPacketOutlined.vert", "displayPacketOutlined.geom", "displayPacketOutlined.frag"};
|
const GLchar *shaders[3] = {"displayPacketOutlined.vert", "displayPacketOutlined.geom", "displayPacketOutlined.frag"};
|
||||||
progDisplayPacketOutlined = createShader(shaders);
|
progDisplayPacketOutlined = createShader(shaders);
|
||||||
locVertexDPO = getloc( progDisplayPacketOutlined, "Vertex" , LocAttrib);
|
locPosDPO = getloc( progDisplayPacketOutlined, "Pos" , LocAttrib);
|
||||||
locTexCoordDPO = getloc( progDisplayPacketOutlined, "TexCoord" , LocAttrib);
|
locAtt1DPO = getloc( progDisplayPacketOutlined, "Att1" , LocAttrib);
|
||||||
|
locAtt2DPO = getloc( progDisplayPacketOutlined, "Att2" , LocAttrib);
|
||||||
locmatrModelDPO = getloc( progDisplayPacketOutlined, "matrModel" , LocUniform);
|
locmatrModelDPO = getloc( progDisplayPacketOutlined, "matrModel" , LocUniform);
|
||||||
locmatrVisuDPO = getloc( progDisplayPacketOutlined, "matrVisu" , LocUniform);
|
locmatrVisuDPO = getloc( progDisplayPacketOutlined, "matrVisu" , LocUniform);
|
||||||
locmatrProjDPO = getloc( progDisplayPacketOutlined, "matrProj" , LocUniform);
|
locmatrProjDPO = getloc( progDisplayPacketOutlined, "matrProj" , LocUniform);
|
||||||
|
@ -527,7 +505,7 @@ void chargerNuanceurs()
|
||||||
|
|
||||||
// Load RenderAA shader
|
// Load RenderAA shader
|
||||||
{
|
{
|
||||||
const GLchar *shaders[3] = {"displayTerrain.vert", NULL, "displayTerrain.frag"};
|
const GLchar *shaders[3] = {"renderAA.vert", NULL, "RenderAA.frag"};
|
||||||
progRenderAA = createShader(shaders);
|
progRenderAA = createShader(shaders);
|
||||||
locVertexRAA = getloc( progRenderAA, "Vertex" , LocAttrib);
|
locVertexRAA = getloc( progRenderAA, "Vertex" , LocAttrib);
|
||||||
locTexCoordRAA = getloc( progRenderAA, "TexCoord" , LocAttrib);
|
locTexCoordRAA = getloc( progRenderAA, "TexCoord" , LocAttrib);
|
||||||
|
@ -552,21 +530,61 @@ void initQuad()
|
||||||
};
|
};
|
||||||
|
|
||||||
// allouer les objets OpenGL
|
// allouer les objets OpenGL
|
||||||
glGenVertexArrays( 1, &vaoQuad );
|
/* TODO Add support for RenderAA shader */
|
||||||
glGenBuffers( 2, vbosQuad );
|
glGenBuffers( 2, vbosQuad );
|
||||||
// initialiser le VAO
|
|
||||||
glBindVertexArray( vaoQuad );
|
|
||||||
|
|
||||||
// charger le VBO pour les vertices
|
/* Prepare VAO for RasterizeWaveMeshPosition shader */
|
||||||
|
glBindVertexArray(vao[RWMP_SHADER]);
|
||||||
|
// Bind vertices VBO
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, vbosQuad[0] );
|
glBindBuffer( GL_ARRAY_BUFFER, vbosQuad[0] );
|
||||||
glBufferData( GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW );
|
glBufferData( GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW );
|
||||||
glVertexAttribPointer( locVertexRWMP, 2, GL_FLOAT, GL_FALSE, 0, 0 );
|
glVertexAttribPointer( locVertexRWMP, 2, GL_FLOAT, GL_FALSE, 0, 0 );
|
||||||
glEnableVertexAttribArray(locVertex);
|
glEnableVertexAttribArray(locVertexRWMP);
|
||||||
// Charger le VBO pour les coordonnées de texture
|
// Bind texture coord VBO
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, vbosQuad[1] );
|
glBindBuffer( GL_ARRAY_BUFFER, vbosQuad[1] );
|
||||||
glBufferData( GL_ARRAY_BUFFER, sizeof(texcoords), texcoords, GL_STATIC_DRAW );
|
glBufferData( GL_ARRAY_BUFFER, sizeof(texcoords), texcoords, GL_STATIC_DRAW );
|
||||||
glVertexAttribPointer( locTexCoordRWMP, 2, GL_FLOAT, GL_FALSE, 0, 0 );
|
glVertexAttribPointer( locTexCoordRWMP, 2, GL_FLOAT, GL_FALSE, 0, 0 );
|
||||||
glEnableVertexAttribArray(locTexCoord);
|
glEnableVertexAttribArray(locTexCoordRWMP);
|
||||||
|
|
||||||
|
/* Prepare VAO for RenderAA shader */
|
||||||
|
glBindVertexArray(vao[RAA_SHADER]);
|
||||||
|
// Bind vertices VBO
|
||||||
|
glBindBuffer( GL_ARRAY_BUFFER, vbosQuad[0] );
|
||||||
|
glVertexAttribPointer( locVertexRAA, 2, GL_FLOAT, GL_FALSE, 0, 0 );
|
||||||
|
glEnableVertexAttribArray(locVertexRAA);
|
||||||
|
// Bind texture coord VBO
|
||||||
|
glBindBuffer( GL_ARRAY_BUFFER, vbosQuad[1] );
|
||||||
|
glVertexAttribPointer( locTexCoordRAA, 2, GL_FLOAT, GL_FALSE, 0, 0 );
|
||||||
|
glEnableVertexAttribArray(locTexCoordRAA);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Create the buffer to store wave packets
|
||||||
|
void initPacketMesh()
|
||||||
|
{
|
||||||
|
glGenBuffers(1, &vboPacket);
|
||||||
|
|
||||||
|
glBindVertexArray(vao[APD_SHADER]);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vboPacket);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(packetData), NULL, GL_DYNAMIC_DRAW);
|
||||||
|
glVertexAttribPointer(locPosAPD, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 12, (void*)0);
|
||||||
|
glVertexAttribPointer(locAtt1APD, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 12, (void*)4);
|
||||||
|
glVertexAttribPointer(locAtt2APD, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 12, (void*)8);
|
||||||
|
glEnableVertexAttribArray(locPosAPD);
|
||||||
|
glEnableVertexAttribArray(locAtt1APD);
|
||||||
|
glEnableVertexAttribArray(locAtt2APD);
|
||||||
|
|
||||||
|
glBindVertexArray(vao[DPO_SHADER]);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vboPacket);
|
||||||
|
/* No need to initialize the buffer a second time */
|
||||||
|
glVertexAttribPointer(locPosDPO, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 12, (void*)0);
|
||||||
|
glVertexAttribPointer(locAtt1DPO, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 12, (void*)4);
|
||||||
|
glVertexAttribPointer(locAtt2DPO, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 12, (void*)8);
|
||||||
|
glEnableVertexAttribArray(locPosDPO);
|
||||||
|
glEnableVertexAttribArray(locAtt1DPO);
|
||||||
|
glEnableVertexAttribArray(locAtt2DPO);
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -576,7 +594,7 @@ void initialiser()
|
||||||
// donner l'orientation du modèle
|
// donner l'orientation du modèle
|
||||||
thetaCam = 0.0;
|
thetaCam = 0.0;
|
||||||
phiCam = 0.0;
|
phiCam = 0.0;
|
||||||
distCam = 30.0;
|
distCam = 90.0;
|
||||||
|
|
||||||
// Create FBOs
|
// Create FBOs
|
||||||
posFBO = new FBO();
|
posFBO = new FBO();
|
||||||
|
@ -597,102 +615,14 @@ void initialiser()
|
||||||
|
|
||||||
// allouer les UBO pour les variables uniformes
|
// allouer les UBO pour les variables uniformes
|
||||||
glGenBuffers( 4, ubo );
|
glGenBuffers( 4, ubo );
|
||||||
|
glGenVertexArrays(NB_SHADERS, vao);
|
||||||
|
|
||||||
// charger les nuanceurs
|
// charger les nuanceurs
|
||||||
chargerNuanceurs();
|
chargerNuanceurs();
|
||||||
|
|
||||||
|
// Initialize VBOs
|
||||||
initQuad();
|
initQuad();
|
||||||
glUseProgram( prog );
|
initPacketMesh();
|
||||||
|
|
||||||
// (partie 1) créer le cube
|
|
||||||
/* +Y */
|
|
||||||
/* 3+-----------+2 */
|
|
||||||
/* |\ |\ */
|
|
||||||
/* | \ | \ */
|
|
||||||
/* | \ | \ */
|
|
||||||
/* | 7+-----------+6 */
|
|
||||||
/* | | | | */
|
|
||||||
/* | | | | */
|
|
||||||
/* 0+---|-------+1 | */
|
|
||||||
/* \ | \ | +X */
|
|
||||||
/* \ | \ | */
|
|
||||||
/* \| \| */
|
|
||||||
/* 4+-----------+5 */
|
|
||||||
/* +Z */
|
|
||||||
|
|
||||||
GLfloat sommets[3*4*6] =
|
|
||||||
{
|
|
||||||
-1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, // P3,P2,P0,P1
|
|
||||||
1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, // P5,P4,P1,P0
|
|
||||||
1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, // P6,P5,P2,P1
|
|
||||||
-1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, // P7,P6,P3,P2
|
|
||||||
-1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, // P4,P7,P0,P3
|
|
||||||
-1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0 // P4,P5,P7,P6
|
|
||||||
};
|
|
||||||
GLfloat normales[3*4*6] =
|
|
||||||
{
|
|
||||||
0.0, 0.0,-1.0, 0.0, 0.0,-1.0, 0.0, 0.0,-1.0, 0.0, 0.0,-1.0,
|
|
||||||
0.0,-1.0, 0.0, 0.0,-1.0, 0.0, 0.0,-1.0, 0.0, 0.0,-1.0, 0.0,
|
|
||||||
1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
|
|
||||||
0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0,
|
|
||||||
-1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0,
|
|
||||||
0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0,
|
|
||||||
};
|
|
||||||
GLfloat texcoordsDe[2*4*6] =
|
|
||||||
{
|
|
||||||
1.000000,0.000000, 0.666666,0.000000, 1.000000,0.333333, 0.666666,0.333333,
|
|
||||||
0.000000,0.666666, 0.333333,0.666666, 0.000000,0.333333, 0.333333,0.333333,
|
|
||||||
0.666666,1.000000, 0.666666,0.666666, 0.333333,1.000000, 0.333333,0.666666,
|
|
||||||
1.000000,0.333333, 0.666666,0.333333, 1.000000,0.666666, 0.666666,0.666666,
|
|
||||||
0.333333,0.000000, 0.333333,0.333333, 0.666666,0.000000, 0.666666,0.333333,
|
|
||||||
0.666666,0.333333, 0.333333,0.333333, 0.666666,0.666666, 0.333333,0.666666
|
|
||||||
};
|
|
||||||
GLfloat texcoordsEchiquier[2*4*6] =
|
|
||||||
{
|
|
||||||
-1.0, -1.0, -1.0, 2.0, 2.0, -1.0, 2.0, 2.0,
|
|
||||||
2.0, -1.0, -1.0, -1.0, 2.0, 2.0, -1.0, 2.0,
|
|
||||||
-1.0, -1.0, -1.0, 2.0, 2.0, -1.0, 2.0, 2.0,
|
|
||||||
-1.0, 2.0, 2.0, 2.0, -1.0, -1.0, 2.0, -1.0,
|
|
||||||
2.0, 2.0, 2.0, -1.0, -1.0, 2.0, -1.0, -1.0,
|
|
||||||
-1.0, -1.0, -1.0, 2.0, 2.0, -1.0, 2.0, 2.0
|
|
||||||
};
|
|
||||||
|
|
||||||
// allouer les objets OpenGL
|
|
||||||
glGenVertexArrays( 2, vao );
|
|
||||||
glGenBuffers( 5, vbo );
|
|
||||||
// initialiser le VAO
|
|
||||||
glBindVertexArray( vao[0] );
|
|
||||||
|
|
||||||
// charger le VBO pour les sommets
|
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, vbo[0] );
|
|
||||||
glBufferData( GL_ARRAY_BUFFER, sizeof(sommets), sommets, GL_STATIC_DRAW );
|
|
||||||
glVertexAttribPointer( locVertex, 3, GL_FLOAT, GL_FALSE, 0, 0 );
|
|
||||||
glEnableVertexAttribArray(locVertex);
|
|
||||||
// (partie 1) charger le VBO pour les normales
|
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, vbo[1] );
|
|
||||||
glBufferData( GL_ARRAY_BUFFER, sizeof(normales), normales, GL_STATIC_DRAW );
|
|
||||||
glVertexAttribPointer( locNormal, 3, GL_FLOAT, GL_FALSE, 0, 0 );
|
|
||||||
glEnableVertexAttribArray(locNormal);
|
|
||||||
// (partie 3) charger le VBO pour les coordonnées de texture du dé
|
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, vbo[2] );
|
|
||||||
glBufferData( GL_ARRAY_BUFFER, sizeof(texcoordsDe), texcoordsDe, GL_STATIC_DRAW );
|
|
||||||
glVertexAttribPointer( locTexCoord, 2, GL_FLOAT, GL_FALSE, 0, 0 );
|
|
||||||
glEnableVertexAttribArray(locTexCoord);
|
|
||||||
// (partie 3) charger le VBO pour les coordonnées de texture de l'échiquier
|
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, vbo[3] );
|
|
||||||
glBufferData( GL_ARRAY_BUFFER, sizeof(texcoordsEchiquier), texcoordsEchiquier, GL_STATIC_DRAW );
|
|
||||||
glVertexAttribPointer( locTexCoord, 2, GL_FLOAT, GL_FALSE, 0, 0 );
|
|
||||||
glEnableVertexAttribArray(locTexCoord);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
// initialiser le VAO pour une ligne (montrant la direction du spot)
|
|
||||||
glBindVertexArray( vao[1] );
|
|
||||||
GLfloat coords[] = { 0., 0., 0., 0., 0., 1. };
|
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, vbo[4] );
|
|
||||||
glBufferData( GL_ARRAY_BUFFER, sizeof(coords), coords, GL_STATIC_DRAW );
|
|
||||||
glVertexAttribPointer( locVertexBase, 3, GL_FLOAT, GL_FALSE, 0, 0 );
|
|
||||||
glEnableVertexAttribArray(locVertexBase);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
// créer quelques autres formes
|
// créer quelques autres formes
|
||||||
sphere = new FormeSphere( 1.0, 32, 32 );
|
sphere = new FormeSphere( 1.0, 32, 32 );
|
||||||
|
@ -709,7 +639,7 @@ void initialiser()
|
||||||
void conclure()
|
void conclure()
|
||||||
{
|
{
|
||||||
glUseProgram( 0 );
|
glUseProgram( 0 );
|
||||||
glDeleteVertexArrays( 2, vao );
|
glDeleteVertexArrays( NB_SHADERS, vao );
|
||||||
glDeleteBuffers( 4, vbo );
|
glDeleteBuffers( 4, vbo );
|
||||||
glDeleteBuffers( 4, ubo );
|
glDeleteBuffers( 4, ubo );
|
||||||
delete sphere;
|
delete sphere;
|
||||||
|
@ -721,6 +651,7 @@ void conclure()
|
||||||
delete posFBO;
|
delete posFBO;
|
||||||
delete heightFBO;
|
delete heightFBO;
|
||||||
delete aaFBO;
|
delete aaFBO;
|
||||||
|
delete packets;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawQuad()
|
void drawQuad()
|
||||||
|
@ -729,29 +660,38 @@ void drawQuad()
|
||||||
glUniformMatrix4fv( locmatrProjRWMP, 1, GL_FALSE, matrProj );
|
glUniformMatrix4fv( locmatrProjRWMP, 1, GL_FALSE, matrProj );
|
||||||
glUniformMatrix4fv( locmatrVisuRWMP, 1, GL_FALSE, matrVisu );
|
glUniformMatrix4fv( locmatrVisuRWMP, 1, GL_FALSE, matrVisu );
|
||||||
glUniformMatrix4fv( locmatrModelRWMP, 1, GL_FALSE, matrModel );
|
glUniformMatrix4fv( locmatrModelRWMP, 1, GL_FALSE, matrModel );
|
||||||
glBindVertexArray(vaoQuad);
|
glBindVertexArray(vao[RWMP_SHADER]);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void afficherModele()
|
void displayPacketOutlined(int count)
|
||||||
{
|
{
|
||||||
// partie 3: paramètres de texture
|
glUseProgram(progDisplayPacketOutlined);
|
||||||
switch ( varsUnif.texnumero )
|
glBindVertexArray(vao[DPO_SHADER]);
|
||||||
{
|
glUniformMatrix4fv(locmatrModelDPO, 1, GL_FALSE, matrModel);
|
||||||
default:
|
glUniformMatrix4fv(locmatrVisuDPO, 1, GL_FALSE, matrVisu);
|
||||||
//std::cout << "Sans texture" << std::endl;
|
glUniformMatrix4fv(locmatrProjDPO, 1, GL_FALSE, matrProj);
|
||||||
glBindTexture( GL_TEXTURE_2D, 0 );
|
glDrawArrays(GL_POINTS, 0, count);
|
||||||
break;
|
glBindVertexArray(0);
|
||||||
case 1:
|
glUseProgram(0);
|
||||||
//std::cout << "Texture DE" << std::endl;
|
|
||||||
glBindTexture( GL_TEXTURE_2D, texTerrain );
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
//std::cout << "Texture ECHIQUIER" << std::endl;
|
|
||||||
glBindTexture( GL_TEXTURE_2D, textureECHIQUIER );
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void addPacketDisplacement(int count)
|
||||||
|
{
|
||||||
|
glUseProgram(progAddPacketDisplacement);
|
||||||
|
glBindVertexArray(vao[APD_SHADER]);
|
||||||
|
glUniformMatrix4fv(locmatrModelAPD, 1, GL_FALSE, matrModel);
|
||||||
|
glUniformMatrix4fv(locmatrVisuAPD, 1, GL_FALSE, matrVisu);
|
||||||
|
glUniformMatrix4fv(locmatrProjAPD, 1, GL_FALSE, matrProj);
|
||||||
|
glDrawArrays(GL_POINTS, 0, count);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
glUseProgram(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void afficherModele()
|
||||||
|
{
|
||||||
// Dessiner le modèle
|
// Dessiner le modèle
|
||||||
matrModel.PushMatrix(); {
|
matrModel.PushMatrix(); {
|
||||||
|
|
||||||
|
@ -763,11 +703,8 @@ void afficherModele()
|
||||||
matrModel.Scale( 5.0, 5.0, 5.0 );
|
matrModel.Scale( 5.0, 5.0, 5.0 );
|
||||||
|
|
||||||
glUniformMatrix4fv( locmatrModel, 1, GL_FALSE, matrModel );
|
glUniformMatrix4fv( locmatrModel, 1, GL_FALSE, matrModel );
|
||||||
// (partie 1: ne pas oublier de calculer et donner une matrice pour les transformations des normales)
|
updatePackets();
|
||||||
glUniformMatrix3fv( locmatrNormale, 1, GL_TRUE, glm::value_ptr( glm::inverse( glm::mat3( matrVisu.getMatr() * matrModel.getMatr() ) ) ) );
|
} matrModel.PopMatrix();
|
||||||
|
|
||||||
drawQuad();
|
|
||||||
} matrModel.PopMatrix(); glUniformMatrix4fv( locmatrModel, 1, GL_FALSE, matrModel );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void afficherLumiere()
|
void afficherLumiere()
|
||||||
|
@ -812,7 +749,7 @@ void FenetreTP::afficherScene()
|
||||||
if ( enPerspective )
|
if ( enPerspective )
|
||||||
{
|
{
|
||||||
matrProj.Perspective( 35.0, (GLdouble)largeur_ / (GLdouble)hauteur_,
|
matrProj.Perspective( 35.0, (GLdouble)largeur_ / (GLdouble)hauteur_,
|
||||||
0.1, 60.0 );
|
0.1, 300.0 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -822,14 +759,14 @@ void FenetreTP::afficherScene()
|
||||||
matrProj.Ortho( -d, d,
|
matrProj.Ortho( -d, d,
|
||||||
-d*(GLdouble)hauteur_ / (GLdouble)largeur_,
|
-d*(GLdouble)hauteur_ / (GLdouble)largeur_,
|
||||||
d*(GLdouble)hauteur_ / (GLdouble)largeur_,
|
d*(GLdouble)hauteur_ / (GLdouble)largeur_,
|
||||||
0.1, 60.0 );
|
0.1, 300.0 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
matrProj.Ortho( -d*(GLdouble)largeur_ / (GLdouble)hauteur_,
|
matrProj.Ortho( -d*(GLdouble)largeur_ / (GLdouble)hauteur_,
|
||||||
d*(GLdouble)largeur_ / (GLdouble)hauteur_,
|
d*(GLdouble)largeur_ / (GLdouble)hauteur_,
|
||||||
-d, d,
|
-d, d,
|
||||||
0.1, 60.0 );
|
0.1, 300.0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glUniformMatrix4fv( locmatrProjBase, 1, GL_FALSE, matrProj );
|
glUniformMatrix4fv( locmatrProjBase, 1, GL_FALSE, matrProj );
|
||||||
|
@ -844,40 +781,6 @@ void FenetreTP::afficherScene()
|
||||||
if ( afficheAxes ) FenetreTP::afficherAxes( 8.0 );
|
if ( afficheAxes ) FenetreTP::afficherAxes( 8.0 );
|
||||||
|
|
||||||
// dessiner la scène
|
// dessiner la scène
|
||||||
afficherLumiere();
|
|
||||||
|
|
||||||
glUseProgram( prog );
|
|
||||||
|
|
||||||
// mettre à jour les blocs de variables uniformes
|
|
||||||
{
|
|
||||||
glBindBuffer( GL_UNIFORM_BUFFER, ubo[0] );
|
|
||||||
GLvoid *p = glMapBuffer( GL_UNIFORM_BUFFER, GL_WRITE_ONLY );
|
|
||||||
memcpy( p, &LightSource, sizeof(LightSource) );
|
|
||||||
glUnmapBuffer( GL_UNIFORM_BUFFER );
|
|
||||||
}
|
|
||||||
{
|
|
||||||
glBindBuffer( GL_UNIFORM_BUFFER, ubo[1] );
|
|
||||||
GLvoid *p = glMapBuffer( GL_UNIFORM_BUFFER, GL_WRITE_ONLY );
|
|
||||||
memcpy( p, &FrontMaterial, sizeof(FrontMaterial) );
|
|
||||||
glUnmapBuffer( GL_UNIFORM_BUFFER );
|
|
||||||
}
|
|
||||||
{
|
|
||||||
glBindBuffer( GL_UNIFORM_BUFFER, ubo[2] );
|
|
||||||
GLvoid *p = glMapBuffer( GL_UNIFORM_BUFFER, GL_WRITE_ONLY );
|
|
||||||
memcpy( p, &LightModel, sizeof(LightModel) );
|
|
||||||
glUnmapBuffer( GL_UNIFORM_BUFFER );
|
|
||||||
}
|
|
||||||
{
|
|
||||||
glBindBuffer( GL_UNIFORM_BUFFER, ubo[3] );
|
|
||||||
GLvoid *p = glMapBuffer( GL_UNIFORM_BUFFER, GL_WRITE_ONLY );
|
|
||||||
memcpy( p, &varsUnif, sizeof(varsUnif) );
|
|
||||||
glUnmapBuffer( GL_UNIFORM_BUFFER );
|
|
||||||
}
|
|
||||||
|
|
||||||
// mettre à jour les matrices et autres uniformes
|
|
||||||
glUniformMatrix4fv( locmatrProj, 1, GL_FALSE, matrProj );
|
|
||||||
glUniformMatrix4fv( locmatrVisu, 1, GL_FALSE, matrVisu );
|
|
||||||
glUniformMatrix4fv( locmatrModel, 1, GL_FALSE, matrModel );
|
|
||||||
//glActiveTexture( GL_TEXTURE0 ); // activer la texture '0' (valeur de défaut)
|
//glActiveTexture( GL_TEXTURE0 ); // activer la texture '0' (valeur de défaut)
|
||||||
glUniform1i( loclaTexture, 0 ); // '0' => utilisation de GL_TEXTURE0
|
glUniform1i( loclaTexture, 0 ); // '0' => utilisation de GL_TEXTURE0
|
||||||
|
|
||||||
|
@ -941,8 +844,9 @@ void FenetreTP::clavier( TP_touche touche )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TP_r: // Alterner entre le modèle de réflexion spéculaire: Phong, Blinn
|
case TP_r: // Alterner entre le modèle de réflexion spéculaire: Phong, Blinn
|
||||||
varsUnif.utiliseBlinn = !varsUnif.utiliseBlinn;
|
// Send one wave front
|
||||||
echoEtats( );
|
packets->CreateCircularWavefront(0.0, 0.0, 2.0, 0.2, 1.0, 10000);
|
||||||
|
printf("Sending a circular wavefront...\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TP_s: // Alterner entre le modèle de spot: OpenGL, Direct3D
|
case TP_s: // Alterner entre le modèle de spot: OpenGL, Direct3D
|
||||||
|
|
4
util.cpp
4
util.cpp
|
@ -91,9 +91,9 @@ checkglerr(const char *msg, const int line)
|
||||||
while ((err = glGetError()) != GL_NO_ERROR)
|
while ((err = glGetError()) != GL_NO_ERROR)
|
||||||
{
|
{
|
||||||
if (err >= GL_INVALID_ENUM && err <= GL_INVALID_FRAMEBUFFER_OPERATION)
|
if (err >= GL_INVALID_ENUM && err <= GL_INVALID_FRAMEBUFFER_OPERATION)
|
||||||
fprintf(stderr, "%s l.%d\n", errors[err - GL_INVALID_ENUM], line);
|
fprintf(stderr, "%s : %s l.%d\n", msg, errors[err - GL_INVALID_ENUM], line);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Unknown error l.%d\n", line);
|
fprintf(stderr, "%s : Unknown error l.%d\n", msg, line);
|
||||||
++rc;
|
++rc;
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Reference in a new issue