mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 16:55:07 +02:00
fix rendering bugs
This commit is contained in:
parent
fc3a499cb3
commit
e8f84aee78
2 changed files with 10 additions and 4 deletions
|
@ -82,8 +82,6 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode) {
|
|||
float * startVertex = firstVertexForCode(currentNode->octalCode);
|
||||
float voxelScale = 1 / powf(2, *currentNode->octalCode);
|
||||
|
||||
printf("Adding a voxel at %f, %f, %f\n", startVertex[0], startVertex[1], startVertex[2]);
|
||||
|
||||
// populate the array with points for the 8 vertices
|
||||
// and RGB color for each added vertex
|
||||
for (int j = 0; j < VERTEX_POINTS_PER_VOXEL; j++ ) {
|
||||
|
@ -93,6 +91,8 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode) {
|
|||
verticesEndPointer++;
|
||||
}
|
||||
|
||||
delete [] startVertex;
|
||||
|
||||
voxelsAdded++;
|
||||
}
|
||||
|
||||
|
@ -170,6 +170,7 @@ void VoxelSystem::render() {
|
|||
|
||||
// draw the number of voxels we have
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID);
|
||||
glScalef(10, 10, 10);
|
||||
glDrawElements(GL_TRIANGLES, 36 * voxelsRendered, GL_UNSIGNED_INT, 0);
|
||||
|
||||
// deactivate vertex and color arrays after drawing
|
||||
|
|
|
@ -20,7 +20,7 @@ int numberOfThreeBitSectionsInCode(unsigned char * octalCode) {
|
|||
}
|
||||
|
||||
void printOctalCode(unsigned char * octalCode) {
|
||||
for (int i = 1; i < bytesRequiredForCodeLength(*octalCode); i++) {
|
||||
for (int i = 0; i < bytesRequiredForCodeLength(*octalCode); i++) {
|
||||
outputBits(octalCode[i]);
|
||||
}
|
||||
}
|
||||
|
@ -108,11 +108,16 @@ float * firstVertexForCode(unsigned char * octalCode) {
|
|||
float * firstVertex = new float[3];
|
||||
memset(firstVertex, 0, 3 * sizeof(float));
|
||||
|
||||
float currentScale = 0.5;
|
||||
|
||||
for (int i = 0; i < numberOfThreeBitSectionsInCode(octalCode); i++) {
|
||||
int sectionIndex = sectionValue(octalCode + 1 + (3 * i / 8), (3 * i) % 8);
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
firstVertex[j] += 0.5 * (int)oneAtBit(sectionIndex, 7 -j);
|
||||
firstVertex[j] += currentScale * (int)oneAtBit(sectionIndex, 5 + j);
|
||||
}
|
||||
|
||||
currentScale *= 0.5;
|
||||
}
|
||||
|
||||
return firstVertex;
|
||||
|
|
Loading…
Reference in a new issue