fill out draw()
This commit is contained in:
parent
e07ed46297
commit
a12c4ec42d
30
WFObj.cc
30
WFObj.cc
@ -450,7 +450,7 @@ bool WFObj::buildVBO()
|
||||
{
|
||||
map<VertexRef, int> flat_vertices;
|
||||
int vid = 0, texture_ref_count = 0, n_vrefs = 0;
|
||||
bool do_textures = m_loadtexture != NULL
|
||||
m_do_textures = m_loadtexture != NULL
|
||||
&& m_vertices[VERTEX_TEXTURE].size() > 0;
|
||||
for (map<string, vector<Face> >::iterator it = m_faces.begin();
|
||||
it != m_faces.end();
|
||||
@ -486,18 +486,18 @@ bool WFObj::buildVBO()
|
||||
}
|
||||
}
|
||||
if (texture_ref_count == 0)
|
||||
do_textures = false;
|
||||
size_t n_floats_per_vref =
|
||||
m_do_textures = false;
|
||||
m_n_floats_per_vref =
|
||||
3 + /* vertex coordinates */
|
||||
3 + /* normal coordinates */
|
||||
(do_textures ? 2 : 0); /* texture coordinates */
|
||||
size_t n_data_elements = n_floats_per_vref * flat_vertices.size();
|
||||
(m_do_textures ? 2 : 0); /* texture coordinates */
|
||||
size_t n_data_elements = m_n_floats_per_vref * flat_vertices.size();
|
||||
GLfloat * data = new GLfloat[n_data_elements];
|
||||
for (map<VertexRef, int>::iterator it = flat_vertices.begin();
|
||||
it != flat_vertices.end();
|
||||
it++)
|
||||
{
|
||||
int base = n_floats_per_vref * it->second;
|
||||
int base = m_n_floats_per_vref * it->second;
|
||||
VertexRef vr = it->first;
|
||||
data[base + 0] = m_vertices[VERTEX][vr.vertex - 1][0];
|
||||
data[base + 1] = m_vertices[VERTEX][vr.vertex - 1][1];
|
||||
@ -505,7 +505,7 @@ bool WFObj::buildVBO()
|
||||
data[base + 3] = m_vertices[VERTEX_NORMAL][vr.normal - 1][0];
|
||||
data[base + 4] = m_vertices[VERTEX_NORMAL][vr.normal - 1][1];
|
||||
data[base + 5] = m_vertices[VERTEX_NORMAL][vr.normal - 1][2];
|
||||
if (do_textures && vr.texture > 0)
|
||||
if (m_do_textures && vr.texture > 0)
|
||||
{
|
||||
data[base + 6] = m_vertices[VERTEX_TEXTURE][vr.texture - 1][0];
|
||||
data[base + 7] = m_vertices[VERTEX_TEXTURE][vr.texture - 1][1];
|
||||
@ -551,14 +551,30 @@ void WFObj::draw()
|
||||
return;
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_data_vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_vbo);
|
||||
glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
size_t stride = sizeof(GLfloat) * m_n_floats_per_vref;
|
||||
glVertexPointer(3, GL_FLOAT, stride, NULL);
|
||||
glNormalPointer(GL_FLOAT, stride, (GLvoid *) (sizeof(GLfloat) * 3));
|
||||
if (m_do_textures)
|
||||
{
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(2, GL_FLOAT, stride,
|
||||
(GLvoid *) (sizeof(GLfloat) * 6));
|
||||
}
|
||||
for (map<string, vector<Face> >::iterator it = m_faces.begin();
|
||||
it != m_faces.end();
|
||||
it++)
|
||||
{
|
||||
glPushAttrib(GL_LIGHTING_BIT);
|
||||
renderMaterial(m_materials[it->first]);
|
||||
glDrawElements(GL_TRIANGLES, m_face_indices[it->first].second,
|
||||
GL_UNSIGNED_SHORT,
|
||||
(GLvoid *) (sizeof(GLfloat) * m_face_indices[it->first].first));
|
||||
glPopAttrib();
|
||||
}
|
||||
glPopClientAttrib();
|
||||
}
|
||||
|
||||
void WFObj::renderMaterial(const WFObj::Material & m)
|
||||
|
Loading…
x
Reference in New Issue
Block a user