-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtexturebaker.cpp
More file actions
35 lines (24 loc) · 782 Bytes
/
texturebaker.cpp
File metadata and controls
35 lines (24 loc) · 782 Bytes
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
#include "texturebaker.h"
#include "glcache.h"
TextureBaker::TextureBaker(QWidget *parent) : QOpenGLWidget(parent)
{
}
// returns true on successful save
bool TextureBaker::writeTextureToFile(Mesh *mesh)
{
makeCurrent();
if (!GLCache::hasMeshTexture(mesh)) {
return false;
}
GLuint textureId = GLCache::meshTextureId(mesh);
QString path = mesh->texturePath();
const int size = mesh->textureSize();
const int NUM_COLOR_CHANNELS = 3;
GLubyte data[size*size*NUM_COLOR_CHANNELS];
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureId);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
QImage out(data, size, size, QImage::Format_RGB888);
out.mirrored().save(path);
return true;
}