PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Surface problem

Hi every1 !
Sorry for my bad english... :) Let's speak in С++ lang :)

i have a problem with creation of a new surface:

1:
Surface * pTexture1 = LoadImage("..."); //first sprite
pTexture1->SetColorMask( Color(0,0,0) ); //setup alpha
//and second sprite:
Surface * pTexture2 = new Surface(100,100);
Rasterizer pRast = Rasterizer(pTexture2);
pRast.Clear(Color(0,0,0));
pRast.Blit( 0, 0, pTexture1 ); // try to copy first image into second
// and now, pTexture2 has no "m_colorMask" from first image... my error?

So... how i can transfer part of image into another inage WITH ALPHA-DATA ?


2: Let's see at Surface.h and Surface.cpp in the PocketFrog (i have v.0.8.1)

// class description:
// Surface.h
class Surface : PHAL::NonCopyable
{
...
private:
...
unsigned m_colorMask; // Source color key
}

//and...
// default constructor of this class:
// Surface.cpp
Surface::Surface( unsigned width, unsigned height )
: m_buffer( PHAL::Surface::Create( width, height ) ),
m_colorMask( -1 ),// is it right? "-1"
m_original( 0 ),
m_hdc( 0 )
{
}


3:
In some part of my engine, i create MANY sprites (something about 3~6 Mb, yeah, i'm crazy, and my Fujitsu (PDA) thinks same... :D ). I have a free memory, but Surface * pSurface = new Surface(512,512) returns pointer with m_buffer=NULL ! Also, sometimes, i can't create sprite with GREAT SIZE (1000x1600). There's a PHAL - limitation? Or it's my errors? I can't use many small sprites instead one big (programm limitation...). Help me plz!

How many mistakes in my english i have? Is it very bad? :)
Hi countryman,

please look in your code, you have:

Code:

pTexture1->SetColorMask( Color(0,0,0) ); //setup alpha
...
pRast.Clear(Color(0,0,0));
pRast.Blit( 0, 0, pTexture1 ); // try to copy first image into second
// and now, pTexture2 has no "m_colorMask" from first image... my error?


Well, you have the same black color for alpha and for back of your pTexture2. So obviously you won't see the difference between pTexture1 and pTexture2 ;)

Try:

Code:

pRast.Clear(Color(255,255,255));
Hi BIGBEN! Spb? :)
so... in my first sprite a have some image(some part of this image has black color, it will be transparent SetColorMask( Color(0,0,0) ). After copy this image to second sprite, i have same image, BUT ! it's has no right value in m_colorMask! In second image a have undefined value (345467676233... something like that), cos in default constructor something wrong ( unsigned m_colorMask = -1 ) and function pRast.Blit( 0, 0, pTexture1 ) does not copy it from first sprite... I try with some colorMask, but it's not work...
I have same problem, when i load 16-bit image (R5G5B5) and try to set colorMask (SetColorMask( Color(...))), after drawing to screen, image has no transparent parts... This problem has gone, when i use 24-bit image...
Lexx31337 wrote:Hi BIGBEN! Spb? :)

SPbSoftwareHouse? no I have my "own company" :D WildGames.NET

As for your question, Blit function should not modify your second surface properties. It just blits (renders) one image to another. To set the masking color for the second surface as for the first:

Code:

//copies pTexture1 masking color to pTexture2
pTexture2->SetColorMask(pTexture1->GetColorMask());


But if you want just to make a "copy" of your image, there is another, better function:

Code:

//Load something to pTexture1 and set masking color
//then
pTexture2 = pTexture1->Clone();
Lexx31337 wrote:
Hi every1 !
Sorry for my bad english... :) Let's speak in С++ lang :)

Don't worry, your English is not bad at all. Better than many native English speakers that I know...

i have a problem with creation of a new surface:

1:
Surface * pTexture1 = LoadImage("..."); //first sprite
pTexture1->SetColorMask( Color(0,0,0) ); //setup alpha
//and second sprite:
Surface * pTexture2 = new Surface(100,100);
Rasterizer pRast = Rasterizer(pTexture2);
pRast.Clear(Color(0,0,0));
pRast.Blit( 0, 0, pTexture1 ); // try to copy first image into second
// and now, pTexture2 has no "m_colorMask" from first image... my error?

So... how i can transfer part of image into another inage WITH ALPHA-DATA ?

I don't think PocketHAL works this way (someone correct me if I'm wrong). When you blit one surface to another, the ColorMask is not copied. In your code above, Texture2 should contain the same image as Texture1 but should NOT have the same ColorMask.

If you want to transfer the ColorMask from Texture1 to Texture2, simply do the following:

Code:

pRast.Blit( 0, 0, pTexture1 ); // try to copy first image into second
pTexture2->SetColorMask (pTexture1->GetColorMask ()); // Copy ColorMask


Now, Texture2 is basically an exact copy of Texture1, including ColorMask.


3:
In some part of my engine, i create MANY sprites (something about 3~6 Mb, yeah, i'm crazy, and my Fujitsu (PDA) thinks same... :D ). I have a free memory, but Surface * pSurface = new Surface(512,512) returns pointer with m_buffer=NULL ! Also, sometimes, i can't create sprite with GREAT SIZE (1000x1600). There's a PHAL - limitation? Or it's my errors? I can't use many small sprites instead one big (programm limitation...). Help me plz!


I've had trouble with large images as well, so it seems to be a PocketHAL limitation. Try breaking the sprite up.