Skip to content

Commit

Permalink
GLM-related Shader.uniformNf overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Nov 16, 2023
1 parent 47e24cb commit bcecdc9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/frontend/world_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float
shader->uniformMatrix("u_view", camera->getView());
shader->uniform1f("u_gamma", 1.6f);
shader->uniform3f("u_skyLightColor", 1.1f,1.1f,1.1f);
shader->uniform3f("u_fogColor", skyColor.r,skyColor.g,skyColor.b);
shader->uniform3f("u_fogColor", skyColor);
shader->uniform1f("u_fogFactor", fogFactor);
shader->uniform1f("u_fogCurve", fogCurve);
shader->uniform3f("u_cameraPos", camera->position.x,camera->position.y,camera->position.z);
shader->uniform3f("u_cameraPos", camera->position);

Block* cblock = Block::blocks[level->player->choosenBlock];
float multiplier = 0.2f;
Expand Down Expand Up @@ -146,8 +146,12 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float
float length = 40.f;

linesShader->use();
glm::mat4 model(glm::translate(glm::mat4(1.f), vec3(Window::width >> 1, -static_cast<int>(Window::height) >> 1, 0.f)));
linesShader->uniformMatrix("u_projview", glm::ortho(0.f, static_cast<float>(Window::width), -static_cast<float>(Window::height), 0.f, -length, length) * model * glm::inverse(camera->rotation));
vec3 tsl = vec3(Window::width/2, -((int)Window::height)/2, 0.f);
glm::mat4 model(glm::translate(glm::mat4(1.f), tsl));
linesShader->uniformMatrix("u_projview", glm::ortho(
0.f, (float)Window::width,
-(float)Window::height, 0.f,
-length, length) * model * glm::inverse(camera->rotation));

glDisable(GL_DEPTH_TEST);

Expand Down
9 changes: 9 additions & 0 deletions src/graphics/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,20 @@ void Shader::uniform2f(std::string name, float x, float y){
glUniform2f(transformLoc, x, y);
}

void Shader::uniform2f(std::string name, glm::vec2 xy){
GLuint transformLoc = glGetUniformLocation(id, name.c_str());
glUniform2f(transformLoc, xy.x, xy.y);
}

void Shader::uniform3f(std::string name, float x, float y, float z){
GLuint transformLoc = glGetUniformLocation(id, name.c_str());
glUniform3f(transformLoc, x,y,z);
}

void Shader::uniform3f(std::string name, glm::vec3 xyz){
GLuint transformLoc = glGetUniformLocation(id, name.c_str());
glUniform3f(transformLoc, xyz.x, xyz.y, xyz.z);
}


Shader* load_shader(std::string vertexFile, std::string fragmentFile) {
Expand Down
2 changes: 2 additions & 0 deletions src/graphics/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class Shader {
void uniform1i(std::string name, int x);
void uniform1f(std::string name, float x);
void uniform2f(std::string name, float x, float y);
void uniform2f(std::string name, glm::vec2 xy);
void uniform3f(std::string name, float x, float y, float z);
void uniform3f(std::string name, glm::vec3 xyz);
};

extern Shader* load_shader(std::string vertexFile, std::string fragmentFile);
Expand Down
4 changes: 3 additions & 1 deletion src/voxels/ChunksController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ bool ChunksController::loadVisible(){
for (size_t i = 0; i < CHUNK_VOL; i++) {
blockid_t id = chunk->voxels[i].id;
if (Block::blocks[id] == nullptr) {
std::cout << "corruped block detected at " << i << " of chunk " << chunk->x << "x" << chunk->z << " -> " << (int)id << std::endl;
std::cout << "corruped block detected at " << i << " of chunk ";
std::cout << chunk->x << "x" << chunk->z;
std::cout << " -> " << (int)id << std::endl;
chunk->voxels[i].id = 11;
}
}
Expand Down

0 comments on commit bcecdc9

Please sign in to comment.