-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTable.cpp
More file actions
83 lines (65 loc) · 2.59 KB
/
Table.cpp
File metadata and controls
83 lines (65 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "Table.h"
#include "texture.h"
#include <iostream>
using namespace std;
Table::Table(Program *program) : Mesh(program)
{
// Définition des VertexData
const struct
{
float x, y, z;
float xn, yn, zn;
float u, v;
} vertices[4] =
{
{ -0.5f, -0.5f, 0.f, 0.f, 0.f, 1.0f, 0.f, 0.f },
{ +0.5f, -0.5f, 0.f, 0.f, 0.f, 1.0f, 1.f, 0.f },
{ +0.5f, +0.5f, 0.f, 0.f, 0.f, 1.0f, 1.f, 1.f },
{ -0.5f, +0.5f, 0.f, 0.f, 0.f, 1.0f, 0.f, 1.f }
};
GLint vpos_location, vnor_location, vtex_location, tex_location;
GLuint texture, sampler, texUnit;
// Creation de la texture
texture = createTexture("textures/Rock_wall/diffuse.png");
// Récupération des "location" des variable du pipeline
vpos_location = glGetAttribLocation(program->getId(), "vPos");
vnor_location = glGetAttribLocation(program->getId(), "vNor");
vtex_location = glGetAttribLocation(program->getId(), "vTex");
tex_location = glGetUniformLocation(program->getId(), "Tex");
// Création du VertexArray
glGenVertexArrays(1, &vertex_array);
glBindVertexArray(vertex_array);
// Définition du vertexBuffer
GLuint vertex_buffer;
glGenBuffers(1, &vertex_buffer);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, vertex_buffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_COPY);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
program->bind();
// Association des 3 1ères composantes des VertexData à la variable "vPos" du pipeline
glEnableVertexAttribArray(vpos_location);
glVertexAttribPointer(vpos_location, 3, GL_FLOAT, GL_FALSE, sizeof(vertices[0]), (void*) 0);
// Association des 3 composantes suivantes des VertexData à la variable "vNor" du pipeline
// glEnableVertexAttribArray(vnor_location);
// glVertexAttribPointer(vnor_location, 3, GL_FLOAT, GL_FALSE, sizeof(vertices[0]), (void*) (sizeof(float) * 3));
// Association des 2 composantes suivantes des VertexData à la variable "vTex" du pipeline
glEnableVertexAttribArray(vtex_location);
glVertexAttribPointer(vtex_location, 2, GL_FLOAT, GL_FALSE, sizeof(vertices[0]), (void*) (sizeof(float) * 6));
// Association de la texture à la variable "Tex"
texUnit = 1;
glUniform1i(tex_location, texUnit);
glActiveTexture(GL_TEXTURE0 + texUnit);
glBindTexture(GL_TEXTURE_2D, texture);
program->unbind();
}
void Table::render(mat4 model)
{
//Mesh::render(projection, view, model);
getProgram()->begin(model);
// Selection du VertexArray
glBindVertexArray(vertex_array);
// Affichage des 4 1ers sommets en utilisant des triangles fan.
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
getProgram()->end();
}