Skip to main content
Minor grammar fixes, markdown formatting
Source Link
liggiorgio
  • 5.5k
  • 6
  • 27
  • 38

These hills can form complicated structures for things like mountains: 

I also want to be able to select tiles with the mouse. I used this solution for a flat map:

  1. This question. The proposed solution does not work because slopes may have different silhouettes so you can't simplify every tile into lines with the same angles.

  2. This solution. As I understand, I'd have to create a second rectangular texture around each tile and use color data to represent the central tile and its neighbours. Still, but I don't think it would work well in my case because the tile can be drawn far from its actual position due to height or it can be completely covered by a large hill can completely cover it in front of it.

Short version: I split my map into small chunks of 100x100 pixels and use their red and green channels to store info about respective tiles.

Full version: I have these fields in my TownLevel class with a map:

I render an entire map to one texture and split it into chunks. I can't use the full map by itself because SDL_RenderReadPixels() works too slowly with large textures. The full map is not necessary and can break my code on other systems due to SDL_Texture size limitations, I'll remove it later. Also, I use a Texture class for all textures. I createcreated a full map and chunks in the constructor:

These hills can form complicated structures for things like mountains:

I also want to be able to select tiles with mouse. I used this solution for a flat map:

  1. This question. The proposed solution does not work because slopes may have different silhouettes so you can't simplify every tile into lines with same angles

  2. This solution. As I understand, I'd have to create a second rectangular texture around each tile and use color data to represent central tile and its neighbours, but I don't think it would work well in my case because tile can be drawn far from its actual position due to height or it can be completely covered by a large hill in front of it.

Short version: I split my map into small chunks 100x100 pixels and use their red and green channels to store info about respective tiles

Full version: I have these fields in my TownLevel class with map:

I render an entire map to one texture and split it into chunks. I can't use full map by itself because SDL_RenderReadPixels() works too slowly with large textures. The full map is not necessary and can break my code on other systems due to SDL_Texture size limitations, I'll remove it later. Also, I use a Texture class for all textures. I create full map and chunks in the constructor:

These hills can form complicated structures for things like mountains: 

I also want to be able to select tiles with the mouse. I used this solution for a flat map:

  1. This question. The proposed solution does not work because slopes may have different silhouettes so you can't simplify every tile into lines with the same angles.

  2. This solution. As I understand, I'd have to create a second rectangular texture around each tile and use color data to represent the central tile and its neighbours. Still, I don't think it would work well in my case because the tile can be drawn far from its actual position due to height or a large hill can completely cover it in front of it.

Short version: I split my map into small chunks of 100x100 pixels and use their red and green channels to store info about respective tiles.

Full version: I have these fields in my TownLevel class with a map:

I render an entire map to one texture and split it into chunks. I can't use the full map by itself because SDL_RenderReadPixels() works too slowly with large textures. The full map is not necessary and can break my code on other systems due to SDL_Texture size limitations, I'll remove it later. Also, I use a Texture class for all textures. I created a full map and chunks in the constructor:

deleted 367 characters in body
Source Link

Is it possible toSince I use 4 or 3only 2 channels of a color? Current implementation limits map size to 256x256. My initial thought was to treat a singleSDL_PIXELFORMAT_RGBA8888 pixel as a 32-bit number, but SDL uses alpha channel for blending. Basicallyinstead of 3 or 4, I need to to overwrite destination with the color and alpha from the source if the alpha inlimit size of the source pixel is not 0, is that possiblemap to achieve with SDL_ComposeCustomBlendMode()? Or if it's impossible, how2^16 instead of 2^24 or 2^32. How can I use pixel data more efficiently treat 3 channels as one 24-bit number or two 12-bit numbers without manual bit logic in the cycle?

Is it possible to use 4 or 3 channels of a color? Current implementation limits map size to 256x256. My initial thought was to treat a single pixel as a 32-bit number, but SDL uses alpha channel for blending. Basically, I need to to overwrite destination with the color and alpha from the source if the alpha in the source pixel is not 0, is that possible to achieve with SDL_ComposeCustomBlendMode()? Or if it's impossible, how can I efficiently treat 3 channels as one 24-bit number or two 12-bit numbers without manual bit logic in the cycle?

Since I use only 2 channels of SDL_PIXELFORMAT_RGBA8888 pixel instead of 3 or 4, I limit size of the map to 2^16 instead of 2^24 or 2^32. How can I use pixel data more efficiently?

deleted 247 characters in body
Source Link

QuestionsQuestion:

  1. Is it possible to use all 4 channels of a color? Current implementation limits map size to 256x256. My initial thought was to treat a single pixel as a 32-bit number, but SDL uses alpha channel for blending. Basically, I need to to overwrite destination with the color and alpha from the source if the alpha in the source pixel is not 0, is that possible to achieve with SDL_ComposeCustomBlendMode()?

  2. If its impossible to use alpha channel, is it possible to efficiently use 8 bits from blue channel? If I could do it, I could make maps with the size up to 4096x4096, which is probably enough for me, but c++ doesn't have built-in 24- or 12-bit types and I'm not sure how to use 24 bits in this case.

  3. Is this the optimal solution in general or am I overcomplicating things?

Is it possible to use 4 or 3 channels of a color? Current implementation limits map size to 256x256. My initial thought was to treat a single pixel as a 32-bit number, but SDL uses alpha channel for blending. Basically, I need to to overwrite destination with the color and alpha from the source if the alpha in the source pixel is not 0, is that possible to achieve with SDL_ComposeCustomBlendMode()? Or if it's impossible, how can I efficiently treat 3 channels as one 24-bit number or two 12-bit numbers without manual bit logic in the cycle?

Questions:

  1. Is it possible to use all 4 channels of a color? Current implementation limits map size to 256x256. My initial thought was to treat a single pixel as a 32-bit number, but SDL uses alpha channel for blending. Basically, I need to to overwrite destination with the color and alpha from the source if the alpha in the source pixel is not 0, is that possible to achieve with SDL_ComposeCustomBlendMode()?

  2. If its impossible to use alpha channel, is it possible to efficiently use 8 bits from blue channel? If I could do it, I could make maps with the size up to 4096x4096, which is probably enough for me, but c++ doesn't have built-in 24- or 12-bit types and I'm not sure how to use 24 bits in this case.

  3. Is this the optimal solution in general or am I overcomplicating things?

Question:

Is it possible to use 4 or 3 channels of a color? Current implementation limits map size to 256x256. My initial thought was to treat a single pixel as a 32-bit number, but SDL uses alpha channel for blending. Basically, I need to to overwrite destination with the color and alpha from the source if the alpha in the source pixel is not 0, is that possible to achieve with SDL_ComposeCustomBlendMode()? Or if it's impossible, how can I efficiently treat 3 channels as one 24-bit number or two 12-bit numbers without manual bit logic in the cycle?

added 2 characters in body
Source Link
Loading
added 2 characters in body
Source Link
Loading
Source Link
Loading