В OGL все однозначно: надо переключать текстуры и координаты для них.
Про VBO, где на форуме было...
Вначале генеришь буфера:
Код:
for ( ulong_t i=0; i<count_meshs; i++ ) {
glGenBuffers(1, &bufferID[i]);
glBindBuffer(GL_ARRAY_BUFFER, bufferID[i]);
off_tex[i] = (sizeof(SVector3f) * meshs[i].count_vertexs);
off_nor[i] = off_tex[i] + (sizeof(SVector2f) * meshs[i].count_vertexs);
glBufferData(GL_ARRAY_BUFFER,
( off_nor[i] + sizeof(SVector3f) * meshs[i].count_vertexs), NULL, GL_STATIC_DRAW );
buf_map = (byte*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
memcpy(buf_map, meshs[i].vertexs, meshs[i].count_vertexs*sizeof(SVector3f));
memcpy((buf_map+off_tex[i]), meshs[i].tex_coords, meshs[i].count_vertexs*sizeof(SVector2f));
memcpy((buf_map + off_nor[i]), meshs[i].normals, meshs[i].count_vertexs*sizeof(SVector3f));
glUnmapBuffer(GL_ARRAY_BUFFER);
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
потом их задаешь
Код:
glBindBuffer(GL_ARRAY_BUFFER, bufferID[i]);
glVertexPointer(3, GL_FLOAT, 0, 0);
glTexCoordPointer(2, GL_FLOAT, 0, (GLvoid*)off_tex[i]);
if ( yes_blend==true )
glNormalPointer(GL_FLOAT, 0, (GLvoid*)off_nor[i] );
Потом рендеришь:
Код:
glDrawElements(GL_TRIANGLES, //mesh->count_tri*3, GL_UNSIGNED_INT, mesh->index_tri);
mesh->sub_meshs[j].count_tri*3, GL_UNSIGNED_INT, mesh->sub_meshs[j].index_tri);
Кстати, только счас увидел, в 3DS есть submesh!
Код:
for ( j=0; j<mesh->count_sub_meshs; j++ ) {
material = mesh->sub_meshs[j].material;
if ( yes_blend==true ) {
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material->ambient.v);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material->diffuse.v);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material->specular.v);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material->emissive.v);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else
glDisable(GL_BLEND);
tex = (CTexture_OGL *)material->textures[0].tex;
if ( tex!=0 )
tex->bind_texture(); // [b]вот здесь привязка текстуры[/b]
glDrawElements(GL_TRIANGLES, //mesh->count_tri*3, GL_UNSIGNED_INT, mesh->index_tri);
mesh->sub_meshs[j].count_tri*3, GL_UNSIGNED_INT, mesh->sub_meshs[j].index_tri);
}