Added gui_util
This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
#include "../graphics/Viewport.h"
|
||||
#include "../graphics/Shader.h"
|
||||
#include "../graphics/Texture.h"
|
||||
#include "../graphics/Atlas.h"
|
||||
#include "../graphics/Batch3D.h"
|
||||
#include "../window/Camera.h"
|
||||
#include "../voxels/Block.h"
|
||||
#include "../window/Window.h"
|
||||
#include "ContentGfxCache.h"
|
||||
|
||||
using glm::vec4;
|
||||
@@ -25,13 +25,12 @@ BlocksPreview::~BlocksPreview() {
|
||||
delete batch;
|
||||
}
|
||||
|
||||
void BlocksPreview::begin() {
|
||||
void BlocksPreview::begin(const Viewport* viewport) {
|
||||
this->viewport = viewport;
|
||||
shader->use();
|
||||
shader->uniformMatrix("u_projview",
|
||||
glm::ortho(0.0f,
|
||||
float(Window::width),
|
||||
0.0f,
|
||||
float(Window::height),
|
||||
glm::ortho(0.0f, float(viewport->getWidth()),
|
||||
0.0f, float(viewport->getHeight()),
|
||||
-1000.0f, 1000.0f) *
|
||||
glm::lookAt(vec3(2, 2, 2), vec3(0.0f), vec3(0, 1, 0)));
|
||||
atlas->getTexture()->bind();
|
||||
@@ -39,10 +38,13 @@ void BlocksPreview::begin() {
|
||||
|
||||
/* Draw one block preview at given screen position */
|
||||
void BlocksPreview::draw(const Block* def, int x, int y, int size, vec4 tint) {
|
||||
y = Window::height - y - 1;
|
||||
uint width = viewport->getWidth();
|
||||
uint height = viewport->getHeight();
|
||||
|
||||
y = height - y - 1;
|
||||
x += 2;
|
||||
y -= 35;
|
||||
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), vec3(x/float(Window::width) * 2, y/float(Window::height) * 2, 0.0f)));
|
||||
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), vec3(x/float(width) * 2, y/float(height) * 2, 0.0f)));
|
||||
blockid_t id = def->rt.id;
|
||||
const UVRegion texfaces[6]{ cache->getRegion(id, 0), cache->getRegion(id, 1),
|
||||
cache->getRegion(id, 2), cache->getRegion(id, 3),
|
||||
|
||||
Reference in New Issue
Block a user