Add background color uniform, remove current color state
This commit is contained in:
parent
6dab039298
commit
39ad8c3b34
5 changed files with 42 additions and 69 deletions
|
@ -1,6 +1,7 @@
|
|||
#version 330 core
|
||||
|
||||
uniform vec4 colortint;
|
||||
uniform vec4 colorbackground;
|
||||
uniform sampler2D textureSampler;
|
||||
|
||||
in vec2 UV;
|
||||
|
@ -9,8 +10,11 @@ out vec4 color;
|
|||
|
||||
void main() {
|
||||
vec4 col = texture(textureSampler, UV);
|
||||
if (col.rgb == vec3(1.0, 0.0, 1.0))
|
||||
discard;
|
||||
if (col.rgb == vec3(1.0, 0.0, 1.0)) {
|
||||
color = colorbackground;
|
||||
}
|
||||
else {
|
||||
color = col * colortint;
|
||||
}
|
||||
//color = colortint;
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ Gamestate *PlayState::update(double delta) {
|
|||
|
||||
bool debug_actors = false;
|
||||
bool debug_settings = false;
|
||||
bool debug_disable_fov = true;
|
||||
bool debug_disable_fov = false;
|
||||
|
||||
void PlayState::draw(double delta) {
|
||||
if (debug) {
|
||||
|
@ -231,21 +231,18 @@ void PlayState::draw(double delta) {
|
|||
|
||||
auto entities = tilemap.get_entity_list();
|
||||
|
||||
Color black = Color(0, 0, 0, 1);
|
||||
|
||||
// Draw dead actors
|
||||
for (Entity* var : *entities) {
|
||||
if (var->entity_type() == ENTITY_ACTOR && ((Actor*)var)->is_alive()) continue;
|
||||
|
||||
vec2i pos = var->get_position();
|
||||
if (debug_disable_fov || fov.can_see(pos)) {
|
||||
|
||||
app->renderer->set_color(0, 0, 0, 1);
|
||||
app->renderer->draw_sprite(ascii->get_sprite(219), margin.x + (offset.x + pos.x) * asciisize.x, margin.y + (offset.y + pos.y) * asciisize.y);
|
||||
|
||||
int sprite = var->get_sprite_id();
|
||||
|
||||
app->renderer->set_color(var->get_sprite_color()*0.35f);
|
||||
|
||||
app->renderer->draw_sprite(ascii->get_sprite(sprite), margin.x + (offset.x + pos.x) * asciisize.x, margin.y + (offset.y + pos.y) * asciisize.y);
|
||||
Color fg = var->get_sprite_color()*0.35f;
|
||||
app->renderer->draw_sprite(ascii->get_sprite(sprite), fg, black, margin.x + (offset.x + pos.x) * asciisize.x, margin.y + (offset.y + pos.y) * asciisize.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,23 +253,17 @@ void PlayState::draw(double delta) {
|
|||
vec2i pos = var->get_position();
|
||||
if (debug_disable_fov || fov.can_see(pos)) {
|
||||
|
||||
app->renderer->set_color(0, 0, 0, 1);
|
||||
app->renderer->draw_sprite(ascii->get_sprite(219), margin.x + (offset.x + pos.x) * asciisize.x, margin.y + (offset.y + pos.y) * asciisize.y);
|
||||
|
||||
int sprite = var->get_sprite_id();
|
||||
|
||||
app->renderer->set_color(var->get_sprite_color());
|
||||
Color fg = var->get_sprite_color();
|
||||
|
||||
app->renderer->draw_sprite(ascii->get_sprite(sprite), margin.x + (offset.x + pos.x) * asciisize.x, margin.y + (offset.y + pos.y) * asciisize.y);
|
||||
app->renderer->draw_sprite(ascii->get_sprite(sprite), fg, black, margin.x + (offset.x + pos.x) * asciisize.x, margin.y + (offset.y + pos.y) * asciisize.y);
|
||||
}
|
||||
}
|
||||
if (hero != nullptr) {
|
||||
app->renderer->set_color(155, 5, 5, 255);
|
||||
Color fg = Color(1, 0.01, 0.01, 1);
|
||||
for (int i = 0; i < hero->get_health(); i++) {
|
||||
app->renderer->set_color(0, 0, 0, 255);
|
||||
app->renderer->draw_sprite(ascii->get_sprite(219), (i+1) * asciisize.x, asciisize.y);
|
||||
app->renderer->set_color(255, 0, 0, 255);
|
||||
app->renderer->draw_sprite(ascii->get_sprite(3), (i+1) * asciisize.x, asciisize.y);
|
||||
app->renderer->draw_sprite(ascii->get_sprite(3), fg, black, (i+1) * asciisize.x, asciisize.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,6 +110,7 @@ GLuint shaderProg;
|
|||
GLuint wireShaderProg;
|
||||
GLuint spriteVertArrayId;
|
||||
GLint colorUniform;
|
||||
GLint bgUniform;
|
||||
GLint mvpUniform;
|
||||
|
||||
bool Renderer::Init(std::string title, int width, int height) {
|
||||
|
@ -169,6 +170,7 @@ bool Renderer::Init(std::string title, int width, int height) {
|
|||
glUseProgram(shaderProg);
|
||||
|
||||
colorUniform = glGetUniformLocation(shaderProg, "colortint");
|
||||
bgUniform = glGetUniformLocation(shaderProg, "colorbackground");
|
||||
mvpUniform = glGetUniformLocation(shaderProg, "MVP");
|
||||
|
||||
set_window_size(width, height);
|
||||
|
@ -177,14 +179,6 @@ bool Renderer::Init(std::string title, int width, int height) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Renderer::set_color(float r, float g, float b, float a) {
|
||||
currentcolor = { r, g, b, a };
|
||||
}
|
||||
|
||||
void Renderer::set_color(Color col) {
|
||||
set_color(col.r, col.g, col.b, col.a);
|
||||
}
|
||||
|
||||
void Renderer::set_title(const char *title) {
|
||||
SDL_SetWindowTitle(window, title);
|
||||
}
|
||||
|
@ -321,7 +315,7 @@ Sprite Renderer::CreateSprite(std::string path, int x, int y, int w, int h) {
|
|||
}
|
||||
|
||||
|
||||
void Renderer::draw_sprite(Sprite *sprite, int x, int y, float sx, float sy) {
|
||||
void Renderer::draw_sprite(Sprite *sprite, Color fg, Color bg, int x, int y, float sx, float sy) {
|
||||
|
||||
glm::mat4 model = glm::translate(glm::vec3(x, y, 0)) * glm::scale(glm::vec3(sprite->region.w * sx, sprite->region.h * sy, 1)) * glm::mat4(1);
|
||||
|
||||
|
@ -334,7 +328,8 @@ void Renderer::draw_sprite(Sprite *sprite, int x, int y, float sx, float sy) {
|
|||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
|
||||
|
||||
glUseProgram(shaderProg);
|
||||
glUniform4f(colorUniform, currentcolor.r, currentcolor.g, currentcolor.b, currentcolor.a);
|
||||
glUniform4f(colorUniform, fg.r, fg.g, fg.b, fg.a);
|
||||
glUniform4f(bgUniform, bg.r, bg.g, bg.b, bg.a);
|
||||
|
||||
glUniformMatrix4fv(mvpUniform, 1, GL_FALSE, &mvp[0][0]);
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ class Renderer
|
|||
{
|
||||
SDL_Window* window;
|
||||
SDL_GLContext context;
|
||||
Color currentcolor;
|
||||
unsigned int spriteVBuf;
|
||||
std::vector<Sprite> sprites;
|
||||
std::map<std::string, Texture> textures;
|
||||
|
@ -39,8 +38,6 @@ public:
|
|||
Renderer();
|
||||
~Renderer();
|
||||
bool Init(std::string title, int width, int height);
|
||||
void set_color(float r, float g, float b, float a);
|
||||
void set_color(Color col);
|
||||
void set_title(const char *title);
|
||||
void set_window_size(int width, int height);
|
||||
void set_clear_color(float r, float g, float b, float a);
|
||||
|
@ -55,7 +52,7 @@ public:
|
|||
void ImguiNewFrame();
|
||||
Texture * LoadTexture(std::string path);
|
||||
Sprite CreateSprite(std::string path, int x, int y, int w, int h);
|
||||
void draw_sprite(Sprite *sprite, int x, int y, float sx = 1, float sy = 1);
|
||||
void draw_sprite(Sprite *sprite, Color fg, Color bg, int x, int y, float sx = 1, float sy = 1);
|
||||
void Clear();
|
||||
void Present();
|
||||
};
|
||||
|
|
|
@ -6,43 +6,36 @@
|
|||
#include "FieldOfView.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
int Tilemap::get_index(int x, int y)
|
||||
{
|
||||
int Tilemap::get_index(int x, int y) {
|
||||
return y * width + x;
|
||||
}
|
||||
|
||||
Tilemap::Tilemap(int width, int height)
|
||||
{
|
||||
Tilemap::Tilemap(int width, int height) {
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
tilemap = std::vector<unsigned int>(width*height, 0);
|
||||
}
|
||||
|
||||
Tilemap::~Tilemap()
|
||||
{
|
||||
Tilemap::~Tilemap() {
|
||||
for (auto var : entities) {
|
||||
delete var;
|
||||
}
|
||||
}
|
||||
|
||||
int Tilemap::get_width()
|
||||
{
|
||||
int Tilemap::get_width() {
|
||||
return width;
|
||||
}
|
||||
|
||||
int Tilemap::get_height()
|
||||
{
|
||||
int Tilemap::get_height() {
|
||||
return height;
|
||||
}
|
||||
|
||||
bool Tilemap::is_inside_bounds(int x, int y)
|
||||
{
|
||||
bool Tilemap::is_inside_bounds(int x, int y) {
|
||||
return x >= 0 && x < width && y >= 0 && y < height;
|
||||
}
|
||||
|
||||
std::vector<vec2i> Tilemap::get_neighbours(int x, int y, int range)
|
||||
{
|
||||
return get_neighbours(x,y,range,range,range,range);
|
||||
std::vector<vec2i> Tilemap::get_neighbours(int x, int y, int range) {
|
||||
return get_neighbours(x, y, range, range, range, range);
|
||||
}
|
||||
|
||||
std::vector<vec2i> Tilemap::get_neighbours(int x, int y, int up, int down, int left, int right) {
|
||||
|
@ -57,28 +50,22 @@ std::vector<vec2i> Tilemap::get_neighbours(int x, int y, int up, int down, int l
|
|||
return neigh;
|
||||
}
|
||||
|
||||
void Tilemap::set_tile(int x, int y, unsigned int tile)
|
||||
{
|
||||
if (is_inside_bounds(x, y))
|
||||
{
|
||||
void Tilemap::set_tile(int x, int y, unsigned int tile) {
|
||||
if (is_inside_bounds(x, y)) {
|
||||
tilemap[get_index(x, y)] = tile;
|
||||
}
|
||||
}
|
||||
|
||||
int Tilemap::get_tile(int x, int y)
|
||||
{
|
||||
if (is_inside_bounds(x, y))
|
||||
{
|
||||
int Tilemap::get_tile(int x, int y) {
|
||||
if (is_inside_bounds(x, y)) {
|
||||
return tilemap[get_index(x, y)];
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool Tilemap::is_blocked(int x, int y)
|
||||
{
|
||||
if (is_inside_bounds(x, y))
|
||||
{
|
||||
if (tilemap[get_index(x,y)] == '#') { // TODO: Replace hardcoded tiles
|
||||
bool Tilemap::is_blocked(int x, int y) {
|
||||
if (is_inside_bounds(x, y)) {
|
||||
if (tilemap[get_index(x, y)] == '#') { // TODO: Replace hardcoded tiles
|
||||
return true;
|
||||
}
|
||||
for (Entity* var : entities) {
|
||||
|
@ -151,14 +138,13 @@ void Tilemap::draw(Renderer *renderer, Tileset* tileset, int x, int y, int tx, i
|
|||
int ax = tx + ix;
|
||||
int ay = ty + iy;
|
||||
if (is_inside_bounds(ax, ay)) {
|
||||
if (view == nullptr || view->has_seen({ax, ay})) {
|
||||
if (view == nullptr || view->has_seen({ ax, ay })) {
|
||||
Color fg = Color(1, 1, 1, 1);
|
||||
Color bg = Color(0, 0, 0, 1);
|
||||
if (view != nullptr && !view->can_see({ ax, ay })) {
|
||||
renderer->set_color(1, 1, 1, .3f);
|
||||
fg.a = 0.4f;
|
||||
}
|
||||
else {
|
||||
renderer->set_color(1, 1, 1, 1);
|
||||
}
|
||||
renderer->draw_sprite(tileset->get_sprite(get_tile(ax, ay)), x + ix * w, y + iy * h);
|
||||
renderer->draw_sprite(tileset->get_sprite(get_tile(ax, ay)), fg, bg, x + ix * w, y + iy * h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue