[solved] GET and PUT ( graphics ) commands slow down my program[solved]

New to FreeBASIC? Post your questions here.
Daniel Ouellette
Posts: 96
Joined: Apr 17, 2011 17:43
Location: Montréal, Canada
Contact:

[solved] GET and PUT ( graphics ) commands slow down my program[solved]

Post by Daniel Ouellette »

Hi everyone, I'm not very good in Freebasic and I could use some help. I only use basic commands, and the execution speed has decreased a lot since I introduced the GET and PUT (graphics) functions in my program. The operation screen is 1024 X 768, and in full screen there is no speed problem, but the image is very stretched when the PC screen is big. Sorry for my terms, I'm a beginner and French. Instead of full screen, I use GET and PUT to center the 1024 x 768 image in the middle of the PC screen, so the rest is grey. The problem is that it slows down the execution a lot. Is there a better practice?
Last edited by Daniel Ouellette on Aug 10, 2020 19:53, edited 1 time in total.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: GET and PUT ( graphics ) commands slow down my program

Post by grindstone »

A code says more than thousand words ;-)

Maybe you can post the relevant part of the code so we can see if there's some room for improvement.
Daniel Ouellette
Posts: 96
Joined: Apr 17, 2011 17:43
Location: Montréal, Canada
Contact:

Re: GET and PUT ( graphics ) commands slow down my program

Post by Daniel Ouellette »

Thank you, it's actually a very heavy program, so it's very slow, since I'm not an expert. Here's the little I can give you concerning only the graphic, it's embarrassing, but here it is:

ScreenInfo w,h,depth

ScreenRes w,h,16,2,GFX_NO_FRAME

ScreenSet 1,0

Get (1,1)-(1023,767),img5
Cls: Put ((w-1024)/2,(h-768)/2), img5, Pset
Flip 1,0
Daniel Ouellette
Posts: 96
Joined: Apr 17, 2011 17:43
Location: Montréal, Canada
Contact:

Re: GET and PUT ( graphics ) commands slow down my program

Post by Daniel Ouellette »

I add, to seem less stupid, that my specialty is the assembler language of microcontrollers and not PCs. I have no knowledge of the C language and I don't know the PC assembler language. In full screen, the program runs in 10mS, but with the GET command, it's 10mS more (sometimes a little less) and I think it's a lot. By decreasing the color to 8 bits, I get back the 10 mS execution time, but I need 16 bits.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: GET and PUT ( graphics ) commands slow down my program

Post by grindstone »

As a first approach I would recommend to set the colour depth of your graphics card to 16 bit, so the colour doesn't have to be recalculated for each pixel.
Daniel Ouellette
Posts: 96
Joined: Apr 17, 2011 17:43
Location: Montréal, Canada
Contact:

Re: GET and PUT ( graphics ) commands slow down my program

Post by Daniel Ouellette »

Thank you, as you recommended, I set the color depth of your graphics card to 16 bits and the execution is a few mS faster. I imagine that this GET command is very laborious, relying on its execution time, to create an image.
Daniel Ouellette
Posts: 96
Joined: Apr 17, 2011 17:43
Location: Montréal, Canada
Contact:

Re: GET and PUT ( graphics ) commands slow down my program

Post by Daniel Ouellette »

More, the depth of my graphics card, sorry, I use a translator.
Daniel Ouellette
Posts: 96
Joined: Apr 17, 2011 17:43
Location: Montréal, Canada
Contact:

Re: GET and PUT ( graphics ) commands slow down my program

Post by Daniel Ouellette »

By switching to fullscreen mode, is it possible to ensure that the image is not stretched? This is a beginner's question, but I wonder what the usual methods are.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: GET and PUT ( graphics ) commands slow down my program

Post by grindstone »

The graphics routines of FB are optimized for the usual color depth of 32 bits. I assume that under the hood they always work with 32 bits, regardless of the chosen depth.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: GET and PUT ( graphics ) commands slow down my program

Post by grindstone »

Daniel Ouellette wrote:By switching to fullscreen mode, is it possible to ensure that the image is not stretched? This is a beginner's question, but I wonder what the usual methods are.
The simplest way to prevent an optical distortion is to add some vertical respectively horizontal stripes so the size of the picture matches the size of the screen (or at least the ratio).
Daniel Ouellette
Posts: 96
Joined: Apr 17, 2011 17:43
Location: Montréal, Canada
Contact:

Re: GET and PUT ( graphics ) commands slow down my program

Post by Daniel Ouellette »

Thanks, I don't know if I did it right, but I also tried my program by changing the depth to 32 bits and the speed stayed the same. I'm wondering how they keep the images in video games in proportion regardless of the screen resolution, unless I'm wrong.
Daniel Ouellette
Posts: 96
Joined: Apr 17, 2011 17:43
Location: Montréal, Canada
Contact:

Re: GET and PUT ( graphics ) commands slow down my program

Post by Daniel Ouellette »

grindstone wrote:The simplest way to prevent an optical distortion is to add some vertical respectively horizontal stripes so the size of the picture matches the size of the screen (or at least the ratio).
That's what I've been trying to do and I don't know how it's usually done.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: GET and PUT ( graphics ) commands slow down my program

Post by grindstone »

Daniel Ouellette wrote:I'm wondering how they keep the images in video games in proportion regardless of the screen resolution, unless I'm wrong.
Modern grapics cards are equipped with a great number of GPUs, spezialized processors for graphic computation. I doubt that there is a way to access those GPUs by FB (correct me anyone if I'm wrong).
Daniel Ouellette
Posts: 96
Joined: Apr 17, 2011 17:43
Location: Montréal, Canada
Contact:

Re: GET and PUT ( graphics ) commands slow down my program

Post by Daniel Ouellette »

Personally, I don't know enough about it...
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: GET and PUT ( graphics ) commands slow down my program

Post by BasicCoder2 »

grindstone wrote:
Daniel Ouellette wrote:I'm wondering how they keep the images in video games in proportion regardless of the screen resolution, unless I'm wrong.
Modern graphics cards are equipped with a great number of GPUs, spezialized processors for graphic computation. I doubt that there is a way to access those GPUs by FB (correct me anyone if I'm wrong).
There is no direct access to hardware that existed on the older computers like the c64, Amiga and MDDOS machines. Today the hardware has an overlay of driver software to access that secret proprietary hardware. On top of that is software to provide a consistent way to use the hardware such as provided by DirectX and so on... Not really sure of the details.

PUT and GET probably use the hardware BLITTER functions to move whole sections of data. I don't know if that can be matched using inline assembler to move pixels data stored in bitmap structures. You can speed up pixel manipulations in FB using pointers or inline assembler.

I never use the GET statement. I don't know how fast it is. Your code example is simply too terse and incomplete to mean much as an example. Using less than the 32 bits may even slow it down as the cpu would move 32 or 64 bits at a time?
'example using put statement

Code: Select all

dim shared as any ptr img5
img5 = imagecreate(SCRW,SCRH)

'fill image with stuff
dim as integer x,y,r
for i as integer = 0 to 50
    x = int(rnd(1)*SCRW)
    y = int(rnd(1)*SCRH)
    r = int(rnd(1)*50)+20
    circle img5,(x,y),r,rgb( int(Rnd(1)*256), int(rnd(1)*256), int(rnd(1)*256)),,,,f
next i
cls
put (0,0),img5,trans
sleep
    
screenlock
    cls
    put (SCRW\4,SCRH\4),img5,(0,0)-( (SCRW-1)\2, (SCRH-1)\2),trans
screenunlock

sleep
Post Reply