I've used the following code (with sampleAmount set to 256 or 181):
Code: Select all
SMesh* m =new SMesh();
SMeshBuffer* mb = new SMeshBuffer();
m->addMeshBuffer(mb);
mb->drop();
mb->Vertices.reallocate(sampleAmount*sampleAmount);
mb->Vertices.set_used(sampleAmount*sampleAmount);
mb->Indices.reallocate(3*2*(sampleAmount-1)*(sampleAmount-1));
mb->Indices.set_used(3*2*(sampleAmount-1)*(sampleAmount-1));
for(int i=0; i<sampleAmount*sampleAmount; i++){
mb->Vertices[i] = S3DVertex(-1.f+(float)(i%sampleAmount)*2.f/(float)(sampleAmount-1), 0.f, 1.f-(float)(i/sampleAmount)*2.f/(float)(sampleAmount-1), 0.f, 1.f, 0.f, SColor(255,255,255,255), (float)(i%sampleAmount)/(float)(sampleAmount-1), (float)(i/sampleAmount)/(float)(sampleAmount-1));
}
int i = 0;
for(int x=0; x<(sampleAmount-1); x++){//vom letzten Vertex einer Spalte/Reihe geht kein Dreieck aus, daher (sampleAmount-1)
for(int y=0; y<(sampleAmount-1); y++){
//int i = (x+y*sampleAmount)*3*2;
mb->Indices[i] = x+y*sampleAmount;
mb->Indices[i+1] = (x+1)+y*sampleAmount;
mb->Indices[i+2] = x+(y+1)*sampleAmount;
mb->Indices[i+3] = (x+1)+y*sampleAmount;
mb->Indices[i+4] = (x+1)+(y+1)*sampleAmount;
mb->Indices[i+5] = x+(y+1)*sampleAmount;
i += 6;
}
}
mb->recalculateBoundingBox();
mb->setHardwareMappingHint(EHM_STATIC, EBT_VERTEX_AND_INDEX);
mb->setDirty(EBT_VERTEX_AND_INDEX);
m->recalculateBoundingBox();
m->setHardwareMappingHint(EHM_STATIC, EBT_VERTEX_AND_INDEX);
m->setDirty(EBT_VERTEX_AND_INDEX);