Added generation of background.

This commit is contained in:
Miroslav Bendík 2012-08-23 14:21:34 +02:00
parent a6abd1445d
commit 0d8358d4e3
3 changed files with 30 additions and 4 deletions

@ -10,6 +10,8 @@ endif(CMAKE_COMPILER_IS_GNUCXX)
find_package(PkgConfig) find_package(PkgConfig)
include(FindPackageHandleStandardArgs)
pkg_check_modules(PC_LIBSQLITE QUIET sqlite3) pkg_check_modules(PC_LIBSQLITE QUIET sqlite3)
set(LIBSQLITE3_DEFINITIONS ${PC_LIBSQLITE_CFLAGS_OTHER}) set(LIBSQLITE3_DEFINITIONS ${PC_LIBSQLITE_CFLAGS_OTHER})
@ -19,7 +21,6 @@ find_library(LIBSQLITE3_LIBRARY NAMES sqlite3 libsqlite3 HINTS ${PC_LIBSQLITE_LI
set(LIBSQLITE3_LIBRARIES ${LIBSQLITE3_LIBRARY} ) set(LIBSQLITE3_LIBRARIES ${LIBSQLITE3_LIBRARY} )
set(LIBSQLITE3_INCLUDE_DIRS ${LIBSQLITE3_INCLUDE_DIR} ) set(LIBSQLITE3_INCLUDE_DIRS ${LIBSQLITE3_INCLUDE_DIR} )
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibSqlite3 DEFAULT_MSG LIBSQLITE3_LIBRARY LIBSQLITE3_INCLUDE_DIR) find_package_handle_standard_args(LibSqlite3 DEFAULT_MSG LIBSQLITE3_LIBRARY LIBSQLITE3_INCLUDE_DIR)
mark_as_advanced(LIBSQLITE3_INCLUDE_DIR LIBSQLITE3_LIBRARY ) mark_as_advanced(LIBSQLITE3_INCLUDE_DIR LIBSQLITE3_LIBRARY )
@ -50,4 +51,5 @@ add_executable(minetest_mapper
target_link_libraries( target_link_libraries(
minetest_mapper minetest_mapper
${LIBSQLITE3_LIBRARIES} ${LIBSQLITE3_LIBRARIES}
gd
) )

@ -7,6 +7,7 @@
* ===================================================================== * =====================================================================
*/ */
#include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
@ -24,6 +25,7 @@ TileGenerator::TileGenerator():
m_drawScale(false), m_drawScale(false),
m_drawUnderground(false), m_drawUnderground(false),
m_db(0), m_db(0),
m_image(0),
m_xMin(0), m_xMin(0),
m_xMax(0), m_xMax(0),
m_zMin(0), m_zMin(0),
@ -112,10 +114,12 @@ void TileGenerator::parseColorsFile(const std::string &fileName)
} }
} }
void TileGenerator::generate(const std::string &input, const std::string &/*output*/) void TileGenerator::generate(const std::string &input, const std::string &output)
{ {
openDb(input); openDb(input);
loadBlocks(); loadBlocks();
createImage();
writeImage(output);
} }
void TileGenerator::openDb(const std::string &input) void TileGenerator::openDb(const std::string &input)
@ -157,8 +161,6 @@ void TileGenerator::loadBlocks()
break; break;
} }
} }
m_imgWidth = (m_xMax - m_xMin) * 16;
m_imgHeight = (m_zMax - m_zMin) * 16;
} }
else { else {
throw DbError(); throw DbError();
@ -186,3 +188,21 @@ inline int TileGenerator::unsignedToSigned(long i, long max_positive)
} }
} }
void TileGenerator::createImage()
{
m_imgWidth = (m_xMax - m_xMin) * 16;
m_imgHeight = (m_zMax - m_zMin) * 16;
m_image = gdImageCreate(m_imgWidth, m_imgHeight);
// Background
gdImageColorAllocate(m_image, 255, 255, 255);
}
void TileGenerator::writeImage(const std::string &output)
{
FILE *out;
out = fopen(output.c_str(), "w");
gdImagePng(m_image, out);
fclose(out);
gdImageDestroy(m_image);
}

@ -10,6 +10,7 @@
#ifndef TILEGENERATOR_H_JJNUCARH #ifndef TILEGENERATOR_H_JJNUCARH
#define TILEGENERATOR_H_JJNUCARH #define TILEGENERATOR_H_JJNUCARH
#include <gd.h>
#include <map> #include <map>
#include <sqlite3.h> #include <sqlite3.h>
#include <stdint.h> #include <stdint.h>
@ -54,6 +55,8 @@ private:
void loadBlocks(); void loadBlocks();
BlockPos decodeBlockPos(sqlite3_int64 blockId); BlockPos decodeBlockPos(sqlite3_int64 blockId);
int unsignedToSigned(long i, long max_positive); int unsignedToSigned(long i, long max_positive);
void createImage();
void writeImage(const std::string &output);
private: private:
std::string m_bgColor; std::string m_bgColor;
@ -66,6 +69,7 @@ private:
bool m_drawUnderground; bool m_drawUnderground;
sqlite3 *m_db; sqlite3 *m_db;
gdImagePtr m_image;
int m_xMin; int m_xMin;
int m_xMax; int m_xMax;
int m_zMin; int m_zMin;