Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Extending Gosu / TexPlay Bug
- - By lol_o2 Date 2012-12-02 13:19
I mentioned it before, but now I found a 100% way to reproduce it. I made a method that loads tiles with different palettes. It correctly loads 1-3 tilesets and next images appear blank. It's interesting that loading single images doesn't cause the bug. The code looks like this (it's a part of method that loads tiles):

array = Image.load_tiles($screen, "data#{dir}/#{name}.png", width, height, tileable)
if palette
   pal=Img["Palettes/#{palette}"]  ##loads image for palette
   array.each{|img|
      pal.width.times{|x| img.clear(:dest_select=>pal.get_pixel(x,0),:color=>pal.get_pixel(x,1),:tolerance=>0.001)}
   }
end
@@tiles[[name.downcase,size,palette]]=array


And the demo where it appears: http://www.fileden.com/files/2008/1/21/1712119/Texplay%20Bug.zip
So, is there a way to fix it?
Parent - - By Spooner Date 2012-12-02 23:17
Something to try might be img.refresh_cache after you've cleared it. Just a guess, but sometimes that forces updates which otherwise might not get synced properly. Beyond that, I haven't a clue.
Parent - By lol_o2 Date 2012-12-03 14:58
Thanks!
But I haven't solved it completely. Strangely, first image of each tileset (after 1-2 loads) is missing.
- - By lol_o2 Date 2012-12-10 18:11
I've just came up with idea to use Ashton for it. I have to ask if there's a possibility to load image by shader and use it's color data?
Parent - - By Spooner Date 2012-12-10 18:30
Not sure what you mean, since I'm not really sure what the code is supposed to do (and I'm less than keen to write shaders for everyone, rather than help them write their own). I've no doubt that everything TexPlay can do could be done with Ashton::Shader (and significantly faster) but it involves a great deal more work actually writing the appropriate shaders.
Parent - - By lol_o2 Date 2012-12-10 18:52
So to explain it:
I have a palette file (just png). It has any width and 2 pixel height. When I recolor image, I iterate each upper pixel of palette and replace pixels with this color in my image by adjacent color from lower row of palette. So, the upper row of 2-pixel-height palette image is source colors and lower is destination colors. I was asking if Ashton can load these colors into shader to use them.

In TexPlay it works correctly only for single images. When changing whole array (image.load_tiles), it vanishes some of tiles.
Parent - - By Spooner Date 2012-12-10 20:30
Yes, you could just use multitexturing and you can read from two textures at once or else keep it simple and read the pixels in individually and pass those colours into the shader as variables.

I still think there is a possibility that liberal overuse of refresh_cache might help (that is, before AND after every operation on an image - if it fixes it, then remove them one by one until you have the optimal code. I could never be 100% about when I should be manipulating the cache, even though I wrote a similar caching code in Ashton, but that is intentionally automatic, lazy and one-way, so it was simpler - there is no need to sync images back onto the graphics card, since shaders are better for manipulating graphics than pulling it onto the main memory, manipulating and sending back to the card, as Texplay does it).
Parent - By lol_o2 Date 2012-12-11 15:49
FINALLY IT WORKS (at least until it magically breaks again)
Thanks for suggestion, I made cache refreshing before manipulation and nothing seems to be missing.
Up Topic Gosu / Extending Gosu / TexPlay Bug

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill