Suggested feature
I don't think this is currently possible, if it is please let me know as I didn't see how...
With PocketFrog, you can do a scale by specifying a destination rectangle, and the image will be scaled to fit in that area. This is an extremely nice feature because you can know absolutely what the size of the final stretched image will be and adjust for that.
For example, think about the iPaq zoom GD sample... how would you center that on a surface if you didn't want to use the whole surface? Like, if you had a 200x200 area of backbuffer that you wanted tocenter it on, how could you do that? I don't see how it's possible now when you specify a stretch percentage, but with PF you can just keep expanding the corners of the destination rectangle and adjust the coordinate to center it on the 200x200 region as you go.
Am I missing something? If not, I offer that as a suggestion, I think it's a really nice feature to have available (and necassery in some cases perhaps).
It amazed me how you moved from PF to GD and now are requesting all the PF features for GD =)
The irony was not lost on me
But in fairness, I think I only asked for clipping and now this. I wasn't the only one asking for clipping either.
Thierry, I think you were ahead of the game with this feature though

Doesn't Blt( RECT* pDestRect, CGapiSurface* pSrcSurface, RECT* pSrcRect, DWORD dwFlags, GDBLTFX* pGDBltFx); do this for you.
Pejo, the way I understand it, no. I could be wrong, but my experimenting and doc reading seems to indicate that's not how it works.
It looks like that dest rectangle serves as almost a clipping region, i.e., if you scale an image to 500% and indicate a rect of 0,0,100,100, then even though the stretched image would go beyond that rect, it will get "clipped" to that rect.
Johan, am I correct here, or am I missing something?
That was also my understanding. PF stretches the image so that it fits the destination rectangle. GD will use the destination rectangle for clipping, not to determine the destination size for the blit.
I'm not sure this would work, but if GapiDraw itself has the ability to scale in both the x and the y directions, then you should be able to write a simple wrapper function that takes your destination rectangle, calculates the proper scaling, then forwards to GapiDraw to do the work.
Which is to say, if GapiDraw already does this type of scaling, what you really want is simply another API to access that feature. But you could simply provide that API yourself.
(I haven't checked that GapiDraw does the sort of scaling required; I've not yet needed it for my first game.)
I am using Blt to scale to a RECT in my game, and it seems to work.... I am not using clipping though, I have my own clipping routine.
Pejo, could you post some sample code showing this? I tried earlier today and it didn't seem to work that way. I'd be very interested in seeing code that does it. Maybe using the internal clipper has some effect, but that doesn't on the surface make sense to me.
Frank, you could use the get/release buffer functions to directly access the surfaces and write your own routine.
If I have time ill see if I cant bang one up, but basically if you calculate how much bigger the destination rectangle is from the source, then step through the destination rect 1 pixel at a time multiplying the source pixel by the scale factor (source/destination). actually since your doing it uniformly, you can precalculate the scale factor.
heres a little psuedo code since I dont have time to write the function right now:
- Code:
//probably could do this without floats
float fScaleFactor=(iSourceX/iDestinationX);
float fDestX=0,fDestY=0
for (int x=0;x<destinationX;x++)
{
for (int y=0;y<iDestinationY;y++)
{
putpixel[(int)fDestX][(int)fDestY]=getpixel[x][y]
fDestX+=fScaleFactor;
}
fDestX=0;
fDestY+=fScaleFactor;
}
fzammetti I created a modified Minimal app that can be downloaded from
http://memberpages.pejosoftware.com/Copy%20of%20Minimal.zip.
Um..
Is this still an issue Frank?
You can use several combinations in GapiDraw to achieve this effect. The easiest would probably be:
Blt with rotation to the entire destination surface then simply use "rotation center" to adjust the center of rotation on the destination surface. If you want the image to simulate a "PocketFrog" blit you can simply use scalefactor="destrect*100/sourcerect".
The reason the GapiDraw implementation works as is (where the desination rectangle specifies clipping of the rotation and not rotation center/scale) is simply because older versions of GapiDraw did not use clipping.
Please feel free to post here again if this didn't solve your issue.
Sorry all, I was out of town this weekend. I'll take a look at the source provided and see if it does it for me. Johan, I'll post if it's still an issue or not. It sounds like it won't work like PF does (which is what I suspected at the start) but there are a couple of ways to get the same functionality, I just need to see if they'll fit in with what I'm trying to do. Thanks everyone!
Pejo: I just tried your sample finally... All I get is a blank screen. I do notice that you used GD 2.03 for it, I tried it under 2.04. Perhaps a difference in the versions?
Johan: I have to admit I didn't understand your suggestion to try it. If I was getting it at all though, I suspect it won't work for me.
What I'm basically trying to do is this... If you imagine a driving game with trees on the side... as you go down the road, trees in the distance get larger and larger. It's essentially that kind of a thing.
However, they need to not only get larger, but they also need to diverge from a center point, moving outwards towards the edge of the screen (or in my case, a smaller 200x200 area).
To do this in PF, I could simply create a rect of say 0,0,10,10. I could then easily calculate the coordinates to center this rect on the screen, then tell PF to stretch blit to that rect the image of my tree. Because I know before the blit that the final image will be 10x10 and will be a complete version of my image (it'll look horrible of course if it's much larger than that in reality), it's easy to calculate what it's x/y coordinate should be as it moves outward.
Then, I can simply expand my rect to say 0,0,12,12 and then 0,0,14,14 and so on, and move the x coordinate of the blt left or right by the same number of pixels so they will diverge as they expand. Fairly simple.
The only way I can see to do this in GD is to myself calculate the size of the image with each percentage increase and calculate my x/y coordinates based on that. That could be slightly indeterminant though because depending on the percentages I pick, the outcomes may not be integers, and I have to take that into effect. Contrast that with just specifying an absolute rect size, which can easily always be integer, and always even for that matter, to make location calculations that much easier.
Nonw of that shouldn be a terribly big deal to implement in GD, and I'm going to go off and do so now, but that's where I was making a feature suggestion... The PF stretch blt approach makes this trivial and is a pretty powerful thing to have and I think would make a nice addition to GD as well. I don't think it should replace what you already have, but perhaps could supplement it nicely.
Thanks to every for the suggestions!
This thread is making me suspect that I am living in a different reality than the rest of you, This really worries me! Please tell me, is the grass green in the real world too?
Frank, the reason I used 2.03 was that Blt is supposed to be broken in 2.04.
Could someone Please shed some light on this! I can't well sleep at night now that my view of the world as been destroyed!
Frank: I still don't get the issue here..
I downloaded PF to see the differences, and this is how you do it...
PocketFrog Blit Rotated
void BlitRotated( int destX, int destY, float angle, const Surface* source );
GapiDraw Blit Rotated
Just call CGapiSurface::Blt. Use rotationcenter.x = destX, rotationcenter.y=destY, rotationangle=angle. Use destrect=NULL (entire surface).
PocketFrog Blit Stretch
void BlitStretch( const Rect& dest, const Surface* source, const Rect* srcRect = 0 );
GapiDraw Blit Stretch
Just call CGapiSurface::Blt. Use destrect=dest. srcrect=srcRect,
Maybe there were some changes in PocketFrog 0.7, but you can very easily achieve exactly the same result in GapiDraw as you do in PF.
Uff .. Somehow my reply got deleted..
I downloaded PF 0.6 and checked the syntax. Unless something huge has happened in 0.7 you can very easily do exactly the same things in GapiDraw...
PF Blit Rotate
void BlitRotated( int destX, int destY, float angle, const Surface* source );
GapiDraw Blt Rotate
Simply call CGapiSurface::Blt. Set rotationcenter.x = "destX". rotationcenter.y = "destY". set rotationangle = "angle". Set destination rectangle to entire surface. That's basically it...
PF Blit Stretch
void BlitStretch( const Rect& dest, const Surface* source, const Rect* srcRect = 0 );
GapiDraw Blt Stretch
Call CGapiSurface::Blt. Set destination rectangle to "dest". Set source surface to "source". Set source rect to "srcRect". That's basically it...
Frank: What is it that I am missing?
Funny, it never got deleted.. Strange, here's a bug in the forums.. Delete this and the above post and the forum will not display the post at the top of this page...

Johan, I'm only dealing with stretch blt's here, rotation isn't an issue for me...
From what I saw when I tried this a couple of days ago, if I want to stretch an image in GD, I will be setting a percentage. Let's say I have a 50x50 sprite and I stretch it to 200%. That makes it 100s100 in the end. However, if my dest rect is set to 50x50, when it's stretched it gets "clipped" to that rect.
In PF, I don't specify a percentage, I simply pass it the dest rect. It won't get clipped to that rect, it will get STRETCHED TO FIT that rect.
The difference is that with GD, I need to myself calculate what the size of the dest rect will be after the stretch, and set the blt coordinates accordingly. In PF, no calculation is required because I KNOW the size of the final image since it's the size of the rect I specify. It's a more convenient method, in my mind.
Hi Frank,
You do not need to use percentage to stretch an image in GapiDraw. Simply use Blt with no flags, and GapiDraw will stretch the source rectangle into the destination rectangle. It's actually as simple as that..

Then it works as I said! I was starting to think I was crazy! Please dont't do this to me again

.
Frank, it was strange that you could't get my sample working. I only compiled for ARM so if you would like to test it on some other platform you would need to compile it.
PeJo: Unfortunately your sample won't work in 2.04 due to the Blt bug.. It will fail on most PDAs and also in most desktop orientations other than NORMAL.
Very good Johan, then it does work as in PF as well, which is fantastic. That probably should be stated in the docs though (I just looked through, and it doesn't seem to be). From reading the docs, I wouldn't have thought it would work that way, I thought the percentage was my only option.
Sorry about driving you nuts Pejo. The whole problem it seems is that I was trying to run it under 2.04 (because I don't currently have an ARM-based device, and I never run anything in the emulator, and I don't have 2.03 installed, so my only real choice was a quick "upgrade" to 2.04 of your code, which I guess is why it didn't seem to work for me). Thanks for the effort though
