QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: PMACKAY on April 15, 2019, 08:27:42 pm

Title: gl shaders in text mode...
Post by: PMACKAY on April 15, 2019, 08:27:42 pm
how would i use gl... would like to use a simple shadder to put light on screen on dark images (torch light) as in circle (100,100),10,light

i do not know where to start or how to implement



like a dungeon with a torch light on
Title: Re: gl shaders in text mode...
Post by: Raven_Singularity on April 15, 2019, 08:56:28 pm
Why text mode, and not 32bit graphical mode?  OpenGL lighting is clearly graphical.  :-)
Title: Re: gl shaders in text mode...
Post by: Petr on April 16, 2019, 02:57:34 pm
So you say - text mode? Well, try this. I wish you good luck in recalculating the coordinates between the text screen and the hardware image. I mean, I'll be glad if you can do it because I don't want to think of it, but I would definitely use it.



Code: QB64: [Select]
  1. himage = _NEWIMAGE(100, 100, 32)
  2. _DEST himage
  3. FOR x = 1 TO 255
  4.     FOR R = 0 TO _PI(2) STEP .001
  5.         PSET (50 + SIN(R) * x, 50 + COS(R) * x), _RGBA32(0, 0, 0, x)
  6.     NEXT R
  7. himage = _COPYIMAGE(himage, 33) '! HARDWARE IMAGE need DISPLAY!
  8.  
  9. CLS , 15
  10.  
  11. FOR print_something = 1 TO 1000
  12.     char = RND * 127 + 31
  13.     PRINT CHR$(char);
  14.  
  15.  
  16.  
  17.  
  18.     _MAPTRIANGLE (100, 100)-(0, 100)-(100, 0), himage TO(1, -1, -1)-(-1, -1, -1)-(1, 1, -1), 0
  19.     _MAPTRIANGLE (0, 100)-(100, 0)-(0, 0), himage TO(-1, -1, -1)-(1, 1, -1)-(-1, 1, -1), 0
  20.  
  21.  
  22.     _DISPLAY
  23.  

or better...


Code: QB64: [Select]
  1.  
  2. himage = _NEWIMAGE(512, 512, 32)
  3. _DEST himage
  4. FOR x = 1 TO 255
  5.     FOR R = 0 TO _PI(2) STEP .001
  6.         PSET (256 + (SIN(R) * x), 256 + (COS(R) * x)), _RGBA32(0, 0, 0, x - 20)
  7.     NEXT R
  8. himage = _COPYIMAGE(himage, 33) '! HARDWARE IMAGE need DISPLAY!
  9.  
  10. CLS , 15
  11. COLOR 0, 15
  12.  
  13. FOR print_something = 1 TO 2000
  14.     char = RND * 127 + 31
  15.     PRINT CHR$(char);
  16.  
  17. D = -1
  18. W = 512
  19. H = 512
  20.  
  21.  
  22.     _MAPTRIANGLE (W, H)-(0, H)-(W, 0), himage TO(1, -1, D)-(-1, -1, D)-(1, 1, D), 0
  23.     _MAPTRIANGLE (0, H)-(W, 0)-(0, 0), himage TO(-1, -1, D)-(1, 1, D)-(-1, 1, D), 0
  24.  
  25.  
  26.     _DISPLAY
  27.     _LIMIT 15
  28.  
  29.  
Title: Re: gl shaders in text mode...
Post by: bplus on April 16, 2019, 05:25:03 pm
Nice effect Petr!
Title: Re: gl shaders in text mode...
Post by: PMACKAY on April 27, 2019, 06:50:34 am
that is cool... just now to work it out...
Title: Re: gl shaders in text mode...
Post by: Petr on April 27, 2019, 07:35:36 am
Hi. I do it much easier and functional. For this use you need none depth, so is much easyest using PUTIMAGE for hardware image. To completely hide the text, just make the circle so large that it covers the entire area of the text screen. Option for realize using PUTIMAGE for hardware images thought me, when I read the program here https://www.qb64.org/forum/index.php?topic=1310.msg105090#msg105090



Use mouse.

Code: QB64: [Select]
  1.  
  2. himage = _NEWIMAGE(512, 512, 32)
  3. _DEST himage
  4.  
  5. FOR x = 1 TO 255
  6.     FOR R = 0 TO _PI(2) STEP .001
  7.         PSET (256 + (SIN(R) * x), 256 + (COS(R) * x)), _RGBA32(0, 0, 0, x - 20)
  8.     NEXT R
  9. himage = _COPYIMAGE(himage, 33) '! HARDWARE IMAGE need DISPLAY!
  10.  
  11. CLS , 15
  12. COLOR 0, 15
  13.  
  14. FOR print_something = 1 TO 2000
  15.     char = RND * 127 + 31
  16.     PRINT CHR$(char);
  17.  
  18. D = -1
  19. W = 512
  20. H = 512
  21.  
  22.  
  23.     x = (-32 + _MOUSEX) * 8 ' -40 is one half from maximum MOUSEX value. Because X is coordinate SCREEN 0, it is maximal value 80. 8 is font witdh for basic text font. Image width is 512, so 512/2/8 = 32 for image middle in X
  24.     y = (-16 + _MOUSEY) * 16 '16 is one half from maximum MOUSEY value. Because Y coordinate is also SCREEN 0, is maximal Y value 32. Font height is 16. Image height is 512, so 512/2/16 = 16 for image middle in Y
  25.     LOCATE 1, 1: PRINT x, y
  26.  
  27.     _PUTIMAGE (x, y), himage, 0
  28.  
  29.     _DISPLAY
  30.     _LIMIT 15
  31.  
  32.  
Title: Re: gl shaders in text mode...
Post by: Petr on April 28, 2019, 03:50:34 am
For smooth running I recommend to compile in version 1.1, where the mouse coordinates in text mode are returned as a decimal number and not as an integer from newer versions.
Title: Re: gl shaders in text mode...
Post by: PMACKAY on April 28, 2019, 09:29:35 am
works great and very easy...

any chance on this having about eight different lights on screen.... eg (just light up enemys and surrounds (eg.black screen with eight areas visible in ascii)

wanting this for a dungeon like map game in ascii.... so can see enemys and chests and items moving around in my maps

char data like 3x3 cell so light maybe 6x6 or 7x7.....


run smooth in qb64 1.3 on linux mint. thank you very simple :) cheers

Title: Re: gl shaders in text mode...
Post by: bplus on April 28, 2019, 01:19:26 pm
Why text mode, and not 32bit graphical mode?  OpenGL lighting is clearly graphical.  :-)

+1

Let's see Petr or Pete do this in Text mode ;-))
Code: QB64: [Select]
  1. _TITLE "Bouncing Search Lights" 'started 2019-04-28 B+
  2.  
  3. CONST xmax = 800
  4. CONST ymax = 600
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6.  
  7. DIM txt(1 TO 37) AS STRING, v(1 TO 37)
  8. FOR i = 1 TO 37
  9.     b$ = ""
  10.     FOR j = 1 TO 100
  11.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  12.     NEXT
  13.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  14.  
  15. COLOR 0, 1
  16. balls = 20
  17. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  18. FOR i = 1 TO balls
  19.     r(i) = rand(10, 65)
  20.     x(i) = rand(r(i), xmax - r(i))
  21.     y(i) = rand(r(i), ymax - r(i))
  22.     c(i) = rand(1, 15)
  23.     dx(i) = rand(1, 5) * rdir
  24.     dy(i) = rand(1, 5) * rdir
  25.     rr(i) = rand(150, 255)
  26.     gg(i) = rand(150, 255)
  27.     bb(i) = rand(150, 255)
  28.  
  29. WHILE _KEYDOWN(27) = 0
  30.     CLS
  31.     FOR i = 1 TO balls
  32.         'ready for collision
  33.         a(i) = _ATAN2(dy(i), dx(i))
  34.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  35.         imoved = 0
  36.         FOR j = i + 1 TO balls
  37.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  38.                 imoved = 1
  39.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  40.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  41.                 'update new dx, dy for i and j balls
  42.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  43.                 power = (power1 + power2) / 2
  44.                 dx(i) = power * COS(a(i))
  45.                 dy(i) = power * SIN(a(i))
  46.                 dx(j) = power * COS(a(j))
  47.                 dy(j) = power * SIN(a(j))
  48.                 x(i) = x(i) + dx(i)
  49.                 y(i) = y(i) + dy(i)
  50.                 x(j) = x(j) + dx(j)
  51.                 y(j) = y(j) + dy(j)
  52.                 EXIT FOR
  53.             END IF
  54.         NEXT
  55.         IF imoved = 0 THEN
  56.             x(i) = x(i) + dx(i)
  57.             y(i) = y(i) + dy(i)
  58.         END IF
  59.         IF x(i) < r(i) THEN dx(i) = -dx(i): x(i) = r(i)
  60.         IF x(i) > xmax - r(i) THEN dx(i) = -dx(i): x(i) = xmax - r(i)
  61.         IF y(i) < r(i) THEN dy(i) = -dy(i): y(i) = r(i)
  62.         IF y(i) > ymax - r(i) THEN dy(i) = -dy(i): y(i) = ymax - r(i)
  63.  
  64.         FOR rad = r(i) TO 0 STEP -1
  65.             'COLOR _RGB32(rr(i) - 10 * rad, gg(i) - 10 * rad, bb(i) - 10 * rad)
  66.             'fcirc x(i), y(i), rad, _RGBA32((r(i) - rad) / r(i) * rr(i), (rad - i) / r(i) * gg(i), (rad - i) / r(i) * bb(i), 20)
  67.             fcirc x(i), y(i), rad, _RGBA32(rr(i), gg(i), bb(i), 12)
  68.         NEXT
  69.     NEXT
  70.     FOR i = 1 TO 37
  71.         txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  72.         FOR l = 1 TO 100
  73.             IF i MOD 2 THEN midInk 60, 0, 0, 0, 0, 60, l / 100 ELSE midInk 0, 0, 60, 60, 0, 0, l / 100
  74.             LOCATE i, l: PRINT MID$(txt(i), l, 1);
  75.         NEXT
  76.     NEXT
  77.  
  78.     _DISPLAY
  79.     _LIMIT 10
  80.  
  81. FUNCTION rand (lo, hi)
  82.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  83.  
  84. FUNCTION rdir ()
  85.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  86.  
  87. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  88.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  89.     DIM X AS INTEGER, Y AS INTEGER
  90.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  91.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  92.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  93.     WHILE X > Y
  94.         RadiusError = RadiusError + Y * 2 + 1
  95.         IF RadiusError >= 0 THEN
  96.             IF X <> Y + 1 THEN
  97.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  98.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  99.             END IF
  100.             X = X - 1
  101.             RadiusError = RadiusError - X * 2
  102.         END IF
  103.         Y = Y + 1
  104.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  105.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  106.     WEND
  107.  
  108. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  109.     COLOR _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  110.  

BTW does it really count to draw stuff in a graphics _DEST and then paste it into the Text Mode screen?
What would Pete say? :D
Title: Re: gl shaders in text mode...
Post by: Petr on April 28, 2019, 04:23:49 pm
Chacha, good try! And you almost got me! The reason why it could not be implanted directly, is the CLS command in your loop. CLS will do _RGBA32 (0,0,0,255) everywhere, but the default NEWIMAGE window (just at the beginning) is _RGBA32 (0,0,0,0) and this just ensures transparency between layers. If you leave the CLS there, then the CLS color is not transparent and this is undesirable in this case. You have to start drawing on a transparent background - then where you set alpha to zero, there is transparency to the next layer. Where you don't set it, then i do _RGBA32 (0,0,0,255) - just in this program, rows 85-90 in this source. It took a while to figure it me out. You're responsible for the smoke from my brain :-D



Code: QB64: [Select]
  1. 'upgrade for real text mode
  2.  
  3.  
  4.  
  5. _TITLE "Bouncing Search Lights" 'started 2019-04-28 B+, continued by Petr to REAL TEXT SCREEN :-D
  6.  
  7. CONST xmax = 800
  8. CONST ymax = 600
  9.  
  10. DIM txt(1 TO 37) AS STRING, v(1 TO 37)
  11. FOR i = 1 TO 37
  12.     b$ = ""
  13.     FOR j = 1 TO 100
  14.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  15.     NEXT
  16.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  17.  
  18.  
  19. balls = 20
  20. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  21. FOR i = 1 TO balls
  22.     r(i) = rand(10, 65)
  23.     x(i) = rand(r(i), xmax - r(i))
  24.     y(i) = rand(r(i), ymax - r(i))
  25.     c(i) = rand(1, 15)
  26.     dx(i) = rand(1, 5) * rdir
  27.     dy(i) = rand(1, 5) * rdir
  28.     rr(i) = rand(150, 255)
  29.     gg(i) = rand(150, 255)
  30.     bb(i) = rand(150, 255)
  31.  
  32.  
  33.  
  34. WHILE _KEYDOWN(27) = 0
  35.     Bplus = _NEWIMAGE(xmax, ymax, 32)
  36.     _DEST Bplus
  37.  
  38.  
  39.  
  40.     ' CLS , _RGB32(0, 0, 0)
  41.     FOR i = 1 TO balls
  42.         'ready for collision
  43.         a(i) = _ATAN2(dy(i), dx(i))
  44.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  45.         imoved = 0
  46.         FOR j = i + 1 TO balls
  47.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  48.                 imoved = 1
  49.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  50.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  51.                 'update new dx, dy for i and j balls
  52.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  53.                 power = (power1 + power2) / 2
  54.                 dx(i) = power * COS(a(i))
  55.                 dy(i) = power * SIN(a(i))
  56.                 dx(j) = power * COS(a(j))
  57.                 dy(j) = power * SIN(a(j))
  58.                 x(i) = x(i) + dx(i)
  59.                 y(i) = y(i) + dy(i)
  60.                 x(j) = x(j) + dx(j)
  61.                 y(j) = y(j) + dy(j)
  62.                 EXIT FOR
  63.             END IF
  64.         NEXT
  65.         IF imoved = 0 THEN
  66.             x(i) = x(i) + dx(i)
  67.             y(i) = y(i) + dy(i)
  68.         END IF
  69.         IF x(i) < r(i) THEN dx(i) = -dx(i): x(i) = r(i)
  70.         IF x(i) > xmax - r(i) THEN dx(i) = -dx(i): x(i) = xmax - r(i)
  71.         IF y(i) < r(i) THEN dy(i) = -dy(i): y(i) = r(i)
  72.         IF y(i) > ymax - r(i) THEN dy(i) = -dy(i): y(i) = ymax - r(i)
  73.  
  74.  
  75.         FOR rad = r(i) TO 0 STEP -1
  76.             fcirc x(i), y(i), rad, _RGBA32(rr(i), gg(i), bb(i), 12)
  77.         NEXT
  78.     NEXT
  79.  
  80.     'do untransparently unusued areas. More better is do this with MEM
  81.     FOR dby = 0 TO 599
  82.         FOR dbx = 0 TO 799
  83.             _SOURCE Bplus
  84.             IF POINT(dbx, dby) = 0 THEN PSET (dbx, dby), _RGB32(1, 1, 1)
  85.         NEXT
  86.     NEXT
  87.  
  88.     _SOURCE 0
  89.     _DEST 0 'redirecting to text screen
  90.     ' COLOR 0, 1
  91.     FOR i = 1 TO 37
  92.         txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  93.         FOR l = 1 TO 80
  94.             ' IF i MOD 2 THEN midInk 60, 0, 0, 0, 0, 60, l / 100 ELSE midInk 0, 0, 60, 60, 0, 0, l / 100
  95.  
  96.             p = i * 1.3
  97.  
  98.             LOCATE p, l: PRINT MID$(txt(i), l, 1);
  99.             LOCATE p, l: PRINT MID$(txt(i), l, 1);
  100.  
  101.         NEXT
  102.     NEXT
  103.  
  104.     _DEST 0
  105.     Himage = _COPYIMAGE(Bplus, 33)
  106.     _PUTIMAGE (0, 0)-(800, 600), Himage, 0
  107.     _DISPLAY
  108.     _LIMIT 20
  109.     _FREEIMAGE Himage
  110.     _FREEIMAGE Bplus
  111.  
  112. FUNCTION rand (lo, hi)
  113.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  114.  
  115. FUNCTION rdir ()
  116.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  117.  
  118. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  119.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  120.     DIM X AS INTEGER, Y AS INTEGER
  121.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  122.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  123.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  124.     WHILE X > Y
  125.         RadiusError = RadiusError + Y * 2 + 1
  126.         IF RadiusError >= 0 THEN
  127.             IF X <> Y + 1 THEN
  128.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  129.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  130.             END IF
  131.             X = X - 1
  132.             RadiusError = RadiusError - X * 2
  133.         END IF
  134.         Y = Y + 1
  135.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  136.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  137.     WEND
  138.  
  139. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  140.     COLOR _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  141.  
Title: Re: gl shaders in text mode...
Post by: bplus on April 28, 2019, 05:09:41 pm
Wow Petr! Nice! :)

Not sure what is going on and why I can't make the letters Black but at least I can make them better sized:
Code: QB64: [Select]
  1. 'upgrade for real text mod
  2.  
  3. _TITLE "Bouncing Search Lights" 'started 2019-04-28 B+, continued by Petr to REAL TEXT SCREEN :-D
  4. 'continued by B+ with normal letter size :-))
  5.  
  6. CONST xmax = 800
  7. CONST ymax = 600
  8.  
  9. DIM txt(1 TO 25) AS STRING, v(1 TO 25)
  10. FOR i = 1 TO 25
  11.     b$ = ""
  12.     FOR j = 1 TO 100
  13.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  14.     NEXT
  15.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  16.  
  17.  
  18. balls = 20
  19. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  20. FOR i = 1 TO balls
  21.     r(i) = rand(10, 65)
  22.     x(i) = rand(r(i), xmax - r(i))
  23.     y(i) = rand(r(i), ymax - r(i))
  24.     c(i) = rand(1, 15)
  25.     dx(i) = rand(1, 5) * rdir
  26.     dy(i) = rand(1, 5) * rdir
  27.     rr(i) = rand(50, 255)
  28.     gg(i) = rand(50, 255)
  29.     bb(i) = rand(50, 255)
  30.  
  31.  
  32.  
  33. WHILE _KEYDOWN(27) = 0
  34.     Bplus = _NEWIMAGE(xmax, ymax, 32)
  35.     _DEST Bplus
  36.  
  37.  
  38.  
  39.     ' CLS , _RGB32(0, 0, 0)
  40.     FOR i = 1 TO balls
  41.         'ready for collision
  42.         a(i) = _ATAN2(dy(i), dx(i))
  43.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  44.         imoved = 0
  45.         FOR j = i + 1 TO balls
  46.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  47.                 imoved = 1
  48.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  49.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  50.                 'update new dx, dy for i and j balls
  51.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  52.                 power = (power1 + power2) / 2
  53.                 dx(i) = power * COS(a(i))
  54.                 dy(i) = power * SIN(a(i))
  55.                 dx(j) = power * COS(a(j))
  56.                 dy(j) = power * SIN(a(j))
  57.                 x(i) = x(i) + dx(i)
  58.                 y(i) = y(i) + dy(i)
  59.                 x(j) = x(j) + dx(j)
  60.                 y(j) = y(j) + dy(j)
  61.                 EXIT FOR
  62.             END IF
  63.         NEXT
  64.         IF imoved = 0 THEN
  65.             x(i) = x(i) + dx(i)
  66.             y(i) = y(i) + dy(i)
  67.         END IF
  68.         IF x(i) < r(i) THEN dx(i) = -dx(i): x(i) = r(i)
  69.         IF x(i) > xmax - r(i) THEN dx(i) = -dx(i): x(i) = xmax - r(i)
  70.         IF y(i) < r(i) THEN dy(i) = -dy(i): y(i) = r(i)
  71.         IF y(i) > ymax - r(i) THEN dy(i) = -dy(i): y(i) = ymax - r(i)
  72.  
  73.  
  74.         FOR rad = r(i) TO 0 STEP -1
  75.             fcirc x(i), y(i), rad, _RGBA32(rr(i), gg(i), bb(i), 12)
  76.         NEXT
  77.     NEXT
  78.  
  79.     'do untransparently unusued areas. More better is do this with MEM
  80.     FOR dby = 0 TO 599
  81.         FOR dbx = 0 TO 799
  82.             _SOURCE Bplus
  83.             IF POINT(dbx, dby) = 0 THEN PSET (dbx, dby), _RGB32(1, 1, 1)
  84.         NEXT
  85.     NEXT
  86.  
  87.     _SOURCE 0
  88.     _DEST 0 'redirecting to text screen
  89.  
  90.  
  91.     _DEST 0
  92.     Himage = _COPYIMAGE(Bplus, 33)
  93.     _PUTIMAGE (0, 0)-(800, 600), Himage, 0
  94.  
  95.     FOR i = 1 TO 25
  96.         txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  97.         FOR l = 1 TO 80
  98.             ' IF i MOD 2 THEN midInk 60, 0, 0, 0, 0, 60, l / 100 ELSE midInk 0, 0, 60, 60, 0, 0, l / 100
  99.  
  100.             'p = i * 1.3
  101.             COLOR 15
  102.             LOCATE i, l: PRINT MID$(txt(i), l, 1);
  103.             LOCATE i, l: PRINT MID$(txt(i), l, 1);
  104.  
  105.         NEXT
  106.     NEXT
  107.  
  108.     _DISPLAY
  109.     _LIMIT 20
  110.     _FREEIMAGE Himage
  111.     _FREEIMAGE Bplus
  112.  
  113. FUNCTION rand (lo, hi)
  114.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  115.  
  116. FUNCTION rdir ()
  117.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  118.  
  119. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  120.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  121.     DIM X AS INTEGER, Y AS INTEGER
  122.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  123.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  124.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  125.     WHILE X > Y
  126.         RadiusError = RadiusError + Y * 2 + 1
  127.         IF RadiusError >= 0 THEN
  128.             IF X <> Y + 1 THEN
  129.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  130.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  131.             END IF
  132.             X = X - 1
  133.             RadiusError = RadiusError - X * 2
  134.         END IF
  135.         Y = Y + 1
  136.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  137.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  138.     WEND
  139.  
  140. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  141.     COLOR _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  142.  
  143.  
  144.  
Title: Re: gl shaders in text mode...
Post by: Petr on April 28, 2019, 05:21:54 pm
Hi. Rewrite Color 15 to Color 0, 15 on row 105. Just Color 0 do unvisible, because it is black on black background. Also color 0,14 is good :-D
Title: Re: gl shaders in text mode...
Post by: bplus on April 28, 2019, 05:28:20 pm
Yeah, I tried that but I didn't want white background. I ideally the black letters would only appear only over the colored spheres.
Like this:
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

More smoke? :)

Title: Re: gl shaders in text mode...
Post by: Petr on April 28, 2019, 05:44:30 pm
I really do not want to recalculate the coordinates between the text screen and the balls on the graphics screen and print only those letters that are above the ball...

Because the background of the text is on a text screen, but you have a black background on the graphical screen with the balls, and you want black letters on the text screen, the only way I can think of it is set the background on the text screen of the ball by using RGB colors as much as possible with balls colors. BUT we already have midnight here....
Title: Re: gl shaders in text mode...
Post by: bplus on April 28, 2019, 10:40:20 pm
OK forget about colors then:
Code: QB64: [Select]
  1. 'upgrade for real text mod
  2.  
  3. _TITLE "Bouncing Search Lights" 'started 2019-04-28 B+, continued by Petr to REAL TEXT SCREEN :-D
  4. 'continued by B+ with normal letter size :-))
  5. 'mod 2 B+ forget about color to get black letters ending at edge of circles
  6.  
  7. CONST xmax = 640
  8. CONST ymax = 400
  9.  
  10. DIM txt(1 TO 25) AS STRING, v(1 TO 25)
  11. FOR i = 1 TO 25
  12.     b$ = ""
  13.     FOR j = 1 TO 100
  14.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  15.     NEXT
  16.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  17.  
  18. balls = 10
  19. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls)
  20. FOR i = 1 TO balls
  21.     r(i) = rand(10, 60)
  22.     x(i) = rand(r(i), xmax - r(i))
  23.     y(i) = rand(r(i), ymax - r(i))
  24.     c(i) = rand(1, 15)
  25.     dx(i) = rand(1, 5) * rdir
  26.     dy(i) = rand(1, 5) * rdir
  27.  
  28.  
  29. COLOR 0, 15
  30. WHILE _KEYDOWN(27) = 0
  31.     Bplus = _NEWIMAGE(xmax, ymax, 32)
  32.     _DEST Bplus
  33.     FOR i = 1 TO balls
  34.         'ready for collision
  35.         a(i) = _ATAN2(dy(i), dx(i))
  36.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  37.         imoved = 0
  38.         FOR j = i + 1 TO balls
  39.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  40.                 imoved = 1
  41.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  42.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  43.                 'update new dx, dy for i and j balls
  44.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  45.                 power = (power1 + power2) / 2
  46.                 dx(i) = power * COS(a(i))
  47.                 dy(i) = power * SIN(a(i))
  48.                 dx(j) = power * COS(a(j))
  49.                 dy(j) = power * SIN(a(j))
  50.                 x(i) = x(i) + dx(i)
  51.                 y(i) = y(i) + dy(i)
  52.                 x(j) = x(j) + dx(j)
  53.                 y(j) = y(j) + dy(j)
  54.                 EXIT FOR
  55.             END IF
  56.         NEXT
  57.         IF imoved = 0 THEN
  58.             x(i) = x(i) + dx(i)
  59.             y(i) = y(i) + dy(i)
  60.         END IF
  61.         IF x(i) < r(i) THEN dx(i) = -dx(i): x(i) = r(i)
  62.         IF x(i) > xmax - r(i) THEN dx(i) = -dx(i): x(i) = xmax - r(i)
  63.         IF y(i) < r(i) THEN dy(i) = -dy(i): y(i) = r(i)
  64.         IF y(i) > ymax - r(i) THEN dy(i) = -dy(i): y(i) = ymax - r(i)
  65.         fcirc x(i), y(i), r(i), _RGBA32(255, 255, 255, 20)
  66.     NEXT
  67.  
  68.  
  69.     'do untransparently unusued areas. More better is do this with MEM
  70.     FOR dby = 0 TO ymax - 1
  71.         FOR dbx = 0 TO xmax - 1
  72.             _SOURCE Bplus
  73.             IF POINT(dbx, dby) = 0 THEN PSET (dbx, dby), _RGB32(1, 1, 1)
  74.         NEXT
  75.     NEXT
  76.  
  77.     _SOURCE 0
  78.     _DEST 0 'redirecting to text screen
  79.     Himage = _COPYIMAGE(Bplus, 33)
  80.     _PUTIMAGE (0, 0)-(xmax, ymax), Himage, 0
  81.     FOR i = 1 TO 25
  82.         txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  83.         FOR l = 1 TO 80
  84.             LOCATE i, l: PRINT MID$(txt(i), l, 1);
  85.             LOCATE i, l: PRINT MID$(txt(i), l, 1);
  86.         NEXT
  87.     NEXT
  88.     _DISPLAY
  89.     _LIMIT 20
  90.     _FREEIMAGE Himage
  91.     _FREEIMAGE Bplus
  92.  
  93. FUNCTION rand (lo, hi)
  94.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  95.  
  96. FUNCTION rdir ()
  97.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  98.  
  99. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  100.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  101.     DIM X AS INTEGER, Y AS INTEGER
  102.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  103.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  104.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  105.     WHILE X > Y
  106.         RadiusError = RadiusError + Y * 2 + 1
  107.         IF RadiusError >= 0 THEN
  108.             IF X <> Y + 1 THEN
  109.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  110.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  111.             END IF
  112.             X = X - 1
  113.             RadiusError = RadiusError - X * 2
  114.         END IF
  115.         Y = Y + 1
  116.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  117.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  118.     WEND
  119.  
  120.  
Title: Re: gl shaders in text mode...
Post by: Petr on April 29, 2019, 02:01:34 am
Fasters, with black characters. See row 106.

Code: QB64: [Select]
  1. 'upgrade for real text mod
  2.  
  3. _TITLE "Bouncing Search Lights" 'started 2019-04-28 B+, continued by Petr to REAL TEXT SCREEN :-D
  4. 'continued by B+ with normal letter size :-))
  5.  
  6. CONST xmax = 800
  7. CONST ymax = 600
  8.  
  9. DIM txt(1 TO 25) AS STRING, v(1 TO 25)
  10. FOR i = 1 TO 25
  11.     b$ = ""
  12.     FOR j = 1 TO 100
  13.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  14.     NEXT
  15.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  16.  
  17.  
  18. balls = 20
  19. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  20. FOR i = 1 TO balls
  21.     r(i) = rand(10, 65)
  22.     x(i) = rand(r(i), xmax - r(i))
  23.     y(i) = rand(r(i), ymax - r(i))
  24.     c(i) = rand(1, 15)
  25.     dx(i) = rand(1, 5) * rdir
  26.     dy(i) = rand(1, 5) * rdir
  27.     rr(i) = rand(50, 255)
  28.     gg(i) = rand(50, 255)
  29.     bb(i) = rand(50, 255)
  30.  
  31.  
  32.  
  33. WHILE _KEYDOWN(27) = 0
  34.     Bplus = _NEWIMAGE(xmax, ymax, 32)
  35.     _DEST Bplus
  36.  
  37.  
  38.  
  39.     ' CLS , _RGB32(0, 0, 0)
  40.     FOR i = 1 TO balls
  41.         'ready for collision
  42.         a(i) = _ATAN2(dy(i), dx(i))
  43.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  44.         imoved = 0
  45.         FOR j = i + 1 TO balls
  46.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  47.                 imoved = 1
  48.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  49.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  50.                 'update new dx, dy for i and j balls
  51.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  52.                 power = (power1 + power2) / 2
  53.                 dx(i) = power * COS(a(i))
  54.                 dy(i) = power * SIN(a(i))
  55.                 dx(j) = power * COS(a(j))
  56.                 dy(j) = power * SIN(a(j))
  57.                 x(i) = x(i) + dx(i)
  58.                 y(i) = y(i) + dy(i)
  59.                 x(j) = x(j) + dx(j)
  60.                 y(j) = y(j) + dy(j)
  61.                 EXIT FOR
  62.             END IF
  63.         NEXT
  64.         IF imoved = 0 THEN
  65.             x(i) = x(i) + dx(i)
  66.             y(i) = y(i) + dy(i)
  67.         END IF
  68.         IF x(i) < r(i) THEN dx(i) = -dx(i): x(i) = r(i)
  69.         IF x(i) > xmax - r(i) THEN dx(i) = -dx(i): x(i) = xmax - r(i)
  70.         IF y(i) < r(i) THEN dy(i) = -dy(i): y(i) = r(i)
  71.         IF y(i) > ymax - r(i) THEN dy(i) = -dy(i): y(i) = ymax - r(i)
  72.  
  73.  
  74.         FOR rad = r(i) TO 0 STEP -1
  75.             fcirc x(i), y(i), rad, _RGBA32(rr(i), gg(i), bb(i), 12)
  76.         NEXT
  77.     NEXT
  78.  
  79.     _SETALPHA 255, _RGBA32(0, 0, 0, 0), Bplus 'much better solution as previous FOR... NEXT loop
  80.  
  81.  
  82.     _SOURCE 0
  83.     _DEST 0 'redirecting to text screen
  84.  
  85.  
  86.     _DEST 0
  87.     Himage = _COPYIMAGE(Bplus, 33)
  88.     _PUTIMAGE (0, 0)-(800, 600), Himage, 0
  89.     Xtranslate = _WIDTH(Bplus) / 8
  90.     Ytranslate = _HEIGHT(Bplus) / 16
  91.  
  92.     FOR i = 1 TO 25
  93.         txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  94.         FOR l = 1 TO 80
  95.             gX = (Xtranslate + i) * 8
  96.             gY = (-Ytranslate + l) * 16
  97.  
  98.             _SOURCE Bplus
  99.             _DEST 0
  100.             Kolor~& = POINT(gX, gY)
  101.             COLOR 0, 0
  102.             IF Kolor~& <> _RGB32(0, 0, 0) THEN COLOR 0, _RGB(_RED32(Kolor~&), _GREEN32(Kolor~&), _BLUE32(Kolor~&)) 'RGB background for text screen
  103.             LOCATE i, l: PRINT MID$(txt(i), l, 1);
  104.             LOCATE i, l: PRINT MID$(txt(i), l, 1);
  105.  
  106.         NEXT
  107.     NEXT
  108.  
  109.     _DISPLAY
  110.     _LIMIT 20
  111.     _FREEIMAGE Himage
  112.     _FREEIMAGE Bplus
  113.  
  114. FUNCTION rand (lo, hi)
  115.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  116.  
  117. FUNCTION rdir ()
  118.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  119.  
  120. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  121.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  122.     DIM X AS INTEGER, Y AS INTEGER
  123.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  124.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  125.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  126.     WHILE X > Y
  127.         RadiusError = RadiusError + Y * 2 + 1
  128.         IF RadiusError >= 0 THEN
  129.             IF X <> Y + 1 THEN
  130.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  131.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  132.             END IF
  133.             X = X - 1
  134.             RadiusError = RadiusError - X * 2
  135.         END IF
  136.         Y = Y + 1
  137.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  138.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  139.     WEND
  140.  
  141. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  142.     COLOR _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  143.  
Title: Re: gl shaders in text mode...
Post by: Petr on April 29, 2019, 02:49:57 am
Or this...

Code: QB64: [Select]
  1. 'upgrade for real text mod
  2.  
  3. _TITLE "Bouncing Search Lights" 'started 2019-04-28 B+, continued by Petr to REAL TEXT SCREEN :-D
  4. 'continued by B+ with normal letter size :-))
  5.  
  6. CONST xmax = 800
  7. CONST ymax = 600
  8.  
  9. DIM txt(1 TO 25) AS STRING, v(1 TO 25)
  10. FOR i = 1 TO 25
  11.     b$ = ""
  12.     FOR j = 1 TO 100
  13.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  14.     NEXT
  15.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  16.  
  17.  
  18. balls = 20
  19. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  20. FOR i = 1 TO balls
  21.     r(i) = rand(10, 65)
  22.     x(i) = rand(r(i), xmax - r(i))
  23.     y(i) = rand(r(i), ymax - r(i))
  24.     c(i) = rand(1, 15)
  25.     dx(i) = rand(1, 5) * rdir
  26.     dy(i) = rand(1, 5) * rdir
  27.     rr(i) = rand(50, 255)
  28.     gg(i) = rand(50, 255)
  29.     bb(i) = rand(50, 255)
  30.  
  31.  
  32.  
  33. WHILE _KEYDOWN(27) = 0
  34.     Bplus = _NEWIMAGE(xmax, ymax, 32)
  35.     _DEST Bplus
  36.  
  37.  
  38.  
  39.     ' CLS , _RGB32(0, 0, 0)
  40.     FOR i = 1 TO balls
  41.         'ready for collision
  42.         a(i) = _ATAN2(dy(i), dx(i))
  43.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  44.         imoved = 0
  45.         FOR j = i + 1 TO balls
  46.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  47.                 imoved = 1
  48.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  49.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  50.                 'update new dx, dy for i and j balls
  51.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  52.                 power = (power1 + power2) / 2
  53.                 dx(i) = power * COS(a(i))
  54.                 dy(i) = power * SIN(a(i))
  55.                 dx(j) = power * COS(a(j))
  56.                 dy(j) = power * SIN(a(j))
  57.                 x(i) = x(i) + dx(i)
  58.                 y(i) = y(i) + dy(i)
  59.                 x(j) = x(j) + dx(j)
  60.                 y(j) = y(j) + dy(j)
  61.                 EXIT FOR
  62.             END IF
  63.         NEXT
  64.         IF imoved = 0 THEN
  65.             x(i) = x(i) + dx(i)
  66.             y(i) = y(i) + dy(i)
  67.         END IF
  68.         IF x(i) < r(i) THEN dx(i) = -dx(i): x(i) = r(i)
  69.         IF x(i) > xmax - r(i) THEN dx(i) = -dx(i): x(i) = xmax - r(i)
  70.         IF y(i) < r(i) THEN dy(i) = -dy(i): y(i) = r(i)
  71.         IF y(i) > ymax - r(i) THEN dy(i) = -dy(i): y(i) = ymax - r(i)
  72.  
  73.  
  74.         FOR rad = r(i) TO 0 STEP -1
  75.             fcirc x(i), y(i), rad, _RGBA32(rr(i), gg(i), bb(i), 12)
  76.         NEXT
  77.     NEXT
  78.  
  79.     _SETALPHA 155, _RGBA32(0, 0, 0, 0), Bplus 'much better solution as previous FOR... NEXT loop
  80.  
  81.  
  82.     _SOURCE 0
  83.     _DEST 0 'redirecting to text screen
  84.  
  85.  
  86.     _DEST 0
  87.     Himage = _COPYIMAGE(Bplus, 33)
  88.     _PUTIMAGE (0, 0)-(800, 600), Himage, 0
  89.     Xtranslate = (_WIDTH(Bplus) / 80) / 8
  90.     Ytranslate = (_HEIGHT(Bplus) / 25) / 16
  91.  
  92.  
  93.     FOR B = 1 TO balls
  94.         RadiusX = r(B) / 2 / 8
  95.         RadiusY = r(B) / 2 / 16
  96.         FOR i = 1 TO 25
  97.             txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  98.             FOR l = 1 TO 80
  99.  
  100.  
  101.                 gX = (Xtranslate + l - RadiusX + 1) * 8
  102.                 gY = (Ytranslate + i - RadiusY) * 16
  103.  
  104.                 _SOURCE Bplus
  105.                 _DEST 0
  106.                 COLOR 0
  107.                 FOR fy = gY TO gY + 16
  108.                     FOR fx = gX TO gX + 8
  109.                         Kolor~& = POINT(gX, gY)
  110.                         IF _ALPHA32(Kolor~&) < 255 THEN COLOR 0, _RGB(_RED32(Kolor~&), _GREEN32(Kolor~&), _BLUE32(Kolor~&)): GOTO ENDFOR 'RGB background for text screen
  111.                     NEXT
  112.                 NEXT
  113.                 ENDFOR:
  114.                 LOCATE i, l: PRINT MID$(txt(i), l, 1);
  115.                 LOCATE i, l: PRINT MID$(txt(i), l, 1);
  116.             NEXT
  117.         NEXT
  118.     NEXT
  119.     _DISPLAY
  120.     _LIMIT 20
  121.     _FREEIMAGE Himage
  122.     _FREEIMAGE Bplus
  123.  
  124. FUNCTION rand (lo, hi)
  125.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  126.  
  127. FUNCTION rdir ()
  128.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  129.  
  130. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  131.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  132.     DIM X AS INTEGER, Y AS INTEGER
  133.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  134.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  135.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  136.     WHILE X > Y
  137.         RadiusError = RadiusError + Y * 2 + 1
  138.         IF RadiusError >= 0 THEN
  139.             IF X <> Y + 1 THEN
  140.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  141.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  142.             END IF
  143.             X = X - 1
  144.             RadiusError = RadiusError - X * 2
  145.         END IF
  146.         Y = Y + 1
  147.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  148.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  149.     WEND
  150.  
  151. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  152.     COLOR _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  153.  
Title: Re: gl shaders in text mode...
Post by: PMACKAY on April 29, 2019, 05:55:08 am
This is all great stuff.... thanks guys... :)   AWESOME many thanks.....
Title: Re: gl shaders in text mode...
Post by: bplus on April 29, 2019, 10:54:53 am
Here is odd variation that keeps colors but only in the letters!
Code: QB64: [Select]
  1. _TITLE "Bouncing Search Lights" 'started 2019-04-28 B+, continued by Petr to REAL TEXT SCREEN :-D
  2. 'continued by B+ with normal letter size :-))
  3. ' 2019-04-29 another variation
  4.  
  5. 'this really text mode??? ;-))
  6.  
  7. CONST xmax = 640
  8. CONST ymax = 400
  9.  
  10. DIM txt(1 TO 25) AS STRING, v(1 TO 25)
  11. FOR i = 1 TO 25
  12.     b$ = ""
  13.     FOR j = 1 TO 100
  14.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  15.     NEXT
  16.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  17. balls = 20
  18. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  19. FOR i = 1 TO balls
  20.     r(i) = rand(10, 65)
  21.     x(i) = rand(r(i), xmax - r(i))
  22.     y(i) = rand(r(i), ymax - r(i))
  23.     c(i) = rand(1, 15)
  24.     dx(i) = rand(1, 5) * rdir
  25.     dy(i) = rand(1, 5) * rdir
  26.     rr(i) = rand(50, 255)
  27.     gg(i) = rand(50, 255)
  28.     bb(i) = rand(50, 255)
  29. Bplus = _NEWIMAGE(xmax, ymax, 32)
  30. WHILE _KEYDOWN(27) = 0
  31.     _DEST Bplus
  32.     CLS
  33.     FOR i = 1 TO balls
  34.         'ready for collision
  35.         a(i) = _ATAN2(dy(i), dx(i))
  36.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  37.         imoved = 0
  38.         FOR j = i + 1 TO balls
  39.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) - 20 THEN
  40.                 imoved = 1
  41.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  42.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  43.                 'update new dx, dy for i and j balls
  44.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  45.                 power = (power1 + power2) / 2
  46.                 dx(i) = power * COS(a(i))
  47.                 dy(i) = power * SIN(a(i))
  48.                 dx(j) = power * COS(a(j))
  49.                 dy(j) = power * SIN(a(j))
  50.                 x(i) = x(i) + dx(i)
  51.                 y(i) = y(i) + dy(i)
  52.                 x(j) = x(j) + dx(j)
  53.                 y(j) = y(j) + dy(j)
  54.                 EXIT FOR
  55.             END IF
  56.         NEXT
  57.         IF imoved = 0 THEN
  58.             x(i) = x(i) + dx(i)
  59.             y(i) = y(i) + dy(i)
  60.         END IF
  61.         IF x(i) < r(i) THEN dx(i) = -dx(i): x(i) = r(i)
  62.         IF x(i) > xmax - r(i) THEN dx(i) = -dx(i): x(i) = xmax - r(i)
  63.         IF y(i) < r(i) THEN dy(i) = -dy(i): y(i) = r(i)
  64.         IF y(i) > ymax - r(i) THEN dy(i) = -dy(i): y(i) = ymax - r(i)
  65.         FOR rad = r(i) TO 0 STEP -1
  66.             fcirc x(i), y(i), rad, _RGBA32(rr(i), gg(i), bb(i), 10)
  67.         NEXT
  68.     NEXT
  69.  
  70.     COLOR 0 '<<< doesn't matter what color but need something?
  71.     FOR i = 1 TO 25
  72.         txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  73.         LOCATE i, 1: PRINT MID$(txt(i), 1, 80);
  74.     NEXT
  75.  
  76.     _DEST 0 'redirecting to text screen
  77.  
  78.     Himage = _COPYIMAGE(Bplus, 33)
  79.     _PUTIMAGE (0, 0)-(xmax, ymax), Himage, 0
  80.     _DISPLAY
  81.     _LIMIT 15
  82.     _FREEIMAGE Himage
  83.  
  84. FUNCTION rand (lo, hi)
  85.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  86.  
  87. FUNCTION rdir ()
  88.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  89.  
  90. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  91.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  92.     DIM X AS INTEGER, Y AS INTEGER
  93.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  94.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  95.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  96.     WHILE X > Y
  97.         RadiusError = RadiusError + Y * 2 + 1
  98.         IF RadiusError >= 0 THEN
  99.             IF X <> Y + 1 THEN
  100.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  101.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  102.             END IF
  103.             X = X - 1
  104.             RadiusError = RadiusError - X * 2
  105.         END IF
  106.         Y = Y + 1
  107.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  108.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  109.     WEND
  110.  
  111.  
 [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: gl shaders in text mode...
Post by: Petr on April 29, 2019, 01:04:08 pm
Hi Bplus (Sphere King),

It looks nice, but the text is printed on the graphics screen and uses 32-bit color. To your question on line 73 about color: Because you have a black font on a black background inside a 32-bit image, the font is not visible. Since the COLOR 0 in 32-bit mode returns the same as _RGBA32 (0,0,0,0), then the font is transparent (this cannot be achieved if you put the text on SCREEN 0) and the sphere changes his background color, so then is visible.

It's definitely very nice.
Title: Re: gl shaders in text mode...
Post by: bplus on April 29, 2019, 03:21:53 pm
OHHH! The font is transparent. Yeah because in 32 bit... Same if I have COLOR 9 almost transparent... that's why it didn't make a difference but why I did need COLOR something (very low), forgot I was in 32 bit mode, got it. Thanks Petr
Title: Re: gl shaders in text mode...
Post by: bplus on April 29, 2019, 03:31:09 pm
OK now it is same as graphics mode (I think):
Code: QB64: [Select]
  1. _TITLE "Bouncing Search Lights" 'started 2019-04-28 B+, continued by Petr to REAL TEXT SCREEN :-D
  2. 'continued by B+ with normal letter size :-))
  3. ' 2019-04-29 another variation
  4. ' 2019-04-29 now same as graphics mode!!! Thanks Petr!!!
  5.  
  6.  
  7. 'this really text mode??? ;-))
  8.  
  9. CONST xmax = 640
  10. CONST ymax = 400
  11.  
  12. DIM txt(1 TO 25) AS STRING, v(1 TO 25)
  13. FOR i = 1 TO 25
  14.     b$ = ""
  15.     FOR j = 1 TO 100
  16.         b$ = b$ + CHR$(INT(RND * 96) + 32)
  17.     NEXT
  18.     txt(i) = b$: v(i) = INT(RND * 3) + 1
  19. balls = 15
  20. DIM x(balls), y(balls), r(balls), c(balls), dx(balls), dy(balls), a(balls), rr(balls), gg(balls), bb(balls)
  21. FOR i = 1 TO balls
  22.     r(i) = rand(10, 65)
  23.     x(i) = rand(r(i), xmax - r(i))
  24.     y(i) = rand(r(i), ymax - r(i))
  25.     c(i) = rand(1, 15)
  26.     dx(i) = rand(1, 5) * rdir
  27.     dy(i) = rand(1, 5) * rdir
  28.     rr(i) = rand(150, 255)
  29.     gg(i) = rand(150, 255)
  30.     bb(i) = rand(150, 255)
  31. Bplus = _NEWIMAGE(xmax, ymax, 32)
  32. WHILE _KEYDOWN(27) = 0
  33.     _DEST Bplus
  34.     CLS
  35.     FOR i = 1 TO balls
  36.         'ready for collision
  37.         a(i) = _ATAN2(dy(i), dx(i))
  38.         power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
  39.         imoved = 0
  40.         FOR j = i + 1 TO balls
  41.             IF SQR((x(i) - x(j)) ^ 2 + (y(i) - y(j)) ^ 2) < r(i) + r(j) THEN
  42.                 imoved = 1
  43.                 a(i) = _ATAN2(y(i) - y(j), x(i) - x(j))
  44.                 a(j) = _ATAN2(y(j) - y(i), x(j) - x(i))
  45.                 'update new dx, dy for i and j balls
  46.                 power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
  47.                 power = (power1 + power2) / 2
  48.                 dx(i) = power * COS(a(i))
  49.                 dy(i) = power * SIN(a(i))
  50.                 dx(j) = power * COS(a(j))
  51.                 dy(j) = power * SIN(a(j))
  52.                 x(i) = x(i) + dx(i)
  53.                 y(i) = y(i) + dy(i)
  54.                 x(j) = x(j) + dx(j)
  55.                 y(j) = y(j) + dy(j)
  56.                 EXIT FOR
  57.             END IF
  58.         NEXT
  59.         IF imoved = 0 THEN
  60.             x(i) = x(i) + dx(i)
  61.             y(i) = y(i) + dy(i)
  62.         END IF
  63.         IF x(i) < r(i) THEN dx(i) = -dx(i): x(i) = r(i)
  64.         IF x(i) > xmax - r(i) THEN dx(i) = -dx(i): x(i) = xmax - r(i)
  65.         IF y(i) < r(i) THEN dy(i) = -dy(i): y(i) = r(i)
  66.         IF y(i) > ymax - r(i) THEN dy(i) = -dy(i): y(i) = ymax - r(i)
  67.         FOR rad = r(i) TO 0 STEP -1
  68.             fcirc x(i), y(i), rad, _RGBA32(rr(i), gg(i), bb(i), 20)
  69.         NEXT
  70.     NEXT
  71.  
  72.     COLOR , _RGBA(0, 0, 0, 0)
  73.     FOR i = 1 TO 25
  74.         txt(i) = MID$(txt(i), v(i)) + MID$(txt(i), 1, v(i) - 1)
  75.         FOR l = 1 TO 80
  76.             IF i MOD 2 THEN midInk 60, 0, 0, 0, 0, 60, l / 80 ELSE midInk 0, 0, 60, 60, 0, 0, l / 80
  77.             LOCATE i, l: PRINT MID$(txt(i), l, 1);
  78.         NEXT
  79.     NEXT
  80.  
  81.     _DEST 0 'redirecting to text screen
  82.  
  83.     Himage = _COPYIMAGE(Bplus, 33)
  84.     _PUTIMAGE (0, 0)-(xmax, ymax), Himage, 0
  85.     _DISPLAY
  86.     _LIMIT 10
  87.     _FREEIMAGE Himage
  88.  
  89. FUNCTION rand (lo, hi)
  90.     rand = (RND * (hi - lo + 1)) \ 1 + lo
  91.  
  92. FUNCTION rdir ()
  93.     IF RND < .5 THEN rdir = -1 ELSE rdir = 1
  94.  
  95. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  96.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  97.     DIM X AS INTEGER, Y AS INTEGER
  98.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  99.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  100.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  101.     WHILE X > Y
  102.         RadiusError = RadiusError + Y * 2 + 1
  103.         IF RadiusError >= 0 THEN
  104.             IF X <> Y + 1 THEN
  105.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  106.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  107.             END IF
  108.             X = X - 1
  109.             RadiusError = RadiusError - X * 2
  110.         END IF
  111.         Y = Y + 1
  112.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  113.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  114.     WEND
  115.  
  116. SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  117.     COLOR _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  118.  
  119.  

EDIT: added the midInk effect with barely seen letters

 
Title: Re: gl shaders in text mode...
Post by: Petr on April 30, 2019, 04:04:35 pm
Hi. This is again 32bit mode, copyed to SCREEN 0 as background image when done :-D (none _DEST to text screen before print with LOCATE.) MidInk is maybe possible using also on text screen, but not with _RGB32, but _RGB. :-D
Title: Re: gl shaders in text mode...
Post by: PMACKAY on May 03, 2019, 01:34:49 am
My fav bplus is « Last Edit: April 29, 2019, 10:56:23 AM »


Awesome stuff (love the way it looks)