Author Topic: Moving into the Matrix Rain  (Read 15396 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Moving into the Matrix Rain
« on: June 23, 2019, 07:30:08 am »
Hi everyone.
I was just inspire by Bplus's Matrix rain on this topic - https://www.qb64.org/forum/index.php?topic=1152.msg106362
So, I decided to create a similar matrix rain having depth effect.

Code: QB64: [Select]
  1. 'Moving into the Matrix Rain
  2. 'By Ashish Kushwaha
  3. '23 Jun, 2019
  4. '
  5. 'Inspire by B+ Matrix Rain.
  6. _TITLE "Moving into the Matrix Rain"
  7.  
  8.  
  9. SCREEN _NEWIMAGE(800, 600, 32)
  10.  
  11. TYPE matRain
  12.     x AS SINGLE 'x location
  13.     y AS SINGLE 'y location
  14.     z AS SINGLE 'z location
  15.     ay AS SINGLE 'rain velocity
  16.     strData AS STRING 'string data of each matrix rain
  17.  
  18. DIM SHARED charImg(74) AS LONG, matRainWidth, matRainHeight 'ascii char from 48 to 122, i.e, total 75 type of chars
  19. DIM SHARED glAllow AS _BYTE, matrixRain(700) AS matRain, matrixRainTex(74) AS LONG, mov
  20. matRainWidth = _FONTWIDTH * 0.005
  21. matRainHeight = _FONTHEIGHT * 0.005
  22. CLS , _RGB32(255)
  23. FOR i = 0 TO 74
  24.     charImg(i) = _NEWIMAGE(_FONTWIDTH * 5, _FONTHEIGHT * 5, 32)
  25.     _DEST tmp&
  26.     CLS , _RGBA(0, 0, 0, 0)
  27.     COLOR _RGB32(0, 255, 0), 1
  28.     _PRINTSTRING (0, 0), CHR$(i + 48)
  29.     _DEST charImg(i)
  30.     _PUTIMAGE , tmp&
  31.     _DEST 0
  32.  
  33.  
  34. glAllow = -1
  35.     FOR i = 0 TO UBOUND(matrixRain)
  36.         matrixRain(i).y = matrixRain(i).y - matrixRain(i).ay
  37.         IF RND > 0.9 THEN
  38.             d$ = ""
  39.             FOR k = 1 TO LEN(matrixRain(i).strData)
  40.                 d$ = d$ + CHR$(48 + p5random(0, 74)) 'change the character of rain randomly by a chance of 10%
  41.             NEXT
  42.             matrixRain(i).strData = d$
  43.         END IF
  44.         matrixRain(i).z = matrixRain(i).z + 0.00566 'move into the rain
  45.         IF matrixRain(i).z > 0.1 THEN 'when behind screen
  46.             matrixRain(i).x = p5random(-2, 2)
  47.             matrixRain(i).y = p5random(2, 3.7)
  48.             matrixRain(i).z = map((i / UBOUND(matrixRain)), 0, 1, -8, -0.2)
  49.             matrixRain(i).ay = p5random(0.006, 0.02)
  50.         END IF
  51.     NEXT
  52.     _LIMIT 60
  53.  
  54. SUB _GL ()
  55.     STATIC glInit
  56.     mov = mov + 0.01
  57.     IF NOT glAllow THEN EXIT SUB
  58.  
  59.     IF glInit = 0 THEN
  60.         glInit = 1
  61.  
  62.         FOR i = 0 TO UBOUND(matrixRainTex) 'create texture for each ascii character
  63.             _glGenTextures 1, _OFFSET(matrixRainTex(i))
  64.  
  65.             DIM m AS _MEM
  66.             m = _MEMIMAGE(charImg(i))
  67.  
  68.             _glBindTexture _GL_TEXTURE_2D, matrixRainTex(i)
  69.             _glTexImage2D _GL_TEXTURE_2D, 0, _GL_RGBA, _WIDTH(charImg(i)), _HEIGHT(charImg(i)), 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, m.OFFSET
  70.  
  71.             _MEMFREE m
  72.  
  73.             _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_NEAREST
  74.             _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_NEAREST
  75.             _FREEIMAGE charImg(i)
  76.         NEXT
  77.  
  78.         FOR i = 0 TO UBOUND(matrixRain) 'initialization
  79.             n = p5random(1, 15)
  80.             FOR j = 1 TO n
  81.                 v$ = CHR$(p5random(48, 122))
  82.                 matrixRain(i).strData = matrixRain(i).strData + v$
  83.             NEXT
  84.             matrixRain(i).x = p5random(-2, 2)
  85.             matrixRain(i).y = p5random(2, 3.7)
  86.             matrixRain(i).z = map((i / UBOUND(matrixRain)), 0, 1, -8, -0.2)
  87.             matrixRain(i).ay = p5random(0.006, 0.02)
  88.         NEXT
  89.  
  90.         _glViewport 0, 0, _WIDTH, _HEIGHT
  91.     END IF
  92.  
  93.     _glEnable _GL_BLEND 'enabling necessary stuff
  94.     _glEnable _GL_DEPTH_TEST
  95.     _glEnable _GL_TEXTURE_2D
  96.  
  97.  
  98.     _glClearColor 0, 0, 0, 1
  99.     _glClear _GL_COLOR_BUFFER_BIT OR _GL_DEPTH_BUFFER_BIT
  100.  
  101.  
  102.     _glMatrixMode _GL_PROJECTION
  103.     _gluPerspective 60, _WIDTH / _HEIGHT, 0.01, 10.0
  104.  
  105.     _glRotatef SIN(mov) * 20, 1, 0, 0 'rotating x-axis a bit, just to get Depth effect.
  106.  
  107.  
  108.     _glMatrixMode _GL_MODELVIEW
  109.  
  110.     'rendering the rain
  111.     FOR i = 0 TO UBOUND(matrixRain)
  112.         n = LEN(matrixRain(i).strData)
  113.         FOR j = 1 TO n
  114.             ca$ = MID$(matrixRain(i).strData, j, 1)
  115.             'selecting texture on the basis of ascii code.
  116.             _glBindTexture _GL_TEXTURE_2D, matrixRainTex(ASC(ca$) - 48)
  117.             _glBegin _GL_QUADS
  118.             _glTexCoord2f 0, 1
  119.             _glVertex3f matrixRain(i).x - matRainWidth, matrixRain(i).y - matRainHeight + 2 * (j - 1) * matRainHeight, matrixRain(i).z
  120.             _glTexCoord2f 0, 0
  121.             _glVertex3f matrixRain(i).x - matRainWidth, matrixRain(i).y + matRainHeight + 2 * (j - 1) * matRainHeight, matrixRain(i).z
  122.             _glTexCoord2f 1, 0
  123.             _glVertex3f matrixRain(i).x + matRainWidth, matrixRain(i).y + matRainHeight + 2 * (j - 1) * matRainHeight, matrixRain(i).z
  124.             _glTexCoord2f 1, 1
  125.             _glVertex3f matrixRain(i).x + matRainWidth, matrixRain(i).y - matRainHeight + 2 * (j - 1) * matRainHeight, matrixRain(i).z
  126.             _glEnd
  127.         NEXT
  128.     NEXT
  129.  
  130.     _glFlush
  131.  
  132. 'taken from p5js.bas
  133. 'https://bit.ly/p5jsbas
  134. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  135.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  136.  
  137.  
  138. FUNCTION p5random! (mn!, mx!)
  139.     IF mn! > mx! THEN
  140.         SWAP mn!, mx!
  141.     END IF
  142.     p5random! = RND * (mx! - mn!) + mn!
  143.  

Run the code & have fun. :)
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Moving into the Matrix Rain
« Reply #1 on: June 23, 2019, 07:49:09 am »
Very nice, Ashish!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Moving into the Matrix Rain
« Reply #2 on: June 23, 2019, 08:40:41 am »
Wow Ashish! nice work!

You could probably do a Star Wars crawl with 10 layers!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Moving into the Matrix Rain
« Reply #3 on: June 23, 2019, 09:11:38 am »
Nice one Neo...
Logic is the beginning of wisdom.

FellippeHeitor

  • Guest
Re: Moving into the Matrix Rain
« Reply #4 on: June 23, 2019, 09:19:49 am »
Wow! Just wow! 👏👏👏👏👏👏

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Moving into the Matrix Rain
« Reply #5 on: June 23, 2019, 10:30:27 am »
@Petr, @Bplus, @Johnno56, @FellippeHeitor
Thanks!!
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Moving into the Matrix Rain
« Reply #6 on: June 23, 2019, 11:09:35 am »
Ashish, I echo my esteemed colleagues in their praise.  Your mastery of OPEN_GL is to be envied (I certainly do!).  You remind me that I promised myself to learn some OPEN_GL (from your tutorials), but I seem content to stay in the simple 2D world (or possibly _MAPTRIANGLE(3D) on rare occasions).

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Moving into the Matrix Rain
« Reply #7 on: June 23, 2019, 02:15:34 pm »
@Qwerkey
don't mind it up! Give time to the time, here you must follow your flow, not a work timetable with checkpoints.
Think about me that I play chess from when I was fifteen and I have  always promised to me to go on in my attitute until to get the master level (about 2000-2200 ELO) and for now I range always about 1300(+-100)ELO . :-)
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Moving into the Matrix Rain
« Reply #8 on: June 23, 2019, 02:16:44 pm »
@Ashish
Hi I find it cool! Very Cool!
And I'm waiting for when you let me navigate into the matrix with keyboard input...
Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Moving into the Matrix Rain
« Reply #9 on: June 23, 2019, 04:18:41 pm »
Question:  Is the min/max check really needed in the function?


FUNCTION p5random! (mn!, mx!)
    IF mn! > mx! THEN
        SWAP mn!, mx!
    END IF
    p5random! = RND * (mx! - mn!) + mn!
END FUNCTION

Let’s say I send it the values 6,1 to generate a number from 1 to 6.  Let’s pseudo-solve it, without the swap.

p5random! = RND * (mx! - mn!) + mn!

P5 = RND * (1 - 6) + 6
P5 = RND * (-5) + 6

A random number will be generated from 0 to -4.9999999 (RND * -5).  Add 6 to that and we get a value between 6 and 1.0000001.

Swapping the values give a return range between 1 and 5.9999999, which is subtly different, but is that difference worth the conditional check inside a function which gets called multiple times in a loop?  Why bother with the speed bump in the program — especially since it just reduces possible functionality, in case the user might like to get results between 6 and 1, instead of between 1 and 6.

When it comes to this type of error-checking, I’d rather ignore  it, and trust it won’t make much difference even inside a program where the values accidentally get swapped.  No need to add automatic checks which I can manually code for, when truly necessary, myself. 

*********************

With that said, I doubt changing it would make much actual difference in execution speed here.  The values are hard-coded and the min is always less than the max, so that SWAP never actually takes place for us.  A single IF check takes very little time to execute, and without any swapping going on (Which can slow down performance by shuffling memory values.), the change in speed is going to be rather small...

(But, as Rho pointed out with the error-checking with arrays and $CHECKING:OFF, that minute delay can add considerable lag to performance, if called multiple times in large, inner loops.)

I’m just curious if it’s really necessary, or if it might be something you’d want to remove from the p5random function, since the variance in the results is so small, and since the check actually swaps values so rarely.  (In this program, it doesn’t swap them at all.)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Moving into the Matrix Rain
« Reply #10 on: June 24, 2019, 02:57:01 am »
Thanks TempodiBasic, Qwerky. Qwerky, I'm very sad that I'm not able to work a lot on this. You see I also code less now. The reason
is that now I'm in 11th standard. This is the crucial stage of my education. So, I'm focussing on that. Well, don't worry. I will definitely
complete the tutorials stuff in future.

@Steve
Yes, you are absolutely right. I didn't thought for about this in depth. BTW, The function was coded by FellippeHeitor. You can ask from him.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Marked as best answer by Ashish on February 25, 2020, 10:17:49 pm

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Moving into the Matrix Rain
« Reply #11 on: June 25, 2019, 11:53:23 am »
@Ashish
Hi I find it cool! Very Cool!
And I'm waiting for when you let me navigate into the matrix with keyboard input...
Here it is -
W/w for moving forward.
S/s for moving backward.
A/a for moving left.
D/d for moving right.
Code: QB64: [Select]
  1. 'Moving into the Matrix Rain
  2. 'MOD : Supports navigation from keyboard. For TempodiBasic (25 Jun, 2019)
  3. 'By Ashish Kushwaha
  4. '23 Jun, 2019
  5. '
  6. 'Inspire by B+ Matrix Rain.
  7. _TITLE "Moving into the Matrix Rain"
  8.  
  9.  
  10. SCREEN _NEWIMAGE(800, 600, 32)
  11.  
  12. TYPE matRain
  13.     x AS SINGLE 'x location
  14.     y AS SINGLE 'y location
  15.     z AS SINGLE 'z location
  16.     ay AS SINGLE 'rain velocity
  17.     strData AS STRING 'string data of each matrix rain
  18.  
  19. Type location
  20.         x as single
  21.         ' y as single
  22.         z as single
  23.  
  24. DIM SHARED charImg(74) AS LONG, matRainWidth, matRainHeight 'ascii char from 48 to 122, i.e, total 75 type of chars
  25. DIM SHARED glAllow AS _BYTE, matrixRain(700) AS matRain, matrixRainTex(74) AS LONG
  26. dim shared currLoc as location
  27.  
  28. matRainWidth = _FONTWIDTH * 0.005
  29. matRainHeight = _FONTHEIGHT * 0.005
  30. CLS , _RGB32(255)
  31. FOR i = 0 TO 74
  32.     charImg(i) = _NEWIMAGE(_FONTWIDTH * 5, _FONTHEIGHT * 5, 32)
  33.     _DEST tmp&
  34.     CLS , _RGBA(0, 0, 0, 0)
  35.     COLOR _RGB32(0, 255, 0), 1
  36.     _PRINTSTRING (0, 0), CHR$(i + 48)
  37.     _DEST charImg(i)
  38.     _PUTIMAGE , tmp&
  39.     _DEST 0
  40.  
  41.  
  42. glAllow = -1
  43.        
  44.         currLoc.z = 0 : currLoc.x = 0
  45.        
  46.         if _keydown(asc("w")) or _keydown(asc("W")) then currLoc.z = -1
  47.         if _keydown(asc("s")) or _keydown(asc("S")) then currLoc.z = 1
  48.         if _keydown(asc("a")) or _keydown(asc("A")) then currLoc.x = -1
  49.         if _keydown(asc("d")) or _keydown(asc("D")) then currLoc.x = 1
  50.        
  51.     FOR i = 0 TO UBOUND(matrixRain)
  52.         matrixRain(i).y = matrixRain(i).y - matrixRain(i).ay
  53.         IF RND > 0.9 THEN
  54.             d$ = ""
  55.             FOR k = 1 TO LEN(matrixRain(i).strData)
  56.                 d$ = d$ + CHR$(48 + p5random(0, 74)) 'change the character of rain randomly by a chance of 10%
  57.             NEXT
  58.             matrixRain(i).strData = d$
  59.         END IF
  60.         ' matrixRain(i).z = matrixRain(i).z + 0.00566 'move into the rain
  61.                 if currLoc.z = -1 then matrixRain(i).z = matrixRain(i).z + 0.00766
  62.                 if currLoc.z = 1 then matrixRain(i).z = matrixRain(i).z - 0.00766
  63.                 if currLoc.x = -1 then matrixRain(i).x = matrixRain(i).x + 0.00766
  64.                 if currLoc.x = 1 then matrixRain(i).x = matrixRain(i).x - 0.00766
  65.                
  66.         IF matrixRain(i).z > 0.1 or matrixRain(i).z<-8 or matrixRain(i).x>3 or matrixRain(I).x<-3 THEN 'when behind screen
  67.             matrixRain(i).x = p5random(-3, 3)
  68.             matrixRain(i).y = p5random(2, 3.7)
  69.             matrixRain(i).z = map((i / UBOUND(matrixRain)), 0, 1, -8, -0.2)
  70.             matrixRain(i).ay = p5random(0.006, 0.02)
  71.         END IF
  72.     NEXT
  73.     _LIMIT 60
  74.  
  75. SUB _GL ()
  76.     STATIC glInit
  77.     IF NOT glAllow THEN EXIT SUB
  78.  
  79.     IF glInit = 0 THEN
  80.         glInit = 1
  81.  
  82.         FOR i = 0 TO UBOUND(matrixRainTex) 'create texture for each ascii character
  83.             _glGenTextures 1, _OFFSET(matrixRainTex(i))
  84.  
  85.             DIM m AS _MEM
  86.             m = _MEMIMAGE(charImg(i))
  87.  
  88.             _glBindTexture _GL_TEXTURE_2D, matrixRainTex(i)
  89.             _glTexImage2D _GL_TEXTURE_2D, 0, _GL_RGBA, _WIDTH(charImg(i)), _HEIGHT(charImg(i)), 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, m.OFFSET
  90.  
  91.             _MEMFREE m
  92.  
  93.             _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_NEAREST
  94.             _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_NEAREST
  95.             _FREEIMAGE charImg(i)
  96.         NEXT
  97.  
  98.         FOR i = 0 TO UBOUND(matrixRain) 'initialization
  99.             n = p5random(1, 15)
  100.             FOR j = 1 TO n
  101.                 v$ = CHR$(p5random(48, 122))
  102.                 matrixRain(i).strData = matrixRain(i).strData + v$
  103.             NEXT
  104.             matrixRain(i).x = p5random(-3, 3)
  105.             matrixRain(i).y = p5random(2, 3.7)
  106.             matrixRain(i).z = map((i / UBOUND(matrixRain)), 0, 1, -8, -0.2)
  107.             matrixRain(i).ay = p5random(0.006, 0.02)
  108.         NEXT
  109.  
  110.         _glViewport 0, 0, _WIDTH, _HEIGHT
  111.     END IF
  112.  
  113.     _glEnable _GL_BLEND 'enabling necessary stuff
  114.     _glEnable _GL_DEPTH_TEST
  115.     _glEnable _GL_TEXTURE_2D
  116.  
  117.  
  118.     _glClearColor 0, 0, 0, 1
  119.     _glClear _GL_COLOR_BUFFER_BIT OR _GL_DEPTH_BUFFER_BIT
  120.  
  121.  
  122.     _glMatrixMode _GL_PROJECTION
  123.     _gluPerspective 60, _WIDTH / _HEIGHT, 0.01, 10.0
  124.  
  125.  
  126.     _glMatrixMode _GL_MODELVIEW
  127.  
  128.     'rendering the rain
  129.     FOR i = 0 TO UBOUND(matrixRain)
  130.         n = LEN(matrixRain(i).strData)
  131.         FOR j = 1 TO n
  132.             ca$ = MID$(matrixRain(i).strData, j, 1)
  133.             'selecting texture on the basis of ascii code.
  134.             _glBindTexture _GL_TEXTURE_2D, matrixRainTex(ASC(ca$) - 48)
  135.             _glBegin _GL_QUADS
  136.             _glTexCoord2f 0, 1
  137.             _glVertex3f matrixRain(i).x - matRainWidth, matrixRain(i).y - matRainHeight + 2 * (j - 1) * matRainHeight, matrixRain(i).z
  138.             _glTexCoord2f 0, 0
  139.             _glVertex3f matrixRain(i).x - matRainWidth, matrixRain(i).y + matRainHeight + 2 * (j - 1) * matRainHeight, matrixRain(i).z
  140.             _glTexCoord2f 1, 0
  141.             _glVertex3f matrixRain(i).x + matRainWidth, matrixRain(i).y + matRainHeight + 2 * (j - 1) * matRainHeight, matrixRain(i).z
  142.             _glTexCoord2f 1, 1
  143.             _glVertex3f matrixRain(i).x + matRainWidth, matrixRain(i).y - matRainHeight + 2 * (j - 1) * matRainHeight, matrixRain(i).z
  144.             _glEnd
  145.         NEXT
  146.     NEXT
  147.  
  148.     _glFlush
  149.  
  150. 'taken from p5js.bas
  151. 'https://bit.ly/p5jsbas
  152. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  153.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  154.  
  155.  
  156. FUNCTION p5random! (mn!, mx!)
  157. '    IF mn! > mx! THEN
  158. '        SWAP mn!, mx!
  159. '    END IF
  160.     p5random! = RND * (mx! - mn!) + mn!
  161.  
  162.  
« Last Edit: June 25, 2019, 11:54:29 am by Ashish »
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Moving into the Matrix Rain
« Reply #12 on: June 25, 2019, 07:40:04 pm »
Hi Ashish
very cool!

I find fantastic to move into the wood of falling letters...
and Neo has revelead to me the secret to win the Matrix....

If do you want to know it  read in the mirror the next sentence.

!etunimarofgnihtonoD

Programming isn't difficult, only it's  consuming time and coffee

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Star Wars Crawl
« Reply #13 on: June 26, 2019, 05:21:40 am »
...
You could probably do a Star Wars crawl with 10 layers!
Here is my try on making Star Wars crawl
Code: QB64: [Select]
  1. _TITLE "STARSWARS Opening crawl"
  2.  
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4.  
  5. DIM SHARED glAllow, text&, text2&, lines$(26)
  6. DIM SHARED starWars&
  7.  
  8. text& = _NEWIMAGE(256, 600, 32)
  9. text2& = _NEWIMAGE(256, 600, 32)
  10. starWars& = _NEWIMAGE(65, 17, 32)
  11.  
  12. _DEST starWars&
  13. _PRINTSTRING (0, 0), "STARWARS"
  14.  
  15. FOR i = 0 TO UBOUND(lines$)
  16.     READ a$
  17.     lines$(i) = a$
  18.  
  19. COLOR _RGB(0, 0, 255)
  20. centerPrint "A long time ago in galaxy far,", _WIDTH, 280
  21. centerPrint "far away...", _WIDTH, 308
  22. FOR i = 0 TO 255 STEP 5
  23.     LINE (0, 0)-(_WIDTH, _HEIGHT), _RGB32(0, 0, 0, i), BF
  24.     _DISPLAY
  25.     _DELAY 0.01
  26. _PUTIMAGE (_WIDTH / 2 - _WIDTH(starWars&) * 3, _HEIGHT / 2 - _HEIGHT(starWars&) * 3)-STEP(_WIDTH(starWars&) * 6, _HEIGHT(starWars&) * 6), starWars&
  27. FOR i = 0 TO 255 STEP 5
  28.     LINE (0, 0)-(_WIDTH, _HEIGHT), _RGB32(0, 0, 0, i), BF
  29.     _DISPLAY
  30.     _DELAY 0.01
  31.  
  32.  
  33. glAllow = -1
  34. COLOR _RGB(255, 220, 0), _RGBA(0, 0, 0, 0)
  35. y = 610
  36.  
  37.  
  38.     _DEST text&
  39.     CLS
  40.     COLOR _RGB(255, 220, 0), 1
  41.     FOR i = 0 TO UBOUND(lines$)
  42.         IF i = UBOUND(lines$) THEN COLOR _RGB(255, 0, 255)
  43.         _PRINTSTRING ((_WIDTH / 2) - (LEN(lines$(i)) * _FONTWIDTH) / 2, y + i * _FONTHEIGHT), lines$(i)
  44.     NEXT
  45.     y = y - 0.5
  46.     _LIMIT 60
  47. LOOP UNTIL y < -(UBOUND(lines$) - 1) * _FONTHEIGHT
  48.  
  49. DATA "It is a period of civil war"
  50. DATA "Rebel spaceships, striking"
  51. DATA "from a hidden base, have "
  52. DATA "won their first victory"
  53. DATA "against the evil Galactic"
  54. DATA "Empire."
  55. DATA ""
  56. DATA ""
  57. DATA "During the battle, rebel"
  58. DATA "spies managed to steel"
  59. DATA "secret plans to the Empire's"
  60. DATA "ultimate weapon, the DEATH"
  61. DATA "STAR, an armored space station"
  62. DATA "with enough to destroy an entire"
  63. DATA "planet."
  64. DATA ""
  65. DATA ""
  66. DATA "Pursued by the Empire's sinister"
  67. DATA "agents, Princess Leia races"
  68. DATA "home abroad her starship,"
  69. DATA "custodian of the stolen plans"
  70. DATA "that cansave her people and"
  71. DATA "restore the freedom to the galaxy"
  72. DATA ""
  73. DATA ""
  74. DATA ""
  75. DATA "QB64 Rocks!"
  76.  
  77. SUB centerPrint (t$, w, y)
  78.     _PRINTSTRING ((w / 2) - (LEN(t$) * _FONTWIDTH) / 2, y), t$
  79.  
  80. SUB _GL ()
  81.     STATIC glInit, tex&, texMem AS _MEM
  82.     IF NOT glAllow THEN EXIT SUB
  83.     IF glInit = 0 THEN
  84.         glInit = -1
  85.         _glViewport 0, 0, _WIDTH, _HEIGHT
  86.         texMem = _MEMIMAGE(text&)
  87.         _glGenTextures 1, _OFFSET(tex&)
  88.  
  89.     END IF
  90.  
  91.     _glEnable _GL_TEXTURE_2D
  92.     _glEnable _GL_DEPTH_TEST
  93.  
  94.  
  95.  
  96.     _glMatrixMode _GL_PROJECTION
  97.     _gluPerspective 60.0, _WIDTH / _HEIGHT, 0.01, 10
  98.  
  99.     _glMatrixMode _GL_MODELVIEW
  100.  
  101.     _glBindTexture _GL_TEXTURE_2D, tex&
  102.     _glTexImage2D _GL_TEXTURE_2D, 0, _GL_RGB, _WIDTH(texMem.IMAGE), _HEIGHT(texMem.IMAGE), 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, texMem.OFFSET
  103.     _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_LINEAR
  104.     _glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_LINEAR
  105.  
  106.     _glBegin _GL_QUADS
  107.     _glTexCoord2f 0, 1: _glVertex3f -0.4, -1, -0.5 'bottom left     #
  108.     _glTexCoord2f 1, 1: _glVertex3f 0.4, -1, -0.5 'bottom right     # Coordinates sign are same as in Cartesian Plane   (3D)
  109.     _glTexCoord2f 1, 0: _glVertex3f 0.4, 3, -7 'upper right       #
  110.     _glTexCoord2f 0, 0: _glVertex3f -0.4, 3, -7 ' upper left      #
  111.     _glEnd
  112.  
  113.  
  114.     _glFlush
  115.  
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Moving into the Matrix Rain
« Reply #14 on: June 26, 2019, 07:30:46 am »
Hi Ashish
 Cool!
on my Toshiba celeron with Win10 and QB64 1.3 it runs fine!

Just sometimes a bit of flickering  that I have not been able to correct pitching the _Limit's Value.

while some attempts to use an intermediate panel/canvas and _PutImage to avoid CLS (in my little experience CLS is against very fast graphic routines) give me strange results... it maybe that _gLfunctions are faster than _putimage!

Thanks to share.
Programming isn't difficult, only it's  consuming time and coffee