Forgotten Elixir

An enchanting engine where magic and technology intertwine

Rendering wall textures and change to level configuration

created: 2025-03-11 04:36:33 UTC
last updated: 2025-03-11 04:36:48 UTC

I am now rendering textures to the wall appropriately!
Screenshot 2025-03-10 at 9.28.33 PM.png 616 KB

As shown above, we have walls consisting of different textures as defined by the map below.
1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 3
1 0 0 0 0 0 0 0 0 3
1 0 0 0 0 0 0 0 0 2
1 1 1 1 1 1 3 3 2 2

And now is how the current level configuration looks like.

player:
  x: 200
  y: 200
  width: 10
  height: 10
map:
  rows: 10 
  columns: 10
  path: ./assets/maps/one
wall_textures:
  - id: 1
    path: "./assets/textures/redbrick.png"
  - id: 2
    path: "./assets/textures/graystone.png"
  - id: 3
    path: "./assets/textures/colorstone.png"
sprite_textures:
  - name: "armor"
    path: "./assets/textures/armor.png"
  - name: "light"
    path: "./assets/textures/light.png"

One major change is in the sprites. I maintain two unordered_maps, one for sprites and one for wall textures. The wall textures are keyed off of the id. So in the map above, a wall Id of 1 maps to the redbrick, Id 2maps to the graystone and so forth. So when a ray hits a wall that is a 2, the ray store that 2. During wall rendering, we query the unordered_map for wall textures for the texture with the Id 2 which will return the SDL_Surface.

That is another change I made. SDL_Texture utilize the GPU hardware and therefore, are not directly accessible via a buffer of pixels. Changing to storing textures in memory as an SDL_Surface make the pixel buffer accessible to the CPU. The SDL_Textures are more performant, but that is more of utilizing the GPU on the machine. Since I am going for a Wolfenstein style engine, we want to render strictly from the CPU. At least unless I decided to convert the rendering to using SDL_gpu, but as of right now, that is not my intention so far.