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