Author Topic: gl shaders in text mode...  (Read 6068 times)

0 Members and 1 Guest are viewing this topic.

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
gl shaders in text mode...
« 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
MackyWhite

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: gl shaders in text mode...
« Reply #1 on: April 15, 2019, 08:56:28 pm »
Why text mode, and not 32bit graphical mode?  OpenGL lighting is clearly graphical.  :-)

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: gl shaders in text mode...
« Reply #2 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.  
« Last Edit: April 16, 2019, 03:25:21 pm by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: gl shaders in text mode...
« Reply #3 on: April 16, 2019, 05:25:03 pm »
Nice effect Petr!

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: gl shaders in text mode...
« Reply #4 on: April 27, 2019, 06:50:34 am »
that is cool... just now to work it out...
MackyWhite

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: gl shaders in text mode...
« Reply #5 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.  
« Last Edit: April 27, 2019, 07:53:51 am by Petr »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: gl shaders in text mode...
« Reply #6 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.

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: gl shaders in text mode...
« Reply #7 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

MackyWhite

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: gl shaders in text mode...
« Reply #8 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
« Last Edit: April 28, 2019, 01:48:29 pm by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: gl shaders in text mode...
« Reply #9 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.  
« Last Edit: April 28, 2019, 05:03:27 pm by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: gl shaders in text mode...
« Reply #10 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.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: gl shaders in text mode...
« Reply #11 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
« Last Edit: April 28, 2019, 05:24:45 pm by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: gl shaders in text mode...
« Reply #12 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:
  [ You are not allowed to view this attachment ]  

More smoke? :)


Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: gl shaders in text mode...
« Reply #13 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....
« Last Edit: April 28, 2019, 05:58:18 pm by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: gl shaders in text mode...
« Reply #14 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.