-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexturepacker.h
More file actions
61 lines (55 loc) · 2.44 KB
/
Copy pathtexturepacker.h
File metadata and controls
61 lines (55 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef TEXTUREPACKER_H
#define TEXTUREPACKER_H
//NOTE 5.08.16
// найденный TexturePacker здесь https://github.com/bivory/texture-atlas/tree/master/texturepacker
// выдал мне ошибку при запаковки 200-т мелких текстур
// QGM: ../editor/texturepacker/TexturePacker.cpp:417: virtual int TEXTURE_PACKER::MyTexturePacker::packTextures(int&, int&, bool, bool):
// пришлось переписать TexturePaker на свой,на что ушло немало времени ._.
// текстуры пакует без проблем
// но не реализовал поворот текстуры на 90
/* как использовать
//Создадим обьект пакера
TexturePacker *tp = new TexturePacker;
//Установим сколько нам нужно текстур
tp->setTextureCount(images_count);
// добавляем размер текстуры в пакер
tp->addTexture(img_width,img_height);
//Напишем переменные в которые сохранится размер текстурного атласа
int atlasWidth,atlasHeight;
bool forcePowerOfTwo = true; // если нужен атлас кратным двум
bool witchBorder = true; // если нужен пустой бордюр в один пиксель
//далее можно вызвать упаковку
tp->packTextures(atlasWidth,atlasHeight,forcePowerOfTwo,witchBorder);
// и получаем положения наших текстур
int x,y,width,height;
tp->getTextureLocation(index,x,y,width,height);
...
delete tp;
*/
class TexturePacker
{
public:
TexturePacker();
~TexturePacker();
void setTextureCount(int count);//
void addTexture(int width,int height); // add textures 0 - n
void packTextures(int &width,int &height,bool forcePowerOfTwo,bool onePixelBorder); // pack the textures
void getTextureLocation(int index,int &x,int &y,int &width,int &height);
private:
// структура для хранения областей на атласе
//или любых других объектов у которых есть размер
struct Image
{
int id;
int x;
int y;
int width;
int height;
};
Image *imgArr;// массив
int size = 0;
int id = 0;
int nextPow2(int newSize) const;
void BubbleSort(Image *&img, bool sortID);
};
#endif // TEXTUREPACKER_H