PocketMatrix forums

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

How do I make a surface manually

I have PocketGL working inside PF.
Currently I copy PocketGLs buffer to PocketFrog's buffer for blitting but I realised (once I heard that another PGL user had pointed PGL to using GapiDraw's back buffer) that I should be doing something similar in PocketFrog to save on a big copy every frame.

The PGL data is created as follows:-
header file has
extern unsigned short VScreen[DISP_X*DISP_Y]
and the PGL cpp has
unsigned short VScreen[DISP_X*DISP_Y]

and what I want to do is get that data blitted without having to lock, copy, blit, unlock in PF as this takes too long

Having spent a couple of hours messing with my code ( & thank goodness I made a backup first ) I still don't see how to get this to happen.
I thought I could get PGL to simply look at PFs back buffer in some way or get PF to treat PGLs data as a surface so it could be blitted but my C++ is letting me down

Does anyone have any suggestions on how to approach this?

thanks in advance
Keep in mind that I'm just thinking out loud without thinking terribly hard about it, or researching in the slightest, so this may be worth less than the electrons used to render it on your screen...

I don't think there's any way, give PF's public interface, that you will be able to do anything but the lock/copy/unlock cycle you are already doing.

I think a minor PF hack might do the trick though, and I *THINK* this may work...

If you modify display.h and make m_backSurface public instead of private, I believe that will give you access to the pointer to the back buffer, and you can then hand that off to PGL to render to. I think that's all that would be required. You will still need to do a lock/unlock at some point to get the pitch to work with, assuming PGL doesn't handle that for you, but that should only have to be done once.

Let me know if that works out. If so, I might be inclined to make that change for the next PF revision as it seems like something that might give everyone more flexibility without breaking anything.
Thanks, I will think about this approach.
ps: I now have the GD source for PocketGL to try out. 'Unfortunately' it looks like my 3D performance will be much better under GD ( by over 10 FPS at least ) so when Space Treker III is finished I need to either get just as good results with PF or consider a move to GD. Hopefully by that time others will have taken the pain & found all the differences. I really don't relish another learning curve but at the end of the day I can't ignore the speed benefit.
As someone that is now moving to GD for my current project, I have to say that the learning curve is really virtually non-existent. I think it took me about two hours to get to a point of proficiency that I can begin working on my project. The biggest thing that got me was the lack of clipping. We take it for granted because PF is so nice and does it for us. I couldn't find code to do it that (a) worked and (b) allowed me all the functionality that PF does. The code in PF I didn't see as being easily transplanted, so I wound up rolling my own, which took about an hour to actually get right. It's now posted in the GD forum, so it will save you some time if you go that route. But overall, going to GD from PF isn't difficult at all, I think you'll find that you'll be in the swing of things definitely in under a day.

In fact, I'm considering converting Invasion: Trivia to GD. I've kind of backed off of it from a few days ago, I was really into it then, but that's only because I've started on my new project a little faster than I expected. In the end though, I don't think it would have taken more than 2-3 days, a few hours each day, to get it converted.
Conan · 17 Jun 2003, 16:59 UTC — clipping, learning curve etc
If you really mean it about only 2-3 days to convert then I might bite the bullet assuming the 3D performance is as good as I'm told.

Out of interest is there a complete list of available functions in the GD docs & are there any obvious missing functions which would be likely to cause me pain ( I'm thinking of set clipping rectangle, does your code do that? )
Yes, That estimate I think is fair, give or take a day. For the most part it's just a question of changing method calls and some data types here and there, and of course the basic methods that get called (i.e., ProcessNextFrame instead of GameLoop, InitInstance instead of GameInit, etc). The only concern I have is that the way I coded I:T, most of the methods are not members of the base class (don't ask why, I'm embarassed about the reason!). This I think might cause me some headaches, but I can't blame GD for that, can I?!? :)

As for docs, www.gapidraw.com has all the docs online. You can simply click on a class to see the methods it supports. I find that sometimes I can't find what I'm looking for quickly, but that's just a familiarization issue. Generally everything is about where you would expect.

As for missing functions, that depends on what your using out of PF. PF has more in the way of primitive drawing tools, but if you aren't using them at all or not a great deal it's no problem, the blit functionality of GD is superior in most respects and the method signatures look pretty comperable (different, but easily converted). No clipping is a bit of a pain, but grab the function I posted on the GD forum and you shouldn't have to think twice about it.
ok, when time allows I will have a look however I use the line hline vline & circle functions so if GD does not already have them I will need to port.

With the reference to a possible PF2 coming along there is the possibility of not needing to change of course.
Yes, that's a very intriguing post by Thierry! Of course, any effort I put into PF seems a little wasted now, but that's the price of progress I suppose. I can't wait to see the fruits of his labor. Seeing his post in the general forum about exporting ROM DLL's gives some clues where he's going I think, it's very interesting.

I just took a look... there is a DrawLine method in GD, and it is optimized for V&H; lines as one would expect. There is no circle method though, but that's of course not terribly difficult to implement yourself. I'm compiling a little GD_Extensions header that will include circle drawing. If you go the GD route, feel free to ask for it, it's all yours.

The only thing that makes these more difficult, as with everything in GD, is the lack of clipping. You'll have to manually clip your lines as well as your circles. In a way it'd be easier for the circles since your writing the algorithm yourself and can just reject out-of-bounds pixels. For the lines, you'll have to do a line clipping algorithm on them first. Nothing spectacularly difficult, but more so than PF.
fzammetti wrote:
Of course, any effort I put into PF seems a little wasted now, but that's the price of progress I suppose.


Your efforts are much appreciated Frank and I would be afraid of seeing you stop. I don't have the time to work on high-level stuff such as font support, rounding out the feature set and so on. Anything that you add to PocketFrog will simply improve it's value and won't go to waste.