-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHDR.cpp
More file actions
63 lines (51 loc) · 1.77 KB
/
HDR.cpp
File metadata and controls
63 lines (51 loc) · 1.77 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
#include "HDR.h"
#include "math.h"
#include <fstream>
#include <stdlib.h>
#include <glbinding/gl/gl.h>
#include <glbinding/Binding.h>
using namespace gl;
#define GLM_FORCE_CTOR_INIT
#define GLM_FORCE_RADIANS
#define GLM_SWIZZLE
#include <glm/glm.hpp>
#include "texture.h"
//#define STB_IMAGE_IMPLEMENTATION
#define STBI_FAILURE_USERMSG
#include "stb_image.h"
#include <glu.h>
HDR::HDR()
{
}
HDR::HDR(const std::string& filePath)
{
stbi_set_flip_vertically_on_load(true);
image = stbi_loadf(filePath.c_str(), &width, &height, &depth, 4);
printf("%d %d %d %s\n", depth, width, height, filePath.c_str());
if (!image) {
printf("\nRead error on file %s:\n %s\n\n", filePath.c_str(), stbi_failure_reason());
exit(-1);
}
glGenTextures(1, &textureId); // Get an integer id for this texture from OpenGL
glBindTexture(GL_TEXTURE_2D, textureId);
glTexImage2D(GL_TEXTURE_2D, 0, (GLint)GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (int)GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (int)GL_LINEAR_MIPMAP_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
stbi_image_free(image);
}
void HDR::BindTexture(const int unit, const int programId, const std::string& name)
{
glActiveTexture((gl::GLenum)((int)GL_TEXTURE0 + unit));
glBindTexture(GL_TEXTURE_2D, textureId);
int loc = glGetUniformLocation(programId, name.c_str());
glUniform1i(loc, unit);
}
// Unbind a texture from a texture unit whne no longer needed.
void HDR::UnbindTexture(const int unit)
{
glActiveTexture((gl::GLenum)((int)GL_TEXTURE0 + unit));
glBindTexture(GL_TEXTURE_2D, 0);
}