Flipped UI, minor changes

Flipped UI, removed extra Batch2D, added comments and minor changes
This commit is contained in:
MihailRis
2022-06-29 14:03:36 +03:00
committed by GitHub
parent c3b4357852
commit 88c1695903
7 changed files with 67 additions and 66 deletions
+33 -37
View File
@@ -45,7 +45,6 @@ int uiscale = 2;
LineBatch *lineBatch;
Batch2D *batch;
Batch2D *activeBlockBatch;
Camera *uicamera;
void init_renderer(){
@@ -53,9 +52,9 @@ void init_renderer(){
lineBatch = new LineBatch(4096);
batch = new Batch2D(1024);
activeBlockBatch = new Batch2D(1024);
uicamera = new Camera(glm::vec3(), Window::height / uiscale);
uicamera->perspective = false;
uicamera->flipped = true;
}
@@ -63,7 +62,6 @@ void finalize_renderer(){
delete crosshair;
delete lineBatch;
delete batch;
delete activeBlockBatch;
}
void draw_chunk(size_t index, Camera* camera, Shader* shader, bool occlusion){
@@ -112,17 +110,45 @@ bool chunks_comparator(size_t i, size_t j) {
}
void draw_world(Player* player, Camera* camera, Assets* assets, Chunks* chunks,
bool occlusion, bool devdata, int fps){
void draw_hud(Player* player, Assets* assets, bool devdata, int fps){
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
Shader* uishader = assets->getShader("ui");
uishader->use();
uishader->uniformMatrix("u_projview", uicamera->getProjection()*uicamera->getView());
// draw debug info
Font* font = assets->getFont("normal");
batch->begin();
batch->texture(font->texture);
if (devdata){
font->draw(batch, "devdata does not exist", 16, 16);
font->draw(batch, std::to_string((int)player->camera->position.x), 10, 30);
font->draw(batch, std::to_string((int)player->camera->position.y), 50, 30);
font->draw(batch, std::to_string((int)player->camera->position.z), 90, 30);
font->draw(batch, "fps:", 16, 42);
font->draw(batch, std::to_string(fps), 40, 42);
}
batch->render();
// choosen block preview
Texture* blocks = assets->getTexture("block_select");
batch->texture(blocks);
float u = (player->choosenBlock % 16) / 16.0f;
float v = 1.0f - ((player->choosenBlock / 16) / 16.0f) - 1.0f/16.0f;
batch->rect(16, 280, 64, 64, u, v, 1.0f/16.0f, 1.0f/16.0f, 1,1,1,1);
batch->render();
}
void draw_world(Player* player, Camera* camera, Assets* assets, Chunks* chunks, bool occlusion){
glClearColor(0.7f,0.81f,1.0f,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
_chunks = chunks;
// Draw VAO
Texture* texture = assets->getTexture("block");
Texture* blocks = assets->getTexture("block_select");
Shader* shader = assets->getShader("main");
Shader* crosshairShader = assets->getShader("crosshair");
Shader* linesShader = assets->getShader("lines");
@@ -134,7 +160,6 @@ void draw_world(Player* player, Camera* camera, Assets* assets, Chunks* chunks,
shader->uniform3f("u_fogColor", 0.7f,0.71f,0.73f);
shader->uniform3f("u_cameraPos", camera->position.x,camera->position.y,camera->position.z);
texture->bind();
// blocks->bind();
std::vector<size_t> indices;
@@ -171,35 +196,6 @@ void draw_world(Player* player, Camera* camera, Assets* assets, Chunks* chunks,
lineBatch->line(camera->position.x, camera->position.y-0.1f, camera->position.z, camera->position.x, camera->position.y-0.1f, camera->position.z+0.01f, 0, 0, 1, 1);
lineBatch->line(camera->position.x, camera->position.y-0.1f, camera->position.z, camera->position.x, camera->position.y-0.1f+0.01f, camera->position.z, 0, 1, 0, 1);
lineBatch->render();
glDisable(GL_DEPTH_TEST);
Shader* uishader = assets->getShader("ui");
uishader->use();
uishader->uniformMatrix("u_projview", uicamera->getProjection());
Font* font = assets->getFont("normal");
// Texture* blocks = assets->getTexture("blocks")
batch->begin();
batch->texture(font->texture);
// font->draw(batch, "void Font::draw(Batch2D* batch, std::string text, int x, int y) {", 10, 10);
if (devdata){
font->draw(batch, "devdata does not exist", 16, 16);
font->draw(batch, std::to_string((int)player->camera->position.x), 10, 30);
font->draw(batch, std::to_string((int)player->camera->position.y), 50, 30);
font->draw(batch, std::to_string((int)player->camera->position.z), 90, 30);
font->draw(batch, "fps:", 16, 42);
font->draw(batch, std::to_string(fps), 40, 42);
}
//batch->rect(0, 0, 256, 256);
batch->render();
activeBlockBatch->begin();
activeBlockBatch->texture(blocks);
float u = (player->choosenBlock % 16) / 16.0f;
float v = 1.0f - ((player->choosenBlock / 16) / 16.0f) - 1.0f/16.0f;
activeBlockBatch->rect(16, 280, 64, 64, u, v, 1.0f/16.0f, 1.0f/16.0f, 1,1,1,1);
activeBlockBatch->render();
}
#endif // WORLD_RENDERER_CPP