Author Topic: Isometric Mapping Demo  (Read 9015 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Isometric Mapping Demo
« Reply #30 on: December 16, 2019, 02:32:53 pm »
Hi Steve,

Reading about _DONTBLEND in help, it says that such will make the background opaque and block the background. When I use transparent colors with fTri, I usually want just a layer of see through color over what's behind. It's looking like I want to stick with original fTri that frees image to keep pure transparent layers going.

Update: confirmed the transparency is lost with _DONTBLEND

Thanks for your thoughts :)

I'm lost as to what the heck is wrong with _DONTBLEND; it appears to work as it should for me:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. PSET (0, 0), &HAAFFFFFF

How is the transparency lost?  When _dontblend is used, all we do is set the color to exactly what we specify it to be. 

As for the wiki, I have no idea what the heck this is supposed to mean:

Quote
Use CLS or _DONTBLEND to make a new surface background _ALPHA 255 or opaque.

_DONTBLEND doesn't change the alpha levels.  Unless my experience using it is just overly weird, all it does for us is directly put our specified colors to the image, without trying to blend the alpha levels and such like normal. 

Is there some secret trick to this command that I've been missing all these years??
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Isometric Mapping Demo
« Reply #31 on: December 16, 2019, 03:08:20 pm »
Hi Steve,

Here is my test code for the _DONTBLEND. First run it to see the shade of transparent used with fTri that uses _FREEIMAGE. Then run main code with fQuad1 that runs fTri with the _DONTBLEND, you can see it is full opaque blue and so much lighter because solid.
Code: QB64: [Select]
  1. _TITLE "fTri Tests, click 4 points to draw transparent quad" 'b+ 2019-12-15 discovered a problem with fTri or using it with fQuad
  2.  
  3. CONST xmax = 800, ymax = 600
  4. SCREEN _NEWIMAGE(xmax, ymax, 32)
  5. _SCREENMOVE 300, 40
  6. DIM pi, oldMouse
  7. DIM mx(1 TO 4), my(1 TO 4)
  8.     CLS
  9.     oldMouse = -1
  10.     WHILE pi < 4 'get 4 mouse clicks
  11.         _PRINTSTRING (5, 5), SPACE$(20)
  12.         _PRINTSTRING (5, 5), "Need 4 clicks, have" + STR$(pi)
  13.         WHILE _MOUSEINPUT: WEND
  14.         IF _MOUSEBUTTON(1) AND oldMouse = 0 THEN 'new mouse down
  15.             pi = pi + 1
  16.             mx(pi) = _MOUSEX: my(pi) = _MOUSEY
  17.             CIRCLE (mx(pi), my(pi)), 2
  18.         END IF
  19.         oldMouse = _MOUSEBUTTON(1)
  20.         _DISPLAY
  21.         _LIMIT 60
  22.     WEND
  23.     _PRINTSTRING (5, 5), "Sleeping, click or press key... or esc"
  24.     'fquad1 mx(1), my(1), mx(2), my(2), mx(3), my(3), mx(4), my(4), &H880000FF '>>>>>>>>>>>>>>>>>>> switch between fquad and fquad1
  25.     fquad mx(1), my(1), mx(2), my(2), mx(3), my(3), mx(4), my(4), &H880000FF '>>>>>>>>>>>>>>>>>>> switch between fquad and fquad1
  26.     _DISPLAY
  27.     cSleep 45 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< dang!! this is working either fixed 2019-12-16 2nd time oldMouse = -1 at start
  28.     'Pause 30 ' <<<<<<<<<<<<<<<<<<<< well this isn't working either!!!!!!!!!!!!!! now fixed (2x's, Steves fix was better)
  29.     'SLEEP
  30.     pi = 0 'point index
  31.  
  32.  
  33. ' my original fTri that never had a problem with
  34. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  35. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  36.     DIM D AS LONG, a&
  37.     D = _DEST
  38.     a& = _NEWIMAGE(1, 1, 32)
  39.     _DEST a&
  40.     PSET (0, 0), K
  41.     _DEST D
  42.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  43.     _FREEIMAGE a& '<<< this is important!
  44.  
  45. '2019-11-20 Steve saves some time with STATIC and saves and restores last dest
  46. SUB ftri1 (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  47.     DIM D AS LONG
  48.     STATIC a&
  49.     D = _DEST
  50.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32): _DONTBLEND a& '<< fix ??
  51.     _DEST a&
  52.     PSET (0, 0), K
  53.     _DEST D
  54.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  55.  
  56. ' original fill quad that may be at fault using Steve's fTri version
  57. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is opposite of x4, y4
  58. SUB fquad1 (x1, y1, x2, y2, x3, y3, x4, y4, K AS _UNSIGNED LONG)
  59.     ftri1 x1, y1, x2, y2, x4, y4, K
  60.     ftri1 x3, y3, x2, y2, x4, y4, K
  61.  
  62. 'update 2019-12-16 needs orig fTri
  63. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is opposite of x4, y4
  64. SUB fquad (x1, y1, x2, y2, x3, y3, x4, y4, K AS _UNSIGNED LONG)
  65.     ftri x1, y1, x2, y2, x3, y3, K
  66.     ftri x3, y3, x4, y4, x1, y1, K
  67.  
  68. 'update 2019-12-16 in ...test\graphics\fTri tests.bas
  69. SUB cSleep (secsWait AS DOUBLE) 'wait for keypress or mouseclick, solves midnight problem nicely I think
  70.     DIM wayt AS INTEGER, oldMouse AS INTEGER, k AS LONG, startTime AS DOUBLE
  71.  
  72.     oldMouse = -1 '2019-12-16 2nd fix today assume an old mouse click is still active
  73.     startTime = TIMER
  74.     wayt = 1
  75.     _KEYCLEAR
  76.     WHILE wayt
  77.         WHILE _MOUSEINPUT: WEND
  78.         IF _MOUSEBUTTON(1) AND oldMouse = 0 THEN wayt = 0
  79.         oldMouse = _MOUSEBUTTON(1) ' <<< this is Steve's cool way to get clear of mouse click
  80.         k = _KEYHIT: IF k > 0 THEN _KEYCLEAR: wayt = 0
  81.         IF TIMER - startTime < 0 THEN 'past midnight
  82.             IF TIMER + 24 * 60 * 60 - startTime > secsWait THEN wayt = 0
  83.         ELSE
  84.             IF TIMER - startTime >= secsWait THEN wayt = 0
  85.         END IF
  86.         _LIMIT 30
  87.     WEND
  88.  
  89. 'try Steve's Pause, nope doesn't work either!!!!
  90. SUB Pause (time AS _FLOAT)
  91.     DIM ExitTime AS _FLOAT, oldMouse AS INTEGER, k AS LONG
  92.  
  93.     _KEYCLEAR 'clear the keyboard buffer so we don't automatically exit the routine
  94.     'WHILE _MOUSEINPUT OR _MOUSEBUTTON(1): WEND 'clear mouse too
  95.     oldMouse = -1 'in case a mouse down still active
  96.     IF time <= 0 THEN ExitTime = 1.18E+1000 ELSE ExitTime = time + TIMER
  97.     DO
  98.         WHILE _MOUSEINPUT: WEND: IF _MOUSEBUTTON(1) AND NOT oldMouse THEN EXIT SUB
  99.         k = _KEYHIT: IF k > 0 THEN _KEYCLEAR: EXIT SUB 'clear any stray key events so they don't mess with code outside the Pause.
  100.         oldMouse = _MOUSEBUTTON(1)
  101.         _LIMIT 10
  102.     LOOP UNTIL ExitTime < TIMER
  103.  
  104.  
« Last Edit: December 16, 2019, 03:33:56 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Isometric Mapping Demo
« Reply #32 on: December 16, 2019, 03:09:04 pm »
Doing some testing at the computer, I sorted out what was wrong with what I told you:

Code: [Select]
SUB ftri1 (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
    DIM D AS LONG
    STATIC a&
    D = _DEST
    IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
    _DEST a&
    _DONTBLEND a& 'set the image to not blend, so your new color will set itself without blending
    PSET (0, 0), K
    _BLEND a& 'but then turn blending on for the image, so when you use _MAPTRIANGLE, it'll blend into the other screen as desired.
    _DEST D
    _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
END SUB

See if the above doesn't work as intended.  ;)

We can't leave blending off with an image, if we want to blend it with another image.  (Which is kind of oddish.  I would think that all we'd care about is the _DEST blending state, not the _SOURCE's as well...)

Have blending off when setting your pixel, then turn it back on before making use of the _MAPTRIANGLE command.  It should fix the issue.  (I think.)


EDIT:

Testing, I think the code works as intended now:
Code: QB64: [Select]
  1. _TITLE "fTri Tests, click 4 points to draw transparent quad" 'b+ 2019-12-15 discovered a problem with fTri or using it with fQuad
  2.  
  3. CONST xmax = 800, ymax = 600
  4. SCREEN _NEWIMAGE(xmax, ymax, 32)
  5. _SCREENMOVE 300, 40
  6. DIM pi, oldMouse
  7. DIM mx(1 TO 4), my(1 TO 4)
  8.     CLS
  9.     oldMouse = -1
  10.     WHILE pi < 4 'get 4 mouse clicks
  11.         _PRINTSTRING (5, 5), SPACE$(20)
  12.         _PRINTSTRING (5, 5), "Need 4 clicks, have" + STR$(pi)
  13.         WHILE _MOUSEINPUT: WEND
  14.         IF _MOUSEBUTTON(1) AND oldMouse = 0 THEN 'new mouse down
  15.             pi = pi + 1
  16.             mx(pi) = _MOUSEX: my(pi) = _MOUSEY
  17.             CIRCLE (mx(pi), my(pi)), 2
  18.         END IF
  19.         oldMouse = _MOUSEBUTTON(1)
  20.         _DISPLAY
  21.         _LIMIT 60
  22.     WEND
  23.     _PRINTSTRING (5, 5), "Sleeping, click or press key... or esc"
  24.     'fquad1 mx(1), my(1), mx(2), my(2), mx(3), my(3), mx(4), my(4), &H880000FF '>>>>>>>>>>>>>>>>>>> switch between fquad and fquad1
  25.     fquad mx(1), my(1), mx(2), my(2), mx(3), my(3), mx(4), my(4), &H880000FF '>>>>>>>>>>>>>>>>>>> switch between fquad and fquad1
  26.     _DISPLAY
  27.     cSleep 45 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< dang!! this is working either fixed 2019-12-16 2nd time oldMouse = -1 at start
  28.     'Pause 30 ' <<<<<<<<<<<<<<<<<<<< well this isn't working either!!!!!!!!!!!!!!
  29.     'SLEEP
  30.     pi = 0 'point index
  31.  
  32.  
  33. ' my original fTri that never had a problem with
  34. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  35. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  36.     DIM D AS LONG, a&
  37.     D = _DEST
  38.     a& = _NEWIMAGE(1, 1, 32)
  39.     _DEST a&
  40.     PSET (0, 0), K
  41.     _DEST D
  42.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  43.     _FREEIMAGE a& '<<< this is important!
  44.  
  45. '2019-11-20 Steve saves some time with STATIC and saves and restores last dest
  46. SUB ftri1 (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  47.     DIM D AS LONG
  48.     STATIC a&
  49.     D = _DEST
  50.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
  51.     _DEST a&
  52.     _DONTBLEND a&
  53.     PSET (0, 0), K
  54.     _BLEND a&
  55.     _DEST D
  56.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  57.  
  58. ' original fill quad that may be at fault using Steve's fTri version
  59. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is opposite of x4, y4
  60. SUB fquad1 (x1, y1, x2, y2, x3, y3, x4, y4, K AS _UNSIGNED LONG)
  61.     ftri1 x1, y1, x2, y2, x4, y4, K
  62.     ftri1 x3, y3, x2, y2, x4, y4, K
  63.  
  64. 'update 2019-12-16 needs orig fTri
  65. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is opposite of x4, y4
  66. SUB fquad (x1, y1, x2, y2, x3, y3, x4, y4, K AS _UNSIGNED LONG)
  67.     ftri x1, y1, x2, y2, x3, y3, K
  68.     ftri x3, y3, x4, y4, x1, y1, K
  69.  
  70. 'update 2019-12-16 in ...test\graphics\fTri tests.bas
  71. SUB cSleep (secsWait AS DOUBLE) 'wait for keypress or mouseclick, solves midnight problem nicely I think
  72.     DIM wayt AS INTEGER, oldMouse AS INTEGER, k AS LONG, startTime AS DOUBLE
  73.  
  74.     oldMouse = -1 '2019-12-16 2nd fix today assume an old mouse click is still active
  75.     startTime = TIMER
  76.     wayt = 1
  77.     _KEYCLEAR
  78.     WHILE wayt
  79.         WHILE _MOUSEINPUT: WEND
  80.         IF _MOUSEBUTTON(1) AND oldMouse = 0 THEN wayt = 0
  81.         oldMouse = _MOUSEBUTTON(1) ' <<< this is Steve's cool way to get clear of mouse click
  82.         k = _KEYHIT: IF k > 0 THEN _KEYCLEAR: wayt = 0
  83.         IF TIMER - startTime < 0 THEN 'past midnight
  84.             IF TIMER + 24 * 60 * 60 - startTime > secsWait THEN wayt = 0
  85.         ELSE
  86.             IF TIMER - startTime >= secsWait THEN wayt = 0
  87.         END IF
  88.         _LIMIT 30
  89.     WEND
  90.  
  91. 'try Steve's Pause, nope doesn't work either!!!!
  92. SUB Pause (time AS _FLOAT)
  93.     DIM ExitTime AS _FLOAT, oldMouse AS INTEGER, k AS LONG
  94.  
  95.     _KEYCLEAR 'clear the keyboard buffer so we don't automatically exit the routine
  96.     'WHILE _MOUSEINPUT OR _MOUSEBUTTON(1): WEND 'clear mouse too
  97.     oldMouse = -1 'in case a mouse down still active
  98.     IF time <= 0 THEN ExitTime = 1.18E+1000 ELSE ExitTime = time + TIMER
  99.     DO
  100.         WHILE _MOUSEINPUT: WEND: IF _MOUSEBUTTON(1) AND NOT oldMouse THEN EXIT SUB
  101.         k = _KEYHIT: IF k > 0 THEN _KEYCLEAR: EXIT SUB 'clear any stray key events so they don't mess with code outside the Pause.
  102.         oldMouse = _MOUSEBUTTON(1)
  103.         _LIMIT 10
  104.     LOOP UNTIL ExitTime < TIMER
« Last Edit: December 16, 2019, 03:12:07 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Isometric Mapping Demo
« Reply #33 on: December 16, 2019, 03:26:12 pm »
Steve, I think you still have fQuad1 line still commented out and are using fQuad line with the other fTri used.
 I am still seeing a bright solid blue when I uncomment fquad1 and comment fquad.

fquad1 tests with the STATIC a& with _DONTBLEND and fquad tests the working fTri that uses _FREEIMAGE.


Update: OK so I tried testing some other ranges of Alpha and discovered Steve's fix for fTri is working fine and the original fTri isn't registering anything see-able in low ranges of Alpha.

So I am confused, maybe fTri was broken all along? This is sort of the same problem with the version of Titled Ellipse Fill I came up with yesterday, low alpha's are not see-able.
« Last Edit: December 16, 2019, 04:14:25 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Isometric Mapping Demo
« Reply #34 on: December 16, 2019, 10:40:00 pm »
Steve, I think you still have fQuad1 line still commented out and are using fQuad line with the other fTri used.
 I am still seeing a bright solid blue when I uncomment fquad1 and comment fquad.

fquad1 tests with the STATIC a& with _DONTBLEND and fquad tests the working fTri that uses _FREEIMAGE.


Update: OK so I tried testing some other ranges of Alpha and discovered Steve's fix for fTri is working fine and the original fTri isn't registering anything see-able in low ranges of Alpha.

So I am confused, maybe fTri was broken all along? This is sort of the same problem with the version of Titled Ellipse Fill I came up with yesterday, low alpha's are not see-able.

Is it just a case of low alpha getting blended out into the background?  Take an image with 255 alpha, blend it with 10 alpha, and it fades it into the background.  Take a background with 0 alpha, blend it with 10 alpha, and it’s going to end up so faded as to be transparent in almost all cases.  (Particularly with my poor eyes an high gamma/contrast settings...)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Isometric Mapping Demo
« Reply #35 on: December 16, 2019, 11:06:01 pm »
Steve it was the _DONTBLEND / _BLEND thing, not only did it make the Fill Triangle code work better it fixed the problem I had doing tiltled ellipse fills from a Flat Filled Ellipse and RotoZooming the tilt onto the drawing. I guess I misunderstood how drawing transparencies were taking place on a 0 alpha background.