9Texture_2d::Texture_2d(
unsigned int res_x,
unsigned int res_y, GLenum internal_format, GLenum type, GLenum format) : Texture() {
11 create_empty(res_x, res_y, internal_format, type, format);
32 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, res_x, res_y, 0,
33 format, type,
nullptr);
34 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
35 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
36 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
37 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
55 SDL_Surface *tmp = SDL_ConvertSurfaceFormat(image.
image,
56 SDL_PIXELFORMAT_RGBA8888, 0);
62 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
63 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
64 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
65 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
66 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.
width, image.
height, 0,
67 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, tmp->pixels);
68 glGenerateMipmap(GL_TEXTURE_2D);
void unbind(unsigned int texture_unit=0)
Unbind the texture.
void create_empty(unsigned int res_x, unsigned int res_y, GLenum internal_format, GLenum type, GLenum format)
Creates an empty texture.
bool load(const sgltk::Image &image)
Load a new image as texture.
void bind(unsigned int texture_unit=0)
Bind the texture to be used by the shader.
unsigned int width
The width of the texture.
unsigned int height
The height of the texture.