-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextureLoader.cpp
More file actions
44 lines (29 loc) · 1.19 KB
/
Copy pathTextureLoader.cpp
File metadata and controls
44 lines (29 loc) · 1.19 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
//
// Created by roudn on 18/06/2022.
//
#include "TextureLoader.hpp"
#define STB_IMAGE_IMPLEMENTATION
#include "lib/stb-master/stb_image.h"
TextureLoader::TextureLoader() {}
TextureLoader::~TextureLoader() {}
GLuint TextureLoader::getTextureID(std::string texFileName) {
int width;
int height;
int channels;
stbi_uc* image = stbi_load(texFileName.c_str(), &width, &height, &channels, STBI_rgb);
GLuint mtexture;
glGenTextures(1,&mtexture);
glBindTexture(GL_TEXTURE_2D, mtexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// Set texture filtering parameters
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
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, GL_RGB, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
stbi_image_free(image);
return mtexture;
}