Welcome Guest ( Log In | Register )

[ Big| Medium| Small] -



Post new topic Reply to topic  [ 16 posts ] 
    ZenVirZan
  Sat Sep 01, 2012 8:18 am
very undead
User avatar
Sponsor

Inept Evil Stooge

Location: land of the snags 'n tracky-dacks
I'm developing a map editing application, and all is going well, except for blitting transparent surfaces from scratch to the screen.
If i blit a .png with transparency, it merges them fine - the sprite on the background.
But if I blit a surface (Surface.new([width;height])), it leaves a black box, rather than the transparency.

How to I get the alpha channels to merge correctly from Surfaces made from scratch?

_________________
Image


Top Top
Profile      
 

    Xilef
  Sat Sep 01, 2012 12:14 pm
User avatar
Staff

Big Dumb Guy

Location: UK
You need to use surface to_display_alpha after creating the surface with surface::new


Top Top
Profile      
 

    ZenVirZan
  Sat Sep 01, 2012 2:39 pm
very undead
User avatar
Sponsor

Inept Evil Stooge

Location: land of the snags 'n tracky-dacks
Even when using #to_display_alpha, the issue still persists, with and without the SRCALPHA flag.

_________________
Image


Top Top
Profile      
 

    Xilef
  Sat Sep 01, 2012 2:49 pm
User avatar
Staff

Big Dumb Guy

Location: UK
Want to post some of your code?


Top Top
Profile      
 

    ZenVirZan
  Sat Sep 01, 2012 3:03 pm
very undead
User avatar
Sponsor

Inept Evil Stooge

Location: land of the snags 'n tracky-dacks
This is from a different project, but the issue is the same.
The reason I was sending the text to another surface was to apply an outline - I've removed the outline code for now.
Pretty much:
Expand to see the code.

_________________
Image


Top Top
Profile      
 

    Xilef
  Sat Sep 01, 2012 3:18 pm
User avatar
Staff

Big Dumb Guy

Location: UK
You need to assign a surface to surface.to_display_alpha and blit that, you should be able to write:
surface = surface.to_display_alpha
and it should work, the reason is that it's not a self-modifying function it has a return value of a new surface.


Top Top
Profile      
 

    ZenVirZan
  Sat Sep 01, 2012 3:30 pm
very undead
User avatar
Sponsor

Inept Evil Stooge

Location: land of the snags 'n tracky-dacks
Its merging now, thank you :D
Its a pity they don't make it more noticeable in the documentation - It's such a simple mistake.

_________________
Image


Top Top
Profile      
 

    Xilef
  Sat Sep 01, 2012 3:34 pm
User avatar
Staff

Big Dumb Guy

Location: UK
ZenVirZan wrote:
Its merging now, thank you :D
Its a pity they don't make it more noticeable in the documentation - It's such a simple mistake.

And now this is when I shock you by revealing I've never coded in Ruby before and that I've never used RubyGame before.


Top Top
Profile      
 

    ZenVirZan
  Sat Sep 01, 2012 3:43 pm
very undead
User avatar
Sponsor

Inept Evil Stooge

Location: land of the snags 'n tracky-dacks
Xilef wrote:
ZenVirZan wrote:
Its merging now, thank you :D
Its a pity they don't make it more noticeable in the documentation - It's such a simple mistake.

And now this is when I shock you by revealing I've never coded in Ruby before and that I've never used RubyGame before.


Oh wow. :blank:
I am shocked D:

EDIT: New issue.
3 surfaces.
a = Loaded from png with transparency
b = Scratch (has been converted)
c = Scratch (has been converted)
Blitting surfaces a => screen, b => screen and c => screen works
Blitting surfaces a => b => screen and a => c => screen works
But blitting a => b => c => screen doesnt.
If two surfaces have to_display_alpha set, it doesn't show the PNG image blitted onto it.

_________________
Image


Last edited by ZenVirZan on Sat Sep 01, 2012 4:09 pm, edited 1 time in total.

Top Top
Profile      
 

    ZenVirZan
  Sat Sep 01, 2012 3:43 pm
very undead
User avatar
Sponsor

Inept Evil Stooge

Location: land of the snags 'n tracky-dacks
:snip:
Double posted for some reason

_________________
Image


Top Top
Profile      
 

    Xilef
  Sat Sep 01, 2012 5:01 pm
User avatar
Staff

Big Dumb Guy

Location: UK
ZenVirZan wrote:
3 surfaces.
a = Loaded from png with transparency
b = Scratch (has been converted)
c = Scratch (has been converted)
Blitting surfaces a => screen, b => screen and c => screen works
Blitting surfaces a => b => screen and a => c => screen works
But blitting a => b => c => screen doesnt.
If two surfaces have to_display_alpha set, it doesn't show the PNG image blitted onto it.

Could you tell me the dimensions of these surfaces and the screen you're blitting to?


Top Top
Profile      
 

    ZenVirZan
  Sun Sep 02, 2012 1:52 am
very undead
User avatar
Sponsor

Inept Evil Stooge

Location: land of the snags 'n tracky-dacks
surface 'a' is the tileset png file, alpha included.
surface 'b' is a 32x32 tile, blitted to from the tileset image.
surface 'c' is a 1024x800 layer, and has the surface 'a's blitted to it to make the map. (#to_display_alpha is applied)
'screen' is a 1280x800 Screen instance.

If I put #to_display_alpha on surface b, it doesn't show up.
If I omit it, it does show, but the alpha is replaced with black.

_________________
Image


Top Top
Profile      
 

    Xilef
  Sun Sep 02, 2012 9:50 am
User avatar
Staff

Big Dumb Guy

Location: UK
Why are you using surface B at all? You should use clipping to blit a 32x32 section of A straight to C and do any modifications there to save processing speed.
You can do that with the third blit parameter which is a rectangle, instead of having only the x and y position you can add in the width and height of the blit, using surfaces to clip is very inefficient as you're copying entire blocks of ram to a fresh set of memory twice.

$a.blit($c,[destinationX,destinationY],[tileX,tileY,32,32])


Top Top
Profile      
 

    ZenVirZan
  Sun Sep 02, 2012 10:38 am
very undead
User avatar
Sponsor

Inept Evil Stooge

Location: land of the snags 'n tracky-dacks
I have a grid class, which has a method #get_tile(id)
It returns a 32x32 tile surface from the tileset, depending on the id.
It already uses the source rect function of #blit to get the tile onto surface b to begin with.
Even though b may not be required, i'd still like to know for future reference.

_________________
Image


Top Top
Profile      
 

    Xilef
  Sun Sep 02, 2012 11:14 am
User avatar
Staff

Big Dumb Guy

Location: UK
I don't think I can help any further then, I generally don't blit through more than two surfaces, it's probably a problem with preserving the alpha channel (Perhaps it's being overwritten when blitting from B to C?), it would be a Rubygame specific bug (And from looking at the git page, it's full of them)


Top Top
Profile      
 

    ZenVirZan
  Sun Sep 02, 2012 1:59 pm
very undead
User avatar
Sponsor

Inept Evil Stooge

Location: land of the snags 'n tracky-dacks
I managed to fix it somehow.
I removed the SRCALPHA flag from the loaded tileset .png and it works now.
Thanks for your help, Xilef :)

_________________
Image


Top Top
Profile      
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ] 


Who is online

Users browsing this forum: No users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

We are an independent, not-for-profit game making community.
Homepage
Board Index
About Us
Downloadable Games
Free Browser Games
Games in Development
RPG Maker Support
Game Maker Support
Construct 2 Support
HBGames the eZine
Advanced RPG Maker
Site Announcements
Powered by phpBB © phpBB Group