Zen 0.3.0
Loading...
Searching...
No Matches
ZEN_Texture.h
1#pragma once
2
3#include <zen/textures/ZEN_Image.h>
4#include <zen/zen_pch.h>
5
6namespace Zen {
7 typedef struct Texture {
8 uint32_t id;
9 uint32_t width{0};
10 uint32_t height{0};
11 const char *textureName;
12
13 std::weak_ptr<Zen::Image> image;
14
15 Texture(const char *textureName, std::weak_ptr<Zen::Image> image) {
16 this->textureName = textureName;
17 this->image = image;
18 this->width = image.lock()->width;
19 this->height = image.lock()->height;
20
21 glGenTextures(1, &this->id);
22 glBindTexture(GL_TEXTURE_2D, this->id);
23 glTexImage2D(GL_TEXTURE_2D,
24 0,
25 GL_RGBA,
26 this->width,
27 this->height,
28 0,
29 GL_RGBA,
30 GL_UNSIGNED_BYTE,
31 image.lock()->data);
32
33 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
34 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
35 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, 1.0f);
36
37 glBindTexture(GL_TEXTURE_2D, 0);
38 };
39
40 } Texture;
41
42 using TexturePtr = std::shared_ptr<Zen::Texture>;
43}; // namespace Zen