GLBasic forum

Main forum => GLBasic - en => Topic started by: dbots on 2013-Mar-26

Title: Drawrect of image on existing image or something similar ?
Post by: dbots on 2013-Mar-26
Hi guys, here is my problem that I need some help :
I have a clear black image let's say 100x100 pixels and also I have a set of many 10x10 small images as separate ones.
What I want is to be able to select any of the small images, and draw it on the large image and after having prepared that large image accordingly (let's say like a puzzle of small images every time) then use that large image to display it on my program.
I want to be able to change that large image over and over during the program is executed, for example be able to replace a specific area of it that has already been filled previously, with another small image, over and over again.
I have been working with Delphi and DelphiX in the past and did that with DrawRect, is there something similar here ?
Thank you very much
Title: Re: Drawrect of image on existing image or something similar ?
Post by: Ian Price on 2013-Mar-27
Use virtual screens - make the target big image the virtual screen (CREATESCREEN number,spritenumber,sizex,sizey) then use SETSCREEN number,  to draw your smaller sprites to it, then move back to the physical screen with SETSCREEN -1 and then use DRAWSPRITE spritenumber,x,y.

Here's an example using rectangles

Code (glbasic) Select

CREATESCREEN 1,999,320,240

USESCREEN 1


FOR n=0 TO 1000
DRAWRECT RND(320),RND(240),RND(32),RND(32),RGB(RND(255),RND(255),RND(255))
NEXT

USESCREEN -1

DRAWSPRITE 999,100,100

SHOWSCREEN

KEYWAIT


Obviously in your case you'd need to make a loop so that you keep drawing to the virtual screen -

Like so -

Code (glbasic) Select
CREATESCREEN 1,999,320,240

WHILE TRUE

USESCREEN 1

FOR n=0 TO 1000
DRAWRECT RND(320),RND(240),RND(32),RND(32),RGB(RND(255),RND(255),RND(255))
NEXT

USESCREEN -1

DRAWSPRITE 999,100,100

SHOWSCREEN

WEND
Title: Re: Drawrect of image on existing image or something similar ?
Post by: CW on 2013-Mar-27
Wow. I had always wondered about the virtual screens. The manual is a bit cryptic. You should move this example over to the Tutorial section. Very helpful!
-CW
Title: Re: Drawrect of image on existing image or something similar ?
Post by: matchy on 2013-Mar-27
In this case, as they are only small images (less that the screen size in total and virtual screens are not needed [at least for WIN32]), DRAWSPRITE all small into large area, GRABSPRITE the large area and DRAWSPRITE the large sprite in loop.
Title: Re: Drawrect of image on existing image or something similar ?
Post by: Ian Price on 2013-Mar-27
As inferred by Matchy, GRABSPRITE doesn't work on all devices and can be very slow on mobile/handheld devices. If it's Windows, then you can safely use that method.

Really though, you could just draw all the small sprites at the required positions without worrying about any other commands.
Title: Re: Drawrect of image on existing image or something similar ?
Post by: spacefractal on 2013-Mar-27
DRAWRECT suffer on some Android systems, as well the alternative POLYVECTORS with single color can suffer on some iOS systems. Property Gernot should check if its Android, then its should draw with POLYVECTORS internal, or if its not Android, then DRAWRECT should been used.

Otherwice its could of course been af function to doing that :-D.

And yes you could just draw all small sprites without using offbuffers, eventuelly split the image up, and draw them using DRAWANIM's commands.
Title: Re: Drawrect of image on existing image or something similar ?
Post by: matchy on 2013-Mar-27
Let's not confuse dbots now with platforms as I would presume the learning platform and device is primary WIN32 DESKTOP.   :-[Now when I produce for Android, I would simulate the environment and save those original rendered images from the WIN32 version and load those on the TOUCHSCREEN device.  :good: This only works if the images (textures/sprites) are not required to be generated in run-time which is the point to highlight.

Actually, the safest cross-platofrm way to stitch bitmaps would probably be with the SPRITE2MEM command with all manipulation done off dependent screens.
Title: Re: Drawrect of image on existing image or something similar ?
Post by: Ian Price on 2013-Mar-27
I wouldn't assume that dbots ONLY wants to develop for Windows platforms and it's best to be aware of a potential problem BEFORE you encounter it.
Title: Re: Drawrect of image on existing image or something similar ?
Post by: kanonet on 2013-Mar-27
Spacefractal Gernot does not need to include this switch, you can just use ?IFDEF to include it for yourself.
Title: Re: Drawrect of image on existing image or something similar ?
Post by: erico on 2013-Mar-28
Thanks for the usescreen tutorial/example Ian, it is handy. :good:
Title: Re: Drawrect of image on existing image or something similar ?
Post by: dbots on 2013-Mar-29
Hi guys,
the reason I wrote the question was while being developing on Android platform. I am not interested on Windows right now since I use other tools for that. Anyway, I will post my results and opinion when I will implement that solution on my code.
Thanks.
Title: Re: Drawrect of image on existing image or something similar ?
Post by: spacefractal on 2013-Mar-29
Then you can't use DRAWRECT at all, which don't works well on android. Use polyvectors via function instead.
Title: Re: Drawrect of image on existing image or something similar ?
Post by: Ian Price on 2013-Mar-29
Quotethe reason I wrote the question was while being developing on Android platform. I am not interested on Windows right now
matchy, take note ;) :P

As for DRAWRECT on Android, in my code just replace the DRAWRECT commands with sprites instead. I only used DRAWRECTs as it demonstrated the principal in a small piece of standalone code without the need for any media.
Title: Re: Drawrect of image on existing image or something similar ?
Post by: dbots on 2013-Mar-29
@ Ian : Thanks, but what does "just replace the DRAWRECT commands with sprites instead" mean ?
Title: Re: Drawrect of image on existing image or something similar ?
Post by: spacefractal on 2013-Mar-29
using a single colored texture and then draw its with a sprite or polyvector. polyvectors is also fine on Android as well. Im done something in Greedy Mouse, due DRAW_RECT diddent works as intended on Android.

Here you could do a function for that to use DRAW_RECT on devices other than Android, elsewise uses polyvectors (or sprites).
Title: Re: Drawrect of image on existing image or something similar ?
Post by: Ian Price on 2013-Mar-29
It means use sprite commands instead (DRAWSPRITE, DRAWANIM etc.) of primitive drawing (DRAWRECT, DRAWLINE).
Title: Re: Drawrect of image on existing image or something similar ?
Post by: dbots on 2013-Mar-29
Quote from: Ian Price on 2013-Mar-29
It means use sprite commands instead (DRAWSPRITE, DRAWANIM etc.) of primitive drawing (DRAWRECT, DRAWLINE).
Now, that makes more sense to the whole set of answers. Thanks
Title: Re: Drawrect of image on existing image or something similar ?
Post by: matchy on 2013-Mar-30
Quote from: Ian Price on 2013-Mar-29
Quotethe reason I wrote the question was while being developing on Android platform. I am not interested on Windows right now
matchy, take note ;) :P

The reason I replied and modified my intent is because I, well...nevermind.
Title: Re: Drawrect of image on existing image or something similar ?
Post by: dbots on 2013-Apr-01
Quote from: matchy on 2013-Mar-30
Quote from: Ian Price on 2013-Mar-29
Quotethe reason I wrote the question was while being developing on Android platform. I am not interested on Windows right now
matchy, take note ;) :P
The reason I replied and modified my intent is because I, well...nevermind.
Huh ? Did I modified my intent ? I suppose you know better than me, right ?