Weird issue with graphics put [solved]

General FreeBASIC programming questions.
Post Reply
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Weird issue with graphics put [solved]

Post by badidea »

This code makes the image drawn by put toggle on and off on every key press on my system.
This, I did not expect, the screen is not cleared by me inside the loop.
FBC 1.0.5 (32 & 64 bit). Ubuntu Linux (64 bit).
Edit: Same behaviour on Windows 8.1, FBC 1.0.4

Code: Select all

screenres 800, 600

dim pImage as any ptr = imagecreate(200, 200)

circle (200, 200), 100, &h00ff9944,,,,f
get (0,0)-(200-1,200-1), pImage
cls

do
	circle (200, 200), 100, &h00ff9944,,,,f
	put (300, 200), pImage
	locate 2, 2: print "<ESC> to exit. Any other key to test."
loop until getkey = &h1B
Maybe this explains why people here disagree on 'screen flickering issues'?
Last edited by badidea on Jun 08, 2018 22:44, edited 1 time in total.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Weird issue with graphics put

Post by fxm »

Default method for PUT is XOR!
That explains the behavior.

Try with:
put (300, 200), pImage, pset
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Weird issue with graphics put

Post by dodicat »

From the help.
Your put is put (300, 200), pImage,xor
xor is the default.
xor uses the destination buffer, the final colour will be ( 0 xor &h00ff9944) then (&h00ff9944 xor &h00ff9944) (which is 0) then ( 0 xor &h00ff9944) which is &h00ff9944 then (&h00ff9944 xor &h00ff9944) which is zero again ... ...

once again, I did not see fxm's post
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Weird issue with graphics put

Post by badidea »

I just figured it out myself as well.
I guess someone a long time ago decided that xor is a logical default?
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Weird issue with graphics put

Post by fxm »

badidea wrote:I guess someone a long time ago decided that xor is a logical default?
For the following reason (comes from QB): easy animation without clearing the screen.
(a second "Put" at the same location clears the figure)

Code: Select all

ScreenRes 320, 200, 32

Dim img As Any Ptr = ImageCreate( 32, 32, RGB(0, 0, 0) )
Circle img, (16, 16), 15, RGB(255, 255, 0),     ,     , 1, f
Circle img, (10, 10), 3,  RGB(  0,   0, 0),     ,     , 2, f
Circle img, (23, 10), 3,  RGB(  0,   0, 0),     ,     , 2, f
Circle img, (16, 18), 10, RGB(  0,   0, 0), 3.14, 6.28

Locate 11, 13
Print "Easy animation"
Locate 14, 7
Print "without clearing the screen."

Do
  Dim As Integer x = Rnd() * (320 - 32), y = Rnd() * (200 - 32)
  Put (x, y), img
  Sleep 500
  Put (x, y), img
Loop Until Inkey <> ""

ImageDestroy img
Post Reply