string front = full + "-front.png";
CubeMap cm;
+ cm.Bind();
SDL_Surface *srf;
if (!(srf = IMG_Load(right.c_str()))) throw SDLError("IMG_Load");
- cm.Data(CubeMap::RIGHT, *srf);
+ try {
+ cm.Data(CubeMap::RIGHT, *srf);
+ } catch (...) {
+ SDL_FreeSurface(srf);
+ throw;
+ }
SDL_FreeSurface(srf);
if (!(srf = IMG_Load(left.c_str()))) throw SDLError("IMG_Load");
- cm.Data(CubeMap::LEFT, *srf);
+ try {
+ cm.Data(CubeMap::LEFT, *srf);
+ } catch (...) {
+ SDL_FreeSurface(srf);
+ throw;
+ }
SDL_FreeSurface(srf);
if (!(srf = IMG_Load(top.c_str()))) throw SDLError("IMG_Load");
- cm.Data(CubeMap::TOP, *srf);
+ try {
+ cm.Data(CubeMap::TOP, *srf);
+ } catch (...) {
+ SDL_FreeSurface(srf);
+ throw;
+ }
SDL_FreeSurface(srf);
if (!(srf = IMG_Load(bottom.c_str()))) throw SDLError("IMG_Load");
- cm.Data(CubeMap::BOTTOM, *srf);
+ try {
+ cm.Data(CubeMap::BOTTOM, *srf);
+ } catch (...) {
+ SDL_FreeSurface(srf);
+ throw;
+ }
SDL_FreeSurface(srf);
if (!(srf = IMG_Load(back.c_str()))) throw SDLError("IMG_Load");
- cm.Data(CubeMap::BACK, *srf);
+ try {
+ cm.Data(CubeMap::BACK, *srf);
+ } catch (...) {
+ SDL_FreeSurface(srf);
+ throw;
+ }
SDL_FreeSurface(srf);
if (!(srf = IMG_Load(front.c_str()))) throw SDLError("IMG_Load");
- cm.Data(CubeMap::FRONT, *srf);
+ try {
+ cm.Data(CubeMap::FRONT, *srf);
+ } catch (...) {
+ SDL_FreeSurface(srf);
+ throw;
+ }
SDL_FreeSurface(srf);
+ cm.FilterNearest();
+ cm.WrapEdge();
+
return cm;
}
#include "ChunkRequester.hpp"
#include "../app/IntervalTimer.hpp"
#include "../app/State.hpp"
+#include "../graphics/SkyBox.hpp"
#include "../io/WorldSave.hpp"
#include "../model/Skeletons.hpp"
#include "../ui/Interface.hpp"
Skeletons skeletons;
IntervalTimer loop_timer;
+ SkyBox sky;
+
struct PlayerHistory {
EntityState state;
int delta_t;
, chunk_renderer(*interface.GetPlayer().chunks)
, skeletons()
, loop_timer(16)
+, sky(master.GetEnv().loader.LoadCubeMap("skybox"))
, player_hist() {
if (!save.Exists()) {
save.Write(master.GetWorldConf());
viewport.WorldPosition(player.Transform(player.ChunkCoords()));
chunk_renderer.Render(viewport);
world.Render(viewport);
+ sky.Render(viewport);
interface.Render(viewport);
}
CubeMap &operator =(const CubeMap &) = delete;
public:
- void Data(Face, const SDL_Surface &) noexcept;
+ void Data(Face, const SDL_Surface &);
void Data(Face, GLsizei w, GLsizei h, const Format &, GLvoid *data) noexcept;
};
}
-void CubeMap::Data(Face f, const SDL_Surface &srf) noexcept {
- Data(f, srf.w, srf.h, Format(*srf.format), srf.pixels);
+void CubeMap::Data(Face f, const SDL_Surface &srf) {
+ Format format;
+ Format fmt(*srf.format);
+ if (format.Compatible(fmt)) {
+ Data(f, srf.w, srf.h, fmt, srf.pixels);
+ } else {
+ SDL_Surface *converted = SDL_ConvertSurface(
+ const_cast<SDL_Surface *>(&srf),
+ &format.sdl_format,
+ 0
+ );
+ if (!converted) {
+ throw SDLError("SDL_ConvertSurface");
+ }
+ Format new_fmt(*converted->format);
+ if (!format.Compatible(new_fmt)) {
+ SDL_FreeSurface(converted);
+ throw std::runtime_error("unable to convert texture input");
+ }
+ Data(f, converted->w, converted->h, new_fmt, converted->pixels);
+ SDL_FreeSurface(converted);
+ }
}
void CubeMap::Data(Face face, GLsizei w, GLsizei h, const Format &f, GLvoid *data) noexcept {
"out vec3 color;\n"
"void main() {\n"
"color = texture(tex_sampler, vtx_viewspace).rgb;\n"
+ //"color = vec3(1,0,0);\n"
"}\n"
);
program.Link();
view[1].w = 0.0f;
view[2].w = 0.0f;
view[3] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
- vp = projection * v;
+ vp = projection * view;
program.Uniform(vp_handle, vp);
}
cam.Aspect(fw, fh);
canv.Resize(fw, fh);
- chunk_prog.SetProjection(Perspective());
- if (active_prog == HUD) {
- entity_prog.SetProjection(Ortho());
- } else {
- entity_prog.SetProjection(Perspective());
- }
- sky_prog.SetProjection(Perspective());
- sprite_prog.SetProjection(Ortho());
+ ChunkProgram().SetProjection(Perspective());
+ SkyBoxProgram().SetProjection(Perspective());
+ SpriteProgram().SetProjection(Ortho());
}
void Viewport::Clear() noexcept {
void Viewport::WorldPosition(const glm::mat4 &t) noexcept {
cam.View(glm::inverse(t));
- chunk_prog.SetView(cam.View());
- sky_prog.SetView(cam.View());
+ ChunkProgram().SetView(cam.View());
+ sky_prog.Activate();
+ SkyBoxProgram().SetView(cam.View());
}
}