Untitled Game engine no.5  1.0
TextureSheet.hpp
1 #ifndef TILEMAP_H
2 #define TILEMAP_H
3 
4 #include "pch.hpp"
5 #include <Texture.hpp>
6 #include <GLTexture.hpp>
7 
8 
9 namespace Engine {
13  struct TextureSheet {
14 
15 
16 
24  static std::vector<Ref<TextureLookup>> loadSheet(const std::string& path, int inputWidth, int inputHeight) {
25  auto mainTex = Texture2D::Create(path);
26  std::vector<Ref<TextureLookup>> lookup = std::vector<Ref<TextureLookup>>();
27 
28  int boardWidth = (int) mainTex->getWidth();
29  int boardHeight = (int) mainTex->getHeight();
30 
31  int wLen = boardWidth / inputWidth;
32  int hLen = boardHeight / inputHeight;
33 
34  float glWidth = ((float) inputWidth) / ((float) boardWidth);
35  float glHeight = ((float) inputHeight) / ((float) boardHeight);
36 
37  for (int y = 0; y < hLen; ++y) {
38  for (int x = 0; x < wLen; ++x) {
39  auto map = TextureMap::Map2D(glWidth, glHeight, glWidth * (float) x, glHeight * (float) (hLen - y - 1));
40  auto sub = CreateRef<TextureLookup>(mainTex, map, (float) inputWidth, (float) inputHeight);
41  lookup.emplace_back(sub);
42  }
43  }
44 
45  return lookup;
46  };
47 
48  };
49 }
50 
51 #endif
52 
Engine::TextureSheet
Definition: TextureSheet.hpp:13
Engine::TextureSheet::loadSheet
static std::vector< Ref< TextureLookup > > loadSheet(const std::string &path, int inputWidth, int inputHeight)
Definition: TextureSheet.hpp:24
Engine
Definition: Animation.hpp:14