4a95407d0e
- cpp/functions/gfx/gl_loader.{h,cpp,md}: mini loader para OpenGL 2.0+
(Linux no-op via GL_GLEXT_PROTOTYPES, Windows wglGetProcAddress)
- Portar gl_shader/gl_framebuffer/fullscreen_quad/shader_canvas al loader
- CMakeLists: WIN32_EXECUTABLE para lanzar sin consola en Windows
- apps/shaders_lab/shaders_lab.exe: binario PE32+ precompilado
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
47 lines
1.5 KiB
C++
47 lines
1.5 KiB
C++
#include "gfx/gl_loader.h"
|
|
#include "gfx/gl_framebuffer.h"
|
|
|
|
namespace fn::gfx {
|
|
|
|
static void create_tex(Framebuffer& f) {
|
|
glGenTextures(1, &f.tex);
|
|
glBindTexture(GL_TEXTURE_2D, f.tex);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, f.width, f.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
}
|
|
|
|
void fb_init(Framebuffer& f) {
|
|
f.width = 1;
|
|
f.height = 1;
|
|
create_tex(f);
|
|
glGenFramebuffers(1, &f.fbo);
|
|
glBindFramebuffer(GL_FRAMEBUFFER, f.fbo);
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, f.tex, 0);
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
}
|
|
|
|
void fb_resize(Framebuffer& f, int w, int h) {
|
|
if (w == f.width && h == f.height) return;
|
|
f.width = w;
|
|
f.height = h;
|
|
if (f.tex) glDeleteTextures(1, &f.tex);
|
|
f.tex = 0;
|
|
create_tex(f);
|
|
glBindFramebuffer(GL_FRAMEBUFFER, f.fbo);
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, f.tex, 0);
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
}
|
|
|
|
void fb_destroy(Framebuffer& f) {
|
|
if (f.fbo) { glDeleteFramebuffers(1, &f.fbo); f.fbo = 0; }
|
|
if (f.tex) { glDeleteTextures(1, &f.tex); f.tex = 0; }
|
|
f.width = 0;
|
|
f.height = 0;
|
|
}
|
|
|
|
} // namespace fn::gfx
|