-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCubeMap.cpp
More file actions
86 lines (73 loc) · 2.36 KB
/
CubeMap.cpp
File metadata and controls
86 lines (73 loc) · 2.36 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "Application.h"
#include "CubeMap.h"
#include "Glew\include\glew.h"
#include <gl/GL.h>
#include <gl/GLU.h>
#include "ResourceFileTexture.h"
#include "TextureImporter.h"
#include "Globals.h"
#include "ModuleFileSystem.h"
#include "Devil/include/il.h"
#include "Devil/include/ilut.h"
#pragma comment ( lib, "Devil/libx86/DevIL.lib" )
#pragma comment ( lib, "Devil/libx86/ILU.lib" )
#pragma comment ( lib, "Devil/libx86/ILUT.lib" )
CubeMap::CubeMap(const string & posx_filename, const string & negx_filename, const string & posy_filename, const string & negy_filename, const string & posz_filename, const string & negz_filename)
{
textures_filenames.push_back(posx_filename);
textures_filenames.push_back(negx_filename);
textures_filenames.push_back(posy_filename);
textures_filenames.push_back(negy_filename);
textures_filenames.push_back(posz_filename);
textures_filenames.push_back(negz_filename);
}
CubeMap::~CubeMap()
{}
bool CubeMap::Load()
{
//TODO: do not hardcode this. Implement Devil's code inside the texture importer.
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
for (unsigned int i = 0; i < 6; i++)
{
char* buffer = nullptr;
unsigned int size = App->file_system->Load(textures_filenames[i].data(), &buffer);
if (size > 0)
{
ILuint il_id;
ilGenImages(1, &il_id);
ilBindImage(il_id);
if (ilLoadL(IL_DDS, (const void*)buffer, size))
{
ILinfo info;
iluGetImageInfo(&info);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, info.Width, info.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, info.Data);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
ilDeleteImages(1, &il_id);
}
}
delete[] buffer;
}
return true;
}
bool CubeMap::Unload()
{
bool ret = true;
glDeleteBuffers(1, (GLuint*)&id);
GLenum error = glGetError();
if (error != GL_NO_ERROR)
{
LOG("Error removing buffer %i : %s", id, gluErrorString(error));
ret = false;
}
return ret;
}
void CubeMap::Bind(int texture_unit)
{
glActiveTexture(texture_unit);
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
}