GLBasic forum

Main forum => GLBasic - en => Topic started by: Hark0 on 2010-Nov-25

Title: MEM2SPRITE / SPRITE2MEM: How change any byte on memory?
Post by: Hark0 on 2010-Nov-25
Hi!

I have been read all the topics about change pixels color on sprite... none are valid for me...

I have read procedures like:

1- load sprite
2- sprite2mem
3- change memory values
4- mem2sprite

I are very interested on point 3.

How change value of X memory position?

I have tried points 1 and 2... but if I read value of DIM pixels%[memoryposition] I obtain negative values like "-1234567".

In the manual of MEM2SPRITE shows format like 0xAABBGGRR. And this warning: "READ/DATA might probably not read that large negative numbers."

How access directly to AA / BB / GG / RR?


A clear source code are welcome...  :)

TIA, Hark0
Title: Re: MEM2SPRITE / SPRITE2MEM: How change any byte on memory?
Post by: Kitty Hello on 2010-Nov-25
Code (glbasic) Select

LOCAL r%,g%,b%,a%

LOCAL abgr% = pixels%[x + y*width]
r = bAND(abgr, 0xff)
g = bAND(ASR(abgr,8), 0xff)
b = bAND(ASR(abgr,16), 0xff)
a = bAND(ASR(abgr,24), 0xff)

// write back to array
pixels%[x + y*width] = bOR(RGB(r,g,b), ASR(a, 24) )


Title: Re: MEM2SPRITE / SPRITE2MEM: How change any byte on memory?
Post by: Hark0 on 2010-Nov-25
Thanks for your fast reply!  =D

A little question...

It's possible to obtain memory position of pixels%[]?
Title: Re: MEM2SPRITE / SPRITE2MEM: How change any byte on memory?
Post by: Kitty Hello on 2010-Nov-30
No. It's not just "memory". The pixels are in the memory of the graphics adapter, thus you have to copy them back and forth to work with them. An alternative is to use a pixel shader.
Title: Re: MEM2SPRITE / SPRITE2MEM: How change any byte on memory?
Post by: Hark0 on 2010-Dec-01
Thanks!!!

=D
Title: Re: MEM2SPRITE / SPRITE2MEM: How change any byte on memory?
Post by: Albert on 2011-Feb-12
I'm using: pixels%[x + y*width] = bOR(RGB(r,g,b), ASR(a, 24) )
but I always get fully transparent pixels.
I made this example:
Code (glbasic) Select
LOCAL c%=INTEGER(RGB(10,10,10))
DEBUG c%+"\n" //0xa0a0a0 (OK)
c%=INTEGER(bOR(c%, INTEGER(ASR(10, 24))))
DEBUG c%+"\n" //0xa0a0a0 (???)
c%=0xa0a0a0a0
DEBUG c%+"\n" //0xa0a0a0a0 (OK)

So what am I making wrong?
Title: Re: MEM2SPRITE / SPRITE2MEM: How change any byte on memory?
Post by: Albert on 2011-Feb-12
Now I'm using this code:
Code (glbasic) Select

@FUNCTION encodeABGR%: r%, g%, b%, a%
INLINE
return ((unsigned int)a << 24) | ((unsigned int)b <<16) | ((unsigned int)g << 8) | ((unsigned int)r);
ENDINLINE
ENDFUNCTION
Title: Re: MEM2SPRITE / SPRITE2MEM: How change any byte on memory?
Post by: Kitty Hello on 2011-Feb-15
pixel
Title: Re: MEM2SPRITE / SPRITE2MEM: How change any byte on memory?
Post by: Albert on 2011-Feb-15
oke, I copied that ASR() from the helpfile, and the close parenthesis missing too in help :) But you are right, I want to use ASL() not ASR :)
Title: Re: MEM2SPRITE / SPRITE2MEM: How change any byte on memory?
Post by: Kitty Hello on 2011-Feb-15
a bug in the docs? What command?
Title: Re: MEM2SPRITE / SPRITE2MEM: How change any byte on memory?
Post by: Albert on 2011-Feb-15
SPRITE2MEM()