Skip to content

Commit

Permalink
Solve "Failed to create texture, its internal size is too high" probl…
Browse files Browse the repository at this point in the history
…em on some machines
  • Loading branch information
hckr committed Sep 5, 2017
1 parent 89eb321 commit e731451
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
Binary file modified dist/assets/tileset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 15 additions & 15 deletions tileset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ const SpriteInfo astronaut_NE = { 31, 47, { sf::Vector2f(217, 0), sf::Vector2f(2
const SpriteInfo metalTileConnectStraight_NE = { 76, 56, { sf::Vector2f(248, 0), sf::Vector2f(324, 0), sf::Vector2f(324, 56), sf::Vector2f(248, 56) } };
const SpriteInfo metalTileConnectSide_NW = { 76, 55, { sf::Vector2f(324, 0), sf::Vector2f(400, 0), sf::Vector2f(400, 55), sf::Vector2f(324, 55) } };
const SpriteInfo metalTileConnectCornerInner_SW = { 76, 54, { sf::Vector2f(400, 0), sf::Vector2f(476, 0), sf::Vector2f(476, 54), sf::Vector2f(400, 54) } };
const SpriteInfo metalTileConnectCornerInner_NW = { 76, 54, { sf::Vector2f(476, 0), sf::Vector2f(552, 0), sf::Vector2f(552, 54), sf::Vector2f(476, 54) } };
const SpriteInfo metalTileConnectSide_SW = { 76, 54, { sf::Vector2f(552, 0), sf::Vector2f(628, 0), sf::Vector2f(628, 54), sf::Vector2f(552, 54) } };
const SpriteInfo metalTileConnectStraight_NW = { 76, 56, { sf::Vector2f(628, 0), sf::Vector2f(704, 0), sf::Vector2f(704, 56), sf::Vector2f(628, 56) } };
const SpriteInfo metalTileConnectCenter_NE = { 75, 54, { sf::Vector2f(704, 0), sf::Vector2f(779, 0), sf::Vector2f(779, 54), sf::Vector2f(704, 54) } };
const SpriteInfo metalTileConnectEnd_SW = { 72, 54, { sf::Vector2f(779, 0), sf::Vector2f(851, 0), sf::Vector2f(851, 54), sf::Vector2f(779, 54) } };
const SpriteInfo metalTileConnectEnd_NW = { 72, 54, { sf::Vector2f(851, 0), sf::Vector2f(923, 0), sf::Vector2f(923, 54), sf::Vector2f(851, 54) } };
const SpriteInfo metalTileConnectCornerInner_NE = { 72, 56, { sf::Vector2f(923, 0), sf::Vector2f(995, 0), sf::Vector2f(995, 56), sf::Vector2f(923, 56) } };
const SpriteInfo metalTileConnectCornerInner_SE = { 72, 56, { sf::Vector2f(995, 0), sf::Vector2f(1067, 0), sf::Vector2f(1067, 56), sf::Vector2f(995, 56) } };
const SpriteInfo metalTileConnectEnd_NE = { 72, 54, { sf::Vector2f(1067, 0), sf::Vector2f(1139, 0), sf::Vector2f(1139, 54), sf::Vector2f(1067, 54) } };
const SpriteInfo metalTileConnectSide_NE = { 76, 55, { sf::Vector2f(1139, 0), sf::Vector2f(1215, 0), sf::Vector2f(1215, 55), sf::Vector2f(1139, 55) } };
const SpriteInfo metalTileConnectEnd_SE = { 72, 54, { sf::Vector2f(1215, 0), sf::Vector2f(1287, 0), sf::Vector2f(1287, 54), sf::Vector2f(1215, 54) } };
const SpriteInfo metalTileConnectSide_SE = { 76, 55, { sf::Vector2f(1287, 0), sf::Vector2f(1363, 0), sf::Vector2f(1363, 55), sf::Vector2f(1287, 55) } };
const SpriteInfo spaceCraft3_NE = { 78, 58, { sf::Vector2f(1363, 0), sf::Vector2f(1441, 0), sf::Vector2f(1441, 58), sf::Vector2f(1363, 58) } };
const SpriteInfo metalFenceCorner_SW = { 36, 58, { sf::Vector2f(1441, 0), sf::Vector2f(1477, 0), sf::Vector2f(1477, 58), sf::Vector2f(1441, 58) } };
const SpriteInfo metalFenceCorner_NW = { 36, 58, { sf::Vector2f(1477, 0), sf::Vector2f(1513, 0), sf::Vector2f(1513, 58), sf::Vector2f(1477, 58) } };
const SpriteInfo metalTileConnectCornerInner_NW = { 76, 54, { sf::Vector2f(0, 56), sf::Vector2f(76, 56), sf::Vector2f(76, 110), sf::Vector2f(0, 110) } };
const SpriteInfo metalTileConnectSide_SW = { 76, 54, { sf::Vector2f(76, 56), sf::Vector2f(152, 56), sf::Vector2f(152, 110), sf::Vector2f(76, 110) } };
const SpriteInfo metalTileConnectStraight_NW = { 76, 56, { sf::Vector2f(152, 56), sf::Vector2f(228, 56), sf::Vector2f(228, 112), sf::Vector2f(152, 112) } };
const SpriteInfo metalTileConnectCenter_NE = { 75, 54, { sf::Vector2f(228, 56), sf::Vector2f(303, 56), sf::Vector2f(303, 110), sf::Vector2f(228, 110) } };
const SpriteInfo metalTileConnectEnd_SW = { 72, 54, { sf::Vector2f(303, 56), sf::Vector2f(375, 56), sf::Vector2f(375, 110), sf::Vector2f(303, 110) } };
const SpriteInfo metalTileConnectEnd_NW = { 72, 54, { sf::Vector2f(375, 56), sf::Vector2f(447, 56), sf::Vector2f(447, 110), sf::Vector2f(375, 110) } };
const SpriteInfo metalTileConnectCornerInner_NE = { 72, 56, { sf::Vector2f(0, 112), sf::Vector2f(72, 112), sf::Vector2f(72, 168), sf::Vector2f(0, 168) } };
const SpriteInfo metalTileConnectCornerInner_SE = { 72, 56, { sf::Vector2f(72, 112), sf::Vector2f(144, 112), sf::Vector2f(144, 168), sf::Vector2f(72, 168) } };
const SpriteInfo metalTileConnectEnd_NE = { 72, 54, { sf::Vector2f(144, 112), sf::Vector2f(216, 112), sf::Vector2f(216, 166), sf::Vector2f(144, 166) } };
const SpriteInfo metalTileConnectSide_NE = { 76, 55, { sf::Vector2f(216, 112), sf::Vector2f(292, 112), sf::Vector2f(292, 167), sf::Vector2f(216, 167) } };
const SpriteInfo metalTileConnectEnd_SE = { 72, 54, { sf::Vector2f(292, 112), sf::Vector2f(364, 112), sf::Vector2f(364, 166), sf::Vector2f(292, 166) } };
const SpriteInfo metalTileConnectSide_SE = { 76, 55, { sf::Vector2f(364, 112), sf::Vector2f(440, 112), sf::Vector2f(440, 167), sf::Vector2f(364, 167) } };
const SpriteInfo spaceCraft3_NE = { 78, 58, { sf::Vector2f(0, 168), sf::Vector2f(78, 168), sf::Vector2f(78, 226), sf::Vector2f(0, 226) } };
const SpriteInfo metalFenceCorner_SW = { 36, 58, { sf::Vector2f(78, 168), sf::Vector2f(114, 168), sf::Vector2f(114, 226), sf::Vector2f(78, 226) } };
const SpriteInfo metalFenceCorner_NW = { 36, 58, { sf::Vector2f(114, 168), sf::Vector2f(150, 168), sf::Vector2f(150, 226), sf::Vector2f(114, 226) } };

}
29 changes: 19 additions & 10 deletions tools/tileset_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,32 @@
images += [ { 'scale_factor': 0.5, 'file_name': f } for f in glob('../gfx/*spaceCraft3*') ]
images += [ { 'scale_factor': 0.5, 'file_name': f } for f in glob('../gfx/*Fence*') ]

tilemap_temp = Image.new('RGBA', (5000, 100), (255, 0, 0, 0))
tilemap_temp = Image.new('RGBA', (1000, 1000), (255, 0, 0, 0))

curr_x = 0
max_y = 0
curr_y = 0
max_image_y_in_line = 0
max_line_width = 0

sprites = []

for image in images:
im = Image.open(image['file_name'])
scaled_im = im.resize((round(im.width * image['scale_factor']), round(im.height * image['scale_factor'])), Image.LANCZOS)
tilemap_temp.paste(scaled_im, (curr_x, 0))
tilemap_temp.paste(scaled_im, (curr_x, curr_y))
sprites.append({ 'name': splitext(basename(image['file_name']))[0], 'posX': curr_x,
'width': scaled_im.width, 'height': scaled_im.height })
'posY': curr_y, 'width': scaled_im.width, 'height': scaled_im.height })
curr_x += scaled_im.width
max_y = max(scaled_im.height, max_y)
max_image_y_in_line = max(scaled_im.height, max_image_y_in_line)
if curr_x > 400:
max_line_width = max(max_line_width, curr_x)
curr_x = 0
curr_y += max_image_y_in_line
else:
max_line_width = max(max_line_width, curr_x)
curr_y += max_image_y_in_line

tilemap = tilemap_temp.crop((0, 0, curr_x, max_y))
tilemap = tilemap_temp.crop((0, 0, max_line_width, curr_y))
tilemap.save('../dist/assets/tileset.png', optimize=True)

with open('../tileset.hpp', 'w') as f:
Expand All @@ -49,9 +58,9 @@
f.write('const SpriteInfo %s = { %s, %s, { sf::Vector2f(%s, %s), sf::Vector2f(%s, %s), sf::Vector2f(%s, %s), sf::Vector2f(%s, %s) } };\n' % (
sprite['name'],
sprite['width'], sprite['height'],
sprite['posX'], 0,
sprite['posX'] + sprite['width'], 0,
sprite['posX'] + sprite['width'], sprite['height'],
sprite['posX'], sprite['height']
sprite['posX'], sprite['posY'],
sprite['posX'] + sprite['width'], sprite['posY'],
sprite['posX'] + sprite['width'], sprite['posY'] + sprite['height'],
sprite['posX'], sprite['posY'] + sprite['height']
))
f.write('\n}\n')

0 comments on commit e731451

Please sign in to comment.