a deriver pour creer les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
75 {
77
78 #if 1
79
80 struct vertex
81 {
82 glsl::vec3 position;
83 glsl::vec3 normal;
84 glsl::vec2 texcoord;
85
86 vertex( ) : position(), normal(), texcoord() {}
87 };
88
89 #else
90
91 struct vertex
92 {
93 vec3 position;
94 float pad0;
95 vec3 normal;
96 float pad1;
97 vec2 texcoord;
98
99 float pad2;
100 float pad3;
101
102 vertex( ) : position(), normal(), texcoord() {}
103 };
104 #endif
105
106
107
108 std::vector<vertex> data(m_mesh.vertex_count());
109 for(int i= 0; i < m_mesh.vertex_count(); i++)
110 {
111 data[i].position= m_mesh.positions().at(i);
112 data[i].normal= m_mesh.normals().at(i);
113 data[i].texcoord= m_mesh.texcoords().at(i);
114 }
115
116
117 glGenVertexArrays(1, &m_vao);
118 glBindVertexArray(m_vao);
119
120
121 glGenBuffers(1, &m_buffer);
122
123 glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_buffer);
124 glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(vertex) * data.size(), data.data(), GL_STREAM_READ);
125
126
127 m_program=
read_program(
"gkit2_tutos/tuto_storage_buffer.glsl");
129
130
131 Point pmin, pmax;
132 m_mesh.bounds(pmin, pmax);
133 m_camera.lookat(pmin, pmax);
134
136
137
138 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
139
140 glClearDepth(1.f);
141 glDepthFunc(GL_LESS);
142 glEnable(GL_DEPTH_TEST);
143
144 return 0;
145 }
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
GLuint read_program(const char *filename, const char *definitions)
int program_print_errors(const GLuint program)
affiche les erreurs de compilation.
GLuint read_texture(const int unit, const char *filename, const GLenum texel_type)