2 #include "rend_cubemap.h"
4 RendCubemap::RendCubemap()
8 zbuf_width = zbuf_height = 0;
10 proj_matrix.perspective(M_PI / 2.0, 1, 0.5, 10000);
13 void RendCubemap::set_position(const Vec3 &pos)
18 void RendCubemap::set_cubemap(Texture *cubemap)
20 this->cubemap = cubemap;
23 void RendCubemap::draw() const
25 static const Vec3 targ[] = {
26 Vec3{1, 0, 0}, Vec3{-1, 0, 0},
27 Vec3{0, 1, 0}, Vec3{0, -1, 0},
28 Vec3{0, 0, 1}, Vec3{0, 0, -1}
30 static const Vec3 up[] = {
31 Vec3{0, 1, 0}, Vec3{0, 1, 0},
32 Vec3{0, 0, 1}, Vec3{0, 0, -1},
33 Vec3{0, 1, 0}, Vec3{0, 1, 0}
37 glMatrixMode(GL_PROJECTION);
39 glLoadMatrixf(proj_matrix[0]);
41 for(int i=0; i<6; i++) {
43 vmat.inv_lookat(pos, targ[i], up[i]);
45 glMatrixMode(GL_MODELVIEW);
46 if(i == 0) glPushMatrix();
47 glLoadMatrixf(vmat[0]);
54 glMatrixMode(GL_PROJECTION);
56 glMatrixMode(GL_MODELVIEW);
60 void RendCubemap::draw_object(Object *obj) const
65 void RendCubemap::setup(int face_idx) const
70 glGenFramebuffers(1, &fbo);
72 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
74 glGenRenderbuffers(1, &zbuf);
75 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, zbuf);
78 if(zbuf_width != cubemap->get_width() || zbuf_height != cubemap->get_height()) {
79 zbuf_width = cubemap->get_width();
80 zbuf_height = cubemap->get_height();
81 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, zbuf_width, zbuf_height);
84 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
85 GL_TEXTURE_CUBE_MAP_POSITIVE_X + face_idx, cubemap->get_id(), 0);