-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTexture.cpp
31 lines (29 loc) · 1.06 KB
/
Texture.cpp
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
#include "Texture.h"
#include "Image.h"
#include "GLIncludes.h"
Texture &Texture::operator=(const Texture &tex)
{
if (isHandle)
textureManager.release(name);
id = tex.id;
name = tex.name;
isHandle = true;
textureManager.addRef(name);
return *this;
}
Texture TextureManager::load(const Image &img, bool repeat)
{
Texture tex;
tex.name = img.getName();
glGenTextures(1, &tex.id);
glBindTexture(GL_TEXTURE_2D, tex.id);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE);
gluBuild2DMipmaps(GL_TEXTURE_2D, img.bpp, img.width, img.height,
img.bpp == 4 ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, img.pixels);
textures[tex.name].set(tex, 0);
return tex;
}