medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit a37512ca8d6d51f41db97001d9ed9e5a635cbdc5
parent 2f911485a3b21d27a822eb3f991f8a8861b4200e
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Aug 16 20:32:11 +0200

Fix gaps between tiles

Diffstat:
heightmap.cc | 2+-
pp.cc | 17+++++++++--------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/heightmap.cc b/heightmap.cc @@ -343,5 +343,5 @@ void Heightmap::render( const glm::mat4 & VP ) const { glEnableVertexAttribArray( at_lit ); glVertexAttribPointer( at_lit, 1, GL_FLOAT, GL_FALSE, 0, 0 ); - glDrawElements( GL_TRIANGLES, ( w - 1 ) * ( h - 1 ) * 6, GL_UNSIGNED_INT, 0 ); + glDrawElements( GL_TRIANGLES, w * h * 6, GL_UNSIGNED_INT, 0 ); } diff --git a/pp.cc b/pp.cc @@ -10,36 +10,37 @@ #include "stb_image_write.h" const int TILE_SIZE = 128; +const int OUT_SIZE = TILE_SIZE + 1; int w, h; u8 * pixels; void write_tile( const std::string & dir, const int tx, const int ty ) { - u8 tile[ TILE_SIZE * TILE_SIZE ]; + u8 tile[ OUT_SIZE * OUT_SIZE ]; - for( int y = 0; y < TILE_SIZE; y++ ) { - for( int x = 0; x < TILE_SIZE; x++ ) { + for( int y = 0; y <= TILE_SIZE; y++ ) { + for( int x = 0; x <= TILE_SIZE; x++ ) { const int gy = ty * TILE_SIZE + y; const int gx = tx * TILE_SIZE + x; if( gy >= h || gx >= w ) { - tile[ y * TILE_SIZE + x ] = 0; + tile[ y * OUT_SIZE + x ] = 0; } else { - tile[ y * TILE_SIZE + x ] = pixels[ ( ty * TILE_SIZE + y ) * w + tx * TILE_SIZE + x ]; + tile[ y * OUT_SIZE + x ] = pixels[ gy * w + gx ]; } } } - const std::string file = dir + "/" + std::to_string( tx ) + "_" + std::to_string( ty ) + ".tga"; + const std::string file = dir + "/" + std::to_string( tx ) + "_" + std::to_string( ty ) + ".tga"; printf( "writing tile %s\n", file.c_str() ); - stbi_write_tga( file.c_str(), TILE_SIZE, TILE_SIZE, 1, tile ); + stbi_write_tga( file.c_str(), OUT_SIZE, OUT_SIZE, 1, tile ); } int main( int argc, char ** argv ) { const std::string path = argc == 2 ? argv[ 1 ] : "mountains512.png"; pixels = stbi_load( path.c_str(), &w, &h, nullptr, 1 ); - + const std::string dir = path + ".parts"; mkdir( dir.c_str(), 0755 );