complex entities are made up of part which have their own local
transform that can be animated (like e.g. an arm or head)
-textures
-
- okay, now I need a better solution for the crosshair ^^
-
font rendering
with background now being a thing, a padding might be nice
--- /dev/null
+#ifndef BLANK_GRAPHICS_PLAINCOLOR_HPP_
+#define BLANK_GRAPHICS_PLAINCOLOR_HPP_
+
+#include "Program.hpp"
+
+#include <GL/glew.h>
+#include <glm/glm.hpp>
+
+
+namespace blank {
+
+class PlainColor {
+
+public:
+ PlainColor();
+
+ void Activate() noexcept;
+
+ void SetM(const glm::mat4 &m) noexcept;
+ void SetProjection(const glm::mat4 &p) noexcept;
+ void SetView(const glm::mat4 &v) noexcept;
+ void SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept;
+ void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept;
+
+ const glm::mat4 &Projection() const noexcept { return projection; }
+ const glm::mat4 &View() const noexcept { return view; }
+ const glm::mat4 &GetVP() const noexcept { return vp; }
+
+private:
+ Program program;
+
+ glm::mat4 projection;
+ glm::mat4 view;
+ glm::mat4 vp;
+
+ GLuint mvp_handle;
+
+};
+
+}
+
+#endif
#include "Camera.hpp"
#include "Canvas.hpp"
#include "DirectionalLighting.hpp"
+#include "PlainColor.hpp"
#include <glm/glm.hpp>
BlockLighting &ChunkProgram() noexcept;
DirectionalLighting &EntityProgram() noexcept;
DirectionalLighting &HUDProgram() noexcept;
+ PlainColor &WorldOutlineProgram() noexcept;
+ PlainColor &HUDOutlineProgram() noexcept;
BlendedSprite &SpriteProgram() noexcept;
void WorldPosition(const glm::mat4 &) noexcept;
BlockLighting chunk_prog;
DirectionalLighting entity_prog;
+ PlainColor outline_prog;
BlendedSprite sprite_prog;
enum {
CHUNK,
ENTITY,
HUD,
+ OUTLINE_WORLD,
+ OUTLINE_HUD,
SPRITE,
} active_prog;
#include "BlendedSprite.hpp"
#include "BlockLighting.hpp"
#include "DirectionalLighting.hpp"
+#include "PlainColor.hpp"
#include "Program.hpp"
#include "Shader.hpp"
program.Uniform(bg_handle, v);
}
+
+PlainColor::PlainColor()
+: program()
+, vp(1.0f)
+, mvp_handle(0) {
+ program.LoadShader(
+ GL_VERTEX_SHADER,
+ "#version 330 core\n"
+ "layout(location = 0) in vec3 vtx_position;\n"
+ "layout(location = 1) in vec3 vtx_color;\n"
+ "uniform mat4 MVP;\n"
+ "out vec3 frag_color;\n"
+ "void main() {\n"
+ "gl_Position = MVP * vec4(vtx_position, 1);\n"
+ "frag_color = vtx_color;\n"
+ "}\n"
+ );
+ program.LoadShader(
+ GL_FRAGMENT_SHADER,
+ "#version 330 core\n"
+ "in vec3 frag_color;\n"
+ "out vec3 color;\n"
+ "void main() {\n"
+ "color = frag_color;\n"
+ "}\n"
+ );
+ program.Link();
+ if (!program.Linked()) {
+ program.Log(std::cerr);
+ throw std::runtime_error("link program");
+ }
+
+ mvp_handle = program.UniformLocation("MVP");
+}
+
+
+void PlainColor::Activate() noexcept {
+ program.Use();
+}
+
+void PlainColor::SetM(const glm::mat4 &m) noexcept {
+ program.Uniform(mvp_handle, vp * m);
+}
+
+void PlainColor::SetProjection(const glm::mat4 &p) noexcept {
+ projection = p;
+ vp = p * view;
+}
+
+void PlainColor::SetView(const glm::mat4 &v) noexcept {
+ view = v;
+ vp = projection * v;
+}
+
+void PlainColor::SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept {
+ projection = p;
+ view = v;
+ vp = p * v;
+}
+
+void PlainColor::SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept {
+ SetVP(v, p);
+ SetM(m);
+}
+
}
return entity_prog;
}
+PlainColor &Viewport::WorldOutlineProgram() noexcept {
+ if (active_prog != OUTLINE_WORLD) {
+ outline_prog.Activate();
+ outline_prog.SetVP(cam.View(), cam.Projection());
+ active_prog = OUTLINE_WORLD;
+ }
+ return outline_prog;
+}
+
+PlainColor &Viewport::HUDOutlineProgram() noexcept {
+ if (active_prog != OUTLINE_HUD) {
+ outline_prog.Activate();
+ outline_prog.SetVP(canv.View(), canv.Projection());
+ active_prog = OUTLINE_HUD;
+ }
+ return outline_prog;
+}
+
BlendedSprite &Viewport::SpriteProgram() noexcept {
if (active_prog != SPRITE) {
sprite_prog.Activate();
void HUD::Render(Viewport &viewport) noexcept {
viewport.ClearDepth();
- DirectionalLighting &world_prog = viewport.HUDProgram();
- world_prog.SetLightDirection({ 1.0f, 3.0f, 5.0f });
- // disable distance fog
- world_prog.SetFogDensity(0.0f);
-
+ PlainColor &outline_prog = viewport.HUDOutlineProgram();
viewport.EnableInvertBlending();
viewport.SetCursor(glm::vec3(0.0f), Gravity::CENTER);
- world_prog.SetM(viewport.Cursor());
+ outline_prog.SetM(viewport.Cursor());
crosshair.Draw();
if (block_visible) {
+ DirectionalLighting &world_prog = viewport.HUDProgram();
+ world_prog.SetLightDirection({ 1.0f, 3.0f, 5.0f });
+ // disable distance fog
+ world_prog.SetFogDensity(0.0f);
+
viewport.DisableBlending();
world_prog.SetM(block_transform);
block.Draw();
outl_buf.Clear();
aim_chunk->Type(aim_chunk->BlockAt(aim_block)).FillOutlineModel(outl_buf);
outline.Update(outl_buf);
- outline_transform = glm::scale(glm::vec3(1.0002f));
- outline_transform *= aim_chunk->Transform(world.Player().ChunkCoords());
+ outline_transform = aim_chunk->Transform(world.Player().ChunkCoords());
outline_transform *= aim_chunk->ToTransform(Chunk::ToPos(aim_block), aim_block);
+ outline_transform *= glm::scale(glm::vec3(1.005f));
} else {
aim_chunk = nullptr;
}
if (config.visual_disabled) return;
if (aim_chunk) {
- DirectionalLighting &world_prog = viewport.EntityProgram();
- world_prog.SetM(outline_transform);
+ PlainColor &outline_prog = viewport.WorldOutlineProgram();
+ outline_prog.SetM(outline_transform);
outline.Draw();
}