-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.cpp
37 lines (27 loc) · 986 Bytes
/
helpers.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
32
33
34
35
36
37
#include "helpers.h"
#include "stb/stb_image.h"
int loadTexture(GLuint tex, GLint repeat, const char* file)
{
int res = -1;
int width, height, nrChannels;
unsigned char* data;
data = stbi_load(file, &width, &height, &nrChannels, 0);
if (data)
{
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, (nrChannels == 4 ? GL_RGBA : GL_RGB), GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
if (repeat == GL_CLAMP_TO_BORDER)
{
float borderColor[] = { 1.0f, 1.0f, 0.0f, 1.0f };
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); //use this for GL_CLAMP_TO_BORDER
}
stbi_image_free(data);
res = 0;
}
return res;
}