PocketMatrix forums

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

G_Lock

Does setpixel use a different function internally after a call to G_Lock?

The reason I ask is because of my experience with pocketfrog and it's lock function.

With PF, you get a pointer to the buffer so you can do direct access, so what's the point of a G_Lock that doesn't return a pointer?

It also seems like doing a lock on a surface just to plot one pixel (as in simple3.ppl) is a bad thing to do (if it works like the lock in pocketfrog).

The reason is that on devices with a non-native NORTH display orentation, all 320x240 pixels must be rotated before and after the lock. It only makes sense if you are going to be doing a LOT of pixel operations.
Amazing observation. I have so much on my plane that sometimes I cannot think correctly. :lol:

I will make sure the g_lock returns a pointer too.

Regards,
Kornalius
You'll need to return a pointer to the pixel data as well as the pitch...

struct LockInfo
{
int pitch;
Pixel* pixels;
};


Pitch is the byte offset between rows of pixels, which may or may not be 2xwidth (in case you haven't seen the PF post about this).

You should also remove the G_Lock statement from the sample program to keep someone from thinking it should be used that way. If you get the lock implemented in 0.5, I can probably write a demo that uses it.
I removed the g_lock from the Simple3.ppl demo. G_Lock() now returns a pointer to the struct.

If you get the lock implemented in 0.5, I can probably write a demo that uses it.


That would be awesome. :D

Regards,
Kornalius
I tried using G_lock in version 0.5.

I compiles, but I don't see anything on screen.

I've tried using this:

Code:

struct(lockinf$, LockInfo);
lockinf$ = G_Lock();

&lockinf.pixels$ = G_RGB(255,255,255);

G_Unlock;



I'll admit, I'm a little confused by the pointers and referencing. In C, what I want to write is:
*(lockinf.pixel + y*lockinf.pitch + x) = Color(a,b,c);
where it is addressed as an int16.

I tried using variations with the ^, but it doesn't compile.

How do you do this?

Thanks,
Jason
Hi,

You will have to use the peek and poke functions. The ^ is only used to return a string to the stack from an address. So, not usefull in this case.

This should work:

Code:
struct(lockinf$, LockInfo);
lockinf$ = G_Lock();

poke((lockinf.pixels$ + y) * (lockinf.pixels$ + x), G_RGB(255,255,255), tint);

G_Unlock;


I am just not sure about the size though. Is it 4 bytes per pixel? I support tbyte, tshort, tint and tdouble as defaults. Any other size should work also.

Btw, wait for version 0.5a before you try this out. I made a little fix to the poke() function. It should be out anytime now.
Regards,
Kornalius
A pixel is a 16 bit... so 'short' should work.

I tried using poke, and the program just exits when it attempts the poke. No errors and such. I tried running in debug mode, and the IDE doesn't act like it's really in debug mode and reports nothing as well.

I assume, you would have to use 2*x and 2*y for it to account for the pixel being 16 bits, although, I'm just trying to get the 0th pixel to change - so that addressing is irrelavent at this point.

If it DID work, would you have to worry about byte alignment? Just curious.

Here's the code:
Code:

if (KeysPressed$[keys.vkUp$])
struct(lockinf$, LockInfo );
lockinf$ = G_Lock();

poke(lockinf.pixels$, 0, 1);

G_Unlock;

end;
Are you using 0.5a?

If so I will give it a shot tomorrow for sure.

Regards,
Kornalius
yes, 0.5a.
Hi,

I fixed the struct pointer assignment in 0.5b. However you will have to make sure you are aligning your address locations for pixels.

Btw, 0.5b should be out tomorrow.

Regards,
Kornalius