Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
One single layer, no sprites. Pushing Tilengine to its limits?
#11
(06-17-2023, 02:06 AM)megamarc Wrote: Hi!

I see, you're displaying a direct color 16 bpp image (at least). For doing this, Tilengine doesn't have anything special to offer. As you're not using any feature like raster effects, layer composition or animation, I'd just use plain SDL2 to create a 32-bit streaming texture and blit video frames onto it:

https://wiki.libsdl.org/SDL2/SDL_CreateTexture
Hi!

I use raster effects in a clever way.
I have a long tile that is 256x8. it has 256 vertical lines, each line is one color, so this tile has 256 colors.
I fill the screen with this tile and then I change the palette at every scanline.
So you have 224 palettes of 256 colors, each palette entry corresponds to one pixel.
Reply
#12
(06-17-2023, 07:05 AM)System64 Wrote: Hi!

I use raster effects in a clever way.
I have a long tile that is 256x8. it has 256 vertical lines, each line is one color, so this tile has 256 colors.
I fill the screen with this tile and then I change the palette at every scanline.
So you have 224 palettes of 256 colors, each palette entry corresponds to one pixel.

Seems really interesting, could you share the code so I could try it out as well?
Reply
#13
I agree, that's a very creative use, would be nice to see sample implementation
Reply
#14
Hi, I found the code, it is quite simple. I read a binary file that contains the colors :
Code:
import std/streams
import Tilengine/Tilengine
import strutils
proc readInts(path: string): seq[uint32] =
  result = newSeq[uint32](57344) # Preallocate 100 ints
  let fs = newFileStream(path, fmRead)
  defer: fs.close()
  let read = fs.readData(result[0].addr, sizeof(uint32) * result.len)
  result.setLen(read div sizeof(int32))

var array = readInts("./byte.dat")

var engine = initEngine(256, 224, 2, 0, 0)

var palettes: array[256, TLN_Palette]

# We init palettes...
for i in 0..palettes.len - 1:
    palettes[i] = createPalette(256)
    for a in 0..255:
        discard setPaletteColor(palettes[i], a, 0, 0, 0)

for y in 0..223: # 224 scanlines
    for x in 0..255: # 256 columns
        let arr = cast[array[4, byte]](array[(y * 256) + x])
        discard setPaletteColor(palettes[y], x, arr[0], arr[1], arr[2]) 

proc rasterCallback(scanline: cint) =
    discard setLayerPalette(1, palettes[scanline])
    var color = getPaletteColor(palettes[scanline], 0)
    setBgColor(color)

setRasterCallback(  rasterCallback)

# The background that contains 256 colors, and is 256 pixels wide (one color per column)
var tilemap = loadTilemap("./assets/hicolor/gradient.tmx")
if(tilemap == nil):
    echo "ERROR"

discard setLayerTilemap(1, tilemap)

discard createWindow("", {SIZE3})
while(processWindow()):
    drawFrame(0)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)