-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage.cpp
29 lines (25 loc) · 942 Bytes
/
image.cpp
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
#include "image.h"
#include "glext.h"
namespace nes::image {
Image::Image() noexcept {
// Create a new texture.
glGenTextures(1, &texture);
// Bind that texture.
glBindTexture(GL_TEXTURE_2D, texture);
// Set some texture parameters.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
void Image::set_data(const GLuint *data, int width, int height) const noexcept {
// Bind the texture.
glBindTexture(GL_TEXTURE_2D, texture);
// Blit the image to the texture.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
GL_UNSIGNED_INT_8_8_8_8, data);
}
ImTextureID Image::imgui_image() const noexcept {
return (void *)(intptr_t)texture;
}
} // namespace nes::image