Tried out 512px tiles and sprites and they actually look like crap. They just look like bad textures not better painted. With 256 they look nicely pixelated.
Before Width: | Height: | Size: 20 KiB |
BIN
assets/armored_knight_1-512.png
Normal file
After Width: | Height: | Size: 117 KiB |
Before Width: | Height: | Size: 58 KiB |
BIN
assets/ceiling_test-512.png
Normal file
After Width: | Height: | Size: 249 KiB |
Before Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 75 KiB |
|
@ -1,15 +1,17 @@
|
|||
{
|
||||
"textures": [
|
||||
"assets/tile01.png",
|
||||
"assets/tile16.png",
|
||||
"assets/tile02.png",
|
||||
"assets/tile03.png",
|
||||
"assets/tile05.png",
|
||||
"assets/tile17.png"
|
||||
"assets/floor_tile_test-512.png",
|
||||
"assets/wall_texture_test-512.png",
|
||||
"assets/ceiling_test-512.png",
|
||||
"assets/wood_wall-512.png"
|
||||
],
|
||||
"sprites": [
|
||||
"assets/portal.png"
|
||||
"assets/armored_knight_1-512.png",
|
||||
"assets/cinqueda_1-512.png",
|
||||
"assets/wood_barrel_large-512.png",
|
||||
"assets/evil_eye_test-512.png",
|
||||
"assets/undead_peasant-256.png"
|
||||
],
|
||||
"floor": "assets/tile32.png",
|
||||
"ceiling": "assets/tile10.png"
|
||||
"floor": "assets/floor_tile_test-512.png",
|
||||
"ceiling": "assets/ceiling_test-512.png"
|
||||
}
|
||||
|
|
Before Width: | Height: | Size: 59 KiB |
BIN
assets/evil_eye_test-512.png
Normal file
After Width: | Height: | Size: 204 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 87 KiB |
BIN
assets/floor_tile_test-512.png
Normal file
After Width: | Height: | Size: 350 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 196 KiB |
Before Width: | Height: | Size: 94 KiB |
Before Width: | Height: | Size: 134 KiB |
Before Width: | Height: | Size: 101 KiB |
Before Width: | Height: | Size: 144 KiB |
Before Width: | Height: | Size: 83 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 88 KiB |
Before Width: | Height: | Size: 58 KiB |
Before Width: | Height: | Size: 93 KiB |
Before Width: | Height: | Size: 77 KiB |
Before Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 115 KiB |
Before Width: | Height: | Size: 132 KiB |
Before Width: | Height: | Size: 140 KiB |
Before Width: | Height: | Size: 405 KiB |
Before Width: | Height: | Size: 97 KiB |
Before Width: | Height: | Size: 87 KiB |
Before Width: | Height: | Size: 94 KiB |
BIN
assets/wall_texture_test-512.png
Normal file
After Width: | Height: | Size: 389 KiB |
Before Width: | Height: | Size: 12 KiB |
BIN
assets/wood_barrel_large-512.png
Normal file
After Width: | Height: | Size: 263 KiB |
Before Width: | Height: | Size: 66 KiB |
BIN
assets/wood_wall-512.png
Normal file
After Width: | Height: | Size: 335 KiB |
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
constexpr const int TEXTURE_WIDTH=256;
|
||||
constexpr const int TEXTURE_HEIGHT=256;
|
||||
constexpr const int TEXTURE_WIDTH=512;
|
||||
constexpr const int TEXTURE_HEIGHT=512;
|
||||
constexpr const int RAY_VIEW_WIDTH=960;
|
||||
constexpr const int RAY_VIEW_HEIGHT=720;
|
||||
constexpr const int RAY_VIEW_X=(1280 - RAY_VIEW_WIDTH);
|
||||
|
|
|
@ -65,8 +65,8 @@ void Raycaster::clear() {
|
|||
}
|
||||
|
||||
void Raycaster::sprite_casting() {
|
||||
const int textureWidth = $textures.TEXTURE_WIDTH;
|
||||
const int textureHeight = $textures.TEXTURE_HEIGHT;
|
||||
const int textureWidth = TEXTURE_WIDTH;
|
||||
const int textureHeight = TEXTURE_HEIGHT;
|
||||
|
||||
// sort sprites from far to close
|
||||
for(int i = 0; i < $textures.NUM_SPRITES; i++) {
|
||||
|
@ -126,7 +126,7 @@ void Raycaster::sprite_casting() {
|
|||
if(!(transformY > 0 && transformY < ZBuffer[stripe])) break;
|
||||
}
|
||||
|
||||
int texX_end = int(256 * (stripe - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 256;
|
||||
int texX_end = int(512 * (stripe - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 512;
|
||||
|
||||
if(drawStartX < drawEndX && transformY > 0 && transformY < ZBuffer[drawStartX]) {
|
||||
int vMoveScreen = int(sprite_rec.elevation * -1 / transformY);
|
||||
|
@ -136,15 +136,15 @@ void Raycaster::sprite_casting() {
|
|||
int drawEndY = spriteHeight / 2 + $height / 2 + vMoveScreen;
|
||||
if(drawEndY >= $height) drawEndY = $height - 1;
|
||||
|
||||
int texX = int(256 * (drawStartX - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 256;
|
||||
int texX = int(512 * (drawStartX - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 512;
|
||||
|
||||
float x = float(drawStartX + RAY_VIEW_X);
|
||||
float y = float(drawStartY + RAY_VIEW_Y);
|
||||
float sprite_w = float(spriteWidth) / float(textureWidth);
|
||||
float sprite_h = float(spriteHeight) / float(textureHeight);
|
||||
|
||||
int d = (y - vMoveScreen) * 256 - $height * 128 + spriteHeight * 128;
|
||||
int texY = ((d * textureHeight) / spriteHeight) / 256;
|
||||
int d = (y - vMoveScreen) * 512 - $height * 256 + spriteHeight * 256;
|
||||
int texY = ((d * textureHeight) / spriteHeight) / 512;
|
||||
|
||||
sf_sprite->setScale({sprite_w, sprite_h});
|
||||
sf_sprite->setTextureRect(sf::IntRect({texX, texY}, {texX_end - texX, textureHeight}));
|
||||
|
@ -155,8 +155,8 @@ void Raycaster::sprite_casting() {
|
|||
}
|
||||
|
||||
void Raycaster::cast_rays() {
|
||||
constexpr static const int textureWidth = $textures.TEXTURE_WIDTH;
|
||||
constexpr static const int textureHeight = $textures.TEXTURE_HEIGHT;
|
||||
constexpr static const int textureWidth = TEXTURE_WIDTH;
|
||||
constexpr static const int textureHeight = TEXTURE_HEIGHT;
|
||||
double perpWallDist;
|
||||
|
||||
// WALL CASTING
|
||||
|
@ -229,7 +229,7 @@ void Raycaster::cast_rays() {
|
|||
int drawEnd = lineHeight / 2 + $height / 2 + $pitch;
|
||||
if(drawEnd >= $height) drawEnd = $height - 1;
|
||||
|
||||
auto &texture = $textures.get_texture($map[mapY][mapX] - 1);
|
||||
auto texture = $textures.get_texture($map[mapY][mapX] - 1);
|
||||
|
||||
// calculate value of wallX
|
||||
double wallX; // where exactly the wall was hit
|
||||
|
@ -265,8 +265,8 @@ void Raycaster::cast_rays() {
|
|||
}
|
||||
|
||||
void Raycaster::draw_ceiling_floor() {
|
||||
constexpr static const int textureWidth = $textures.TEXTURE_WIDTH;
|
||||
constexpr static const int textureHeight = $textures.TEXTURE_HEIGHT;
|
||||
constexpr static const int textureWidth = TEXTURE_WIDTH;
|
||||
constexpr static const int textureHeight = TEXTURE_HEIGHT;
|
||||
|
||||
for(int y = $height / 2 + 1; y < $height; ++y) {
|
||||
// rayDir for leftmost ray (x=0) and rightmost (x = w)
|
||||
|
@ -300,6 +300,9 @@ void Raycaster::draw_ceiling_floor() {
|
|||
float floorX = $posX + rowDistance * rayDirX0;
|
||||
float floorY = $posY + rowDistance * rayDirY0;
|
||||
|
||||
auto floor_texture = (const uint32_t *)$textures.floor.getPixelsPtr();
|
||||
auto ceiling_texture = (const uint32_t *)$textures.ceiling.getPixelsPtr();
|
||||
|
||||
for(int x = 0; x < $width; ++x) {
|
||||
// the cell coord is simply taken from the int parts of
|
||||
// floorX and floorY.
|
||||
|
@ -319,11 +322,11 @@ void Raycaster::draw_ceiling_floor() {
|
|||
// floorX cellX to find the texture x/y. How?
|
||||
|
||||
// FLOOR
|
||||
color = $textures.floor[textureWidth * ty + tx];
|
||||
color = floor_texture[textureWidth * ty + tx];
|
||||
$pixels[pixcoord(x, y)] = color;
|
||||
|
||||
// CEILING
|
||||
color = $textures.ceiling[textureWidth * ty + tx];
|
||||
color = ceiling_texture[textureWidth * ty + tx];
|
||||
$pixels[pixcoord(x, $height - y - 1)] = color;
|
||||
}
|
||||
}
|
||||
|
|
18
texture.cpp
|
@ -3,16 +3,12 @@
|
|||
#include "dbc.hpp"
|
||||
#include <fmt/core.h>
|
||||
#include "config.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
Image TexturePack::load_image(std::string filename) {
|
||||
Image texture(TEXTURE_WIDTH * TEXTURE_HEIGHT);
|
||||
sf::Image img;
|
||||
bool good = img.loadFromFile(filename);
|
||||
sf::Image TexturePack::load_image(std::string filename) {
|
||||
sf::Image texture;
|
||||
bool good = texture.loadFromFile(filename);
|
||||
dbc::check(good, fmt::format("failed to load {}", filename));
|
||||
|
||||
uint32_t *pixbuf = (uint32_t *)img.getPixelsPtr();
|
||||
std::copy_n(pixbuf, texture.size(), texture.begin());
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
@ -29,7 +25,7 @@ void TexturePack::load_textures() {
|
|||
floor = load_image(assets["floor"]);
|
||||
ceiling = load_image(assets["ceiling"]);
|
||||
|
||||
sf::Texture* sprite_texture = new sf::Texture("assets/evil_eye_test-256.png");
|
||||
sf::Texture* sprite_texture = new sf::Texture("assets/evil_eye_test-512.png");
|
||||
sprite_texture->setSmooth(false);
|
||||
sf::Sprite* sf_sprite = new sf::Sprite(*sprite_texture);
|
||||
sprites.push_back({4.0, 3.55, 6, sf_sprite, sprite_texture});
|
||||
|
@ -39,8 +35,8 @@ void TexturePack::load_textures() {
|
|||
sword.sprite = new sf::Sprite(*sword.sprite_texture);
|
||||
}
|
||||
|
||||
Image& TexturePack::get_texture(size_t num) {
|
||||
return images[num];
|
||||
const uint32_t* TexturePack::get_texture(size_t num) {
|
||||
return (const uint32_t *)images[num].getPixelsPtr();
|
||||
}
|
||||
|
||||
Sprite &TexturePack::get_sprite(size_t sprite_num) {
|
||||
|
|
14
texture.hpp
|
@ -17,21 +17,17 @@ struct Sprite {
|
|||
int vDiv=1;
|
||||
};
|
||||
|
||||
using Image = std::vector<uint32_t>;
|
||||
|
||||
struct TexturePack {
|
||||
int NUM_SPRITES=1;
|
||||
constexpr static const int TEXTURE_WIDTH=256; // must be power of two
|
||||
constexpr static const int TEXTURE_HEIGHT=256; // must be power of two
|
||||
|
||||
std::vector<Image> images;
|
||||
std::vector<sf::Image> images;
|
||||
std::vector<Sprite> sprites;
|
||||
Image floor;
|
||||
Image ceiling;
|
||||
sf::Image floor;
|
||||
sf::Image ceiling;
|
||||
Sprite sword;
|
||||
|
||||
void load_textures();
|
||||
std::vector<uint32_t> load_image(std::string filename);
|
||||
sf::Image load_image(std::string filename);
|
||||
Sprite& get_sprite(size_t sprite_num);
|
||||
Image& get_texture(size_t num);
|
||||
const uint32_t* get_texture(size_t num);
|
||||
};
|
||||
|
|