• Create Account

Banner advertising on our site currently available from just \$5!

#ActualSponji

Posted 03 July 2013 - 02:05 PM

I think your verticiesFront is totally wrong. Just think about the values, those are from -size*x to +size*x. I would do just size*x and size*(x+1). Or if you really want the tile's center to be at zero: x*size - halfSize and x*size + halfSize.

Those positions are inside the chunk. And when you're rendering you could translate those chunks by tileSize * numberOfTiles (seems that you're already doing that). It probably also helps reading if you keep your tile size as 1.

Here is some pseudo code:

// Update chunk
void update(chunk) {
vertices[];
foreach(tile) {
if(face_front) {
// I keep the tile size as 1 in this case, so the tile's start is at 0 and end is at 1
// Let's create a quad for the current tile
Vertex v0(tile.x,   tile.y,   tile.z+1);
Vertex v1(tile.x+1, tile.y,   tile.z+1);
Vertex v2(tile.x+1, tile.y+1, tile.z+1);
Vertex v3(tile.x,   tile.y+1, tile.z+1);
// And add it into the array
}
}
// And finally, create a vertexbuffer from those vertices
chunk.vbo = create_vbo(vertices);
}

void render(chunk) {
// chunk.size means the number of tiles per one axis
translate(chunk.position * chunk.size);
render(chunk.vbo);
}

Can I draw using my old method and somehow extract the raw vertex data from OpenGL *after* I have done all the glTranslatef() calls and my mesh is complete inside OpenGL's current frame?

Yes, but I wouldn't suggest that, because you should use your own matrices. But just in case, it goes something like this in C:

float matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);

Translation part is in the last column, matrix[12], matrix[13], matrix[14].

Btw, plural of vertex is vertices.

#1Sponji

Posted 03 July 2013 - 02:03 PM

I think your verticiesFront is totally wrong. Just think about the values, those are from -size*x to +size*x. I would do just size*x and size*(x+1). Or if you really want the tile's center to be at zero: x*size - halfSize and x*size + halfSize.

Those positions are inside the chunk. And when you're rendering you could translate those chunks by tileSize * numberOfTiles (seems that you're already doing that). It probably also helps reading if you keep your tile size as 1.

Here is some pseudo code:

// Update chunk
void update(chunk) {
vertices[];
foreach(tile) {
if(face_front) {
// I keep the tile size as 1 in this case, so the tile's start is at 0 and end is at 1
// Let's create a quad for the current tile
Vertex v0(tile.x,   tile.y,   tile.z+1);
Vertex v1(tile.x+1, tile.y,   tile.z+1);
Vertex v2(tile.x+1, tile.y+1, tile.z+1);
Vertex v3(tile.x,   tile.y+1, tile.z+1);
// And add it into the array
}
}
// And finally, create a vertexbuffer from those vertices
chunk.vbo = create_vbo(vertices);
}

void render(chunk) {
// chunk.size means the number of tiles per one axis
translate(chunk.position * chunk.size);
render(chunk.vbo);
}

No idea why my identation did not work, I blame this silly forum software.

Can I draw using my old method and somehow extract the raw vertex data from OpenGL *after* I have done all the glTranslatef() calls and my mesh is complete inside OpenGL's current frame?

Yes, but I wouldn't suggest that, because you should use your own matrices. But just in case, it goes something like this in C:

float matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);

Translation part is in the last column, matrix[12], matrix[13], matrix[14].

Btw, plural of vertex is vertices.

PARTNERS