-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.cpp
More file actions
37 lines (26 loc) · 918 Bytes
/
texture.cpp
File metadata and controls
37 lines (26 loc) · 918 Bytes
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 "texture.h"
#include <SDL2/SDL_image.h>
Texture::Texture(GLenum textureTarget):
textureTarget(textureTarget) {
}
Texture::~Texture() {
SDL_FreeSurface(image);
//if(image)delete image;
}
#include <iostream>
void Texture::load(const std::string& fileName) {
image = IMG_Load(fileName.c_str());
//image = SDL_ConvertSurfaceFormat(image, SDL_PIXELFORMAT_RGB444, 0);
glGenTextures(1, &textureObject);
glBindTexture(textureTarget, textureObject);
glTexImage2D(textureTarget, 0, GL_RGB,
image->w, image->h,
0, GL_RGB, GL_UNSIGNED_BYTE,
image->pixels);
glTexParameterf(textureTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(textureTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
void Texture::bind(GLenum textureUnit) {
glActiveTexture(textureUnit);
glBindTexture(textureTarget, textureObject);
}