-
Notifications
You must be signed in to change notification settings - Fork 0
/
Texture.hpp
36 lines (29 loc) · 911 Bytes
/
Texture.hpp
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
#pragma once
#include <string>
#include <cstddef>
#include <GL/gl.h>
struct Texture
{
size_t width;
size_t height;
GLuint id;
Texture(size_t width, size_t height) : width(width), height(height), id(0xFFFFFFFF)
{ createEmptyTexture(); }
~Texture()
{ glDeleteTextures(1, &id); }
// TODO
Texture(size_t width, size_t height, std::string filename) : width(width), height(height)
{ }
void createEmptyTexture()
{
glDeleteTextures(1, &id);
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
glBindTexture(GL_TEXTURE_2D, id);
}
};