From 8e46fa85b2d83d65a51ea0cd276d8ecc46926d19 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 27 Feb 2026 08:05:24 +0100 Subject: [PATCH] - Ja carrega els patch, pero les textures es veuen mal. Arreglant mil coses del motor que tenia a foc pintar textures de 64x64 --- draw.cpp | 15 +++++++++++++++ draw.h | 4 ++++ main.cpp | 38 +++++++++++++++++++++----------------- wad.cpp | 21 ++++++++++++++++++--- 4 files changed, 58 insertions(+), 20 deletions(-) diff --git a/draw.cpp b/draw.cpp index 36e46b5..2b8afe4 100644 --- a/draw.cpp +++ b/draw.cpp @@ -99,6 +99,21 @@ namespace draw return surf->pixels[x+y*surf->w]; } + void putpsurf(surface_t *dest, int x, int y, uint8_t color) + { + if (x<0 || y<0 || x>=dest->w || y>=dest->h) return; + dest->pixels[x+y*dest->w] = color; + } + + void drawsurf(int x, int y, surface_t *src, surface_t *dst) + { + int w = src->w; if (x+w > dst->w) w = dst->w-x; + int h = src->h; if (y+h > dst->h) h = dst->h-y; + for (int py=0;pypixels[(px+x)+(py+y)*dst->w] = src->pixels[x+y*src->w]; + } + void line(int x1, int y1, int x2, int y2, Uint8 color) { float dx = float(x2-x1); diff --git a/draw.h b/draw.h index d5e2ecd..71141d5 100644 --- a/draw.h +++ b/draw.h @@ -20,6 +20,10 @@ namespace draw void putpd(int x, int y, uint8_t color, float depth); void putps(int x, int y, uint8_t color, float depth); uint8_t getp(surface_t *surf, int x, int y); + + void putpsurf(surface_t *dest, int x, int y, uint8_t color); + void drawsurf(int x, int y, surface_t *src, surface_t *dst); + void line(int x1, int y1, int x2, int y2, uint8_t color); void render(); void flip(); diff --git a/main.cpp b/main.cpp index ae4f73e..b360802 100644 --- a/main.cpp +++ b/main.cpp @@ -6,7 +6,7 @@ #include "draw.h" #include "wad.h" -#define FOV 190 +#define FOV 277 struct wall { Uint16 v1, v2; @@ -50,7 +50,7 @@ void createMap() { sector s; s.floor_height = 32.0f; - s.ceiling_height = 128.0f; + s.ceiling_height = 96.0f; s.verts.push_back({ 64.0f, 0.0f}); s.verts.push_back({256.0f, 0.0f}); @@ -75,7 +75,7 @@ void createMap() { sector s; s.floor_height = 0.0f; - s.ceiling_height = 96.0f; + s.ceiling_height = 128.0f; s.verts.push_back({256.0f, 0.0f}); s.verts.push_back({ 64.0f, 0.0f}); @@ -103,7 +103,8 @@ void createMap() { for (auto &w : s.walls ) { - w.u2 = distance(s.verts[w.v1], s.verts[w.v2]) / 64.0f; + w.u2 = distance(s.verts[w.v1], s.verts[w.v2]) / 8.0f; + //w.v2 = distance(s.verts[w.v1], s.verts[w.v2]) / 32.0f; vec2 norm = { s.verts[w.v2].x - s.verts[w.v1].x, s.verts[w.v2].y - s.verts[w.v1].y}; normalize(&norm); const float tmp = norm.x; norm.x = -norm.y; norm.y = tmp; @@ -135,18 +136,18 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v } if (w) { - const int tex_height = 64; + //const int tex_height = gif->h; //64; const float sector_height = s.ceiling_height - s.floor_height; draw::map::putp(result.x, result.y, 6); float dist = stright_dist * SDL_cosf(a_inc*DEG_TO_RAD); const vec2 AB = {s.verts[w->v2].x-s.verts[w->v1].x, s.verts[w->v2].y-s.verts[w->v1].y}; const vec2 AP = {result.x-s.verts[w->v1].x, result.y-s.verts[w->v1].y}; - float v = dot(AP,AB) / dot(AB,AB); v *= w->u2; v = (v-int(v))*tex_height; + float v = dot(AP,AB) / dot(AB,AB); v *= w->u2; v = v*gif->w; //(v-int(v))*gif->w; float wall_height = (sector_height*FOV)/dist; // [64=altura sector] float wall_cut = 0.0f; - float dpix = tex_height/wall_height; // [64=crec que altura sector] + float dpix = sector_height/wall_height; // [64=crec que altura sector] float cpix = 0; float wall_start = 120-(wall_height/sector_height)*(sector_height-(height-s.floor_height)); // [64=els dos crec que altura sector] if (wall_start> 1)); float actual_dist = straight_dist / SDL_cosf(a_inc*DEG_TO_RAD); - int tx = SDL_abs(int(actual_dist * SDL_cosf(angle*DEG_TO_RAD) - position.x)) % tex_height; - int ty = SDL_abs(int(actual_dist * SDL_sinf(angle*DEG_TO_RAD) - position.y)) % tex_height; - draw::putpd(screen_column, y, gif->pixels[tx+ty*tex_height], -straight_dist); + int tx = SDL_abs(int(actual_dist * SDL_cosf(angle*DEG_TO_RAD) - position.x)) % gif->w; + int ty = SDL_abs(int(actual_dist * SDL_sinf(angle*DEG_TO_RAD) - position.y)) % gif->h; + draw::putpd(screen_column, y, gif->pixels[tx+ty*gif->w], -straight_dist); } @@ -171,7 +172,7 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v // Pinta la pared for (int i=0; i=end) break; - draw::putpd(screen_column, wall_start+i, gif->pixels[(int(v)%tex_height)+int(cpix)*tex_height], stright_dist); + draw::putpd(screen_column, wall_start+i, gif->pixels[(int(v)%gif->w)+(int(cpix)%gif->h)*gif->w], stright_dist); cpix += dpix; } } else { @@ -185,7 +186,7 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v // Pinta la pared for (int i=0; i=end) break; - draw::putpd(screen_column, wall_start+i, gif->pixels[(int(v)%tex_height)+int(cpix)*tex_height], stright_dist); + draw::putpd(screen_column, wall_start+i, gif->pixels[(int(v)%gif->w)+(int(cpix)%gif->h)*gif->w], stright_dist); cpix += dpix; } wall_start += upper_wall_height; @@ -206,7 +207,7 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v // Pinta la pared for (int i=0; i=end) break; - draw::putpd(screen_column, wall_end+i, gif->pixels[(int(v)%tex_height)+int(cpix)*tex_height], stright_dist); + draw::putpd(screen_column, wall_end+i, gif->pixels[(int(v)%gif->w)+(int(cpix)%gif->h)*gif->w], stright_dist); cpix += dpix; } //wall_start += upper_wall_height; @@ -220,9 +221,9 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v for (int y=paint_end+1; y> 1)); float actual_dist = straight_dist / SDL_cosf(a_inc*DEG_TO_RAD); - int tx = SDL_abs(int(actual_dist * SDL_cosf(angle*DEG_TO_RAD) + position.x)) % tex_height; - int ty = SDL_abs(int(actual_dist * SDL_sinf(angle*DEG_TO_RAD) + position.y)) % tex_height; - draw::putpd(screen_column, y, gif->pixels[tx+ty*tex_height], straight_dist); + int tx = SDL_abs(int(actual_dist * SDL_cosf(angle*DEG_TO_RAD) + position.x)) % gif->w; + int ty = SDL_abs(int(actual_dist * SDL_sinf(angle*DEG_TO_RAD) + position.y)) % gif->h; + draw::putpd(screen_column, y, gif->pixels[tx+ty*gif->w], straight_dist); } //line(screen_column, 120-(wall_height), screen_column, 120+(wall_height), 5); } @@ -279,7 +280,10 @@ int main(int argc, char *argv[]) draw::init(); - gif = wad::loadFlat("FLOOR4_8"); //draw::loadgif("walls.gif"); + //gif = draw::loadgif("walls.gif"); + //gif = wad::loadFlat("FLOOR4_8"); + //gif = wad::loadTexture("COMPSPAN"); + gif = wad::loadPatch("TTALL1_2"); //palette = draw::loadpal("walls.gif"); palette = wad::loadPalette(0); draw::setpal(palette); diff --git a/wad.cpp b/wad.cpp index da9bb03..1aa2d65 100644 --- a/wad.cpp +++ b/wad.cpp @@ -124,11 +124,12 @@ namespace wad { uint16_t *patches = &((uint16_t*)texture_info)[5]; for (int i=0; i