update
This commit is contained in:
parent
4e5869882e
commit
c3b4357852
BIN
res/block_select.png
Normal file
BIN
res/block_select.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 258 KiB |
@ -61,7 +61,7 @@ int initialize_assets(Assets* assets) {
|
|||||||
LOAD_SHADER("res/ui.glslv", "res/ui.glslf", "ui");
|
LOAD_SHADER("res/ui.glslv", "res/ui.glslf", "ui");
|
||||||
|
|
||||||
LOAD_TEXTURE("res/block.png", "block");
|
LOAD_TEXTURE("res/block.png", "block");
|
||||||
//LOAD_TEXTURE("res/font.png", "font");
|
LOAD_TEXTURE("res/block_select.png", "block_select");
|
||||||
|
|
||||||
LOAD_FONT("res/font.png", "normal");
|
LOAD_FONT("res/font.png", "normal");
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -304,7 +304,7 @@ int main() {
|
|||||||
bool occlusion = false;
|
bool occlusion = false;
|
||||||
bool devdata = false;
|
bool devdata = false;
|
||||||
|
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(0);
|
||||||
|
|
||||||
std::cout << "-- initializing finished" << std::endl;
|
std::cout << "-- initializing finished" << std::endl;
|
||||||
|
|
||||||
@ -314,6 +314,7 @@ int main() {
|
|||||||
float currentTime = glfwGetTime();
|
float currentTime = glfwGetTime();
|
||||||
delta = currentTime - lastTime;
|
delta = currentTime - lastTime;
|
||||||
lastTime = currentTime;
|
lastTime = currentTime;
|
||||||
|
int fps = 1 / delta;
|
||||||
|
|
||||||
if (Events::jpressed(GLFW_KEY_O)){
|
if (Events::jpressed(GLFW_KEY_O)){
|
||||||
occlusion = !occlusion;
|
occlusion = !occlusion;
|
||||||
@ -332,7 +333,7 @@ int main() {
|
|||||||
for (int i = 0; i < freeLoaders; i++)
|
for (int i = 0; i < freeLoaders; i++)
|
||||||
chunksController.loadVisible(wfile);
|
chunksController.loadVisible(wfile);
|
||||||
|
|
||||||
draw_world(camera, assets, chunks, occlusion, devdata);
|
draw_world(player, camera, assets, chunks, occlusion, devdata, fps);
|
||||||
|
|
||||||
Window::swapBuffers();
|
Window::swapBuffers();
|
||||||
Events::pullEvents();
|
Events::pullEvents();
|
||||||
|
|||||||
@ -5,6 +5,10 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
#ifndef std::string
|
||||||
|
#include <string>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/ext.hpp>
|
#include <glm/ext.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
@ -41,6 +45,7 @@ int uiscale = 2;
|
|||||||
|
|
||||||
LineBatch *lineBatch;
|
LineBatch *lineBatch;
|
||||||
Batch2D *batch;
|
Batch2D *batch;
|
||||||
|
Batch2D *activeBlockBatch;
|
||||||
Camera *uicamera;
|
Camera *uicamera;
|
||||||
|
|
||||||
void init_renderer(){
|
void init_renderer(){
|
||||||
@ -48,6 +53,7 @@ void init_renderer(){
|
|||||||
lineBatch = new LineBatch(4096);
|
lineBatch = new LineBatch(4096);
|
||||||
|
|
||||||
batch = new Batch2D(1024);
|
batch = new Batch2D(1024);
|
||||||
|
activeBlockBatch = new Batch2D(1024);
|
||||||
uicamera = new Camera(glm::vec3(), Window::height / uiscale);
|
uicamera = new Camera(glm::vec3(), Window::height / uiscale);
|
||||||
uicamera->perspective = false;
|
uicamera->perspective = false;
|
||||||
}
|
}
|
||||||
@ -57,6 +63,7 @@ void finalize_renderer(){
|
|||||||
delete crosshair;
|
delete crosshair;
|
||||||
delete lineBatch;
|
delete lineBatch;
|
||||||
delete batch;
|
delete batch;
|
||||||
|
delete activeBlockBatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_chunk(size_t index, Camera* camera, Shader* shader, bool occlusion){
|
void draw_chunk(size_t index, Camera* camera, Shader* shader, bool occlusion){
|
||||||
@ -105,8 +112,8 @@ bool chunks_comparator(size_t i, size_t j) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void draw_world(Camera* camera, Assets* assets, Chunks* chunks,
|
void draw_world(Player* player, Camera* camera, Assets* assets, Chunks* chunks,
|
||||||
bool occlusion, bool devdata){
|
bool occlusion, bool devdata, int fps){
|
||||||
glClearColor(0.7f,0.81f,1.0f,1);
|
glClearColor(0.7f,0.81f,1.0f,1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
@ -115,6 +122,7 @@ void draw_world(Camera* camera, Assets* assets, Chunks* chunks,
|
|||||||
|
|
||||||
// Draw VAO
|
// Draw VAO
|
||||||
Texture* texture = assets->getTexture("block");
|
Texture* texture = assets->getTexture("block");
|
||||||
|
Texture* blocks = assets->getTexture("block_select");
|
||||||
Shader* shader = assets->getShader("main");
|
Shader* shader = assets->getShader("main");
|
||||||
Shader* crosshairShader = assets->getShader("crosshair");
|
Shader* crosshairShader = assets->getShader("crosshair");
|
||||||
Shader* linesShader = assets->getShader("lines");
|
Shader* linesShader = assets->getShader("lines");
|
||||||
@ -126,6 +134,7 @@ void draw_world(Camera* camera, Assets* assets, Chunks* chunks,
|
|||||||
shader->uniform3f("u_fogColor", 0.7f,0.71f,0.73f);
|
shader->uniform3f("u_fogColor", 0.7f,0.71f,0.73f);
|
||||||
shader->uniform3f("u_cameraPos", camera->position.x,camera->position.y,camera->position.z);
|
shader->uniform3f("u_cameraPos", camera->position.x,camera->position.y,camera->position.z);
|
||||||
texture->bind();
|
texture->bind();
|
||||||
|
// blocks->bind();
|
||||||
|
|
||||||
std::vector<size_t> indices;
|
std::vector<size_t> indices;
|
||||||
|
|
||||||
@ -170,14 +179,27 @@ void draw_world(Camera* camera, Assets* assets, Chunks* chunks,
|
|||||||
uishader->uniformMatrix("u_projview", uicamera->getProjection());
|
uishader->uniformMatrix("u_projview", uicamera->getProjection());
|
||||||
|
|
||||||
Font* font = assets->getFont("normal");
|
Font* font = assets->getFont("normal");
|
||||||
|
// Texture* blocks = assets->getTexture("blocks")
|
||||||
batch->begin();
|
batch->begin();
|
||||||
batch->texture(font->texture);
|
batch->texture(font->texture);
|
||||||
// font->draw(batch, "void Font::draw(Batch2D* batch, std::string text, int x, int y) {", 10, 10);
|
// font->draw(batch, "void Font::draw(Batch2D* batch, std::string text, int x, int y) {", 10, 10);
|
||||||
if (devdata){
|
if (devdata){
|
||||||
font->draw(batch, "devdata does not exist", 10, 10);
|
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->rect(0, 0, 256, 256);
|
||||||
batch->render();
|
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
|
#endif // WORLD_RENDERER_CPP
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user