From 8e221cbc89e523a60f4ff9915b94ad7abeef844b Mon Sep 17 00:00:00 2001 From: "Dmitry V. Sokolov" Date: Sat, 9 Feb 2019 17:05:45 +0100 Subject: [PATCH] apply textures to the walls --- tinyraycaster.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tinyraycaster.cpp b/tinyraycaster.cpp index 10ee09f..8ed98a2 100644 --- a/tinyraycaster.cpp +++ b/tinyraycaster.cpp @@ -79,6 +79,18 @@ bool load_texture(const std::string filename, std::vector &texture, si return true; } +std::vector texture_column(const std::vector &img, const size_t texsize, const size_t ntextures, const size_t texid, const size_t texcoord, const size_t column_height) { + const size_t img_w = texsize*ntextures; + const size_t img_h = texsize; + assert(img.size()==img_w*img_h && texcoord column(column_height); + for (size_t y=0; ystd::abs(hitx)) { // we need to determine whether we hit a "vertical" or a "horizontal" wall (w.r.t the map) + x_texcoord = hity*walltext_size; + } + if (x_texcoord<0) x_texcoord += walltext_size; // do not forget x_texcoord can be negative, fix that + assert(x_texcoord>=0 && x_texcoord<(int)walltext_size); + + std::vector column = texture_column(walltext, walltext_size, walltext_cnt, texid, x_texcoord, column_height); + pix_x = win_w/2+i; + for (size_t j=0; j=(int)win_h) continue; + framebuffer[pix_x + pix_y*win_w] = column[j]; + } break; } }