Author Topic: NEON PEN  (Read 6786 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: NEON PEN
« Reply #15 on: November 21, 2020, 11:24:52 pm »
LOL that's awesome B+! I love the dimming effect, it can be used on neon signs. :)

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: NEON PEN
« Reply #16 on: November 22, 2020, 03:03:52 am »
@TempodiBasic
There is a simpler way to draw circle in OpenGL

Code: QB64: [Select]
  1. _TITLE "Learning OpenGL" 'giving title to your window
  2. SCREEN _NEWIMAGE(600, 600, 32) 'creating a window of 600x600
  3.  
  4. 'This is our main loop
  5.     _LIMIT 40 'Adding this will prevent high cpu usage.
  6.  
  7. SUB _GL ()
  8.     'Here we'll put our OpenGL commands!
  9.  
  10.     _glViewport 0, 0, _WIDTH, _HEIGHT 'here _WIDTH() and _HEIGHT() gives the width and height of our window.
  11.     '_glClearColor 1, .5, 0, 1
  12.     _glClear _GL_COLOR_BUFFER_BIT
  13.  
  14.  
  15.     _glColor3f 1, 1, 1
  16.  
  17.     r = .5
  18.     _glBegin _GL_TRIANGLE_FAN
  19.     FOR i = 0 TO _PI(2) STEP .05
  20.         _glVertex2f COS(i) * r, SIN(i) * r
  21.     NEXT
  22.     _glEnd
  23.  
  24.     _glFlush
  25.  


For explanation, see GL_TRIANGLE_FAN section here - https://ashishkingdom.github.io/OpenGL-Tutorials/2d-shapes/
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 Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: NEON PEN
« Reply #17 on: November 22, 2020, 03:11:56 am »
@bplus gives us new IDEA! :D

Here is the dimming effect in GL
Code: QB64: [Select]
  1. _TITLE "NEON PEN"
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3.  
  4. TYPE vec2
  5.     x AS SINGLE
  6.     y AS SINGLE
  7.  
  8. REDIM SHARED vert(1024) AS vec2, max_v_index
  9. DIM SHARED rFactor!, gFactor!, bFactor!
  10. rFactor! = 0.5: gFactor! = 1: bFactor! = 0.5
  11.     CLS
  12.     PRINT "VRAM Usage : "; vram; "KB"
  13.     PRINT "Vertices Used : "; max_v_index; "/"; UBOUND(vert)
  14.     vram = (UBOUND(vert) * 4) / 1024
  15.         mx = _MOUSEX: my = _MOUSEY
  16.         px = mx: py = my
  17.         WHILE _MOUSEBUTTON(1) AND max_v_index < UBOUND(vert)
  18.             WHILE _MOUSEINPUT: WEND
  19.             mx = _MOUSEX: my = _MOUSEY
  20.             IF ABS(px - mx) >= ABS(py - my) THEN
  21.                 IF mx >= px THEN s = 1 ELSE s = -1
  22.                 FOR i = px TO mx STEP s
  23.                     vert(max_v_index).x = i
  24.                     vert(max_v_index).y = map(i, px, mx, py, my)
  25.                     max_v_index = max_v_index + 1
  26.                     IF max_v_index > INT(UBOUND(vert) * 0.8) THEN REDIM _PRESERVE vert(max_v_index * 2) AS vec2
  27.                 NEXT
  28.             ELSE
  29.                 IF my >= py THEN s = 1 ELSE s = -1
  30.                 FOR i = py TO my STEP s
  31.                     vert(max_v_index).x = map(i, py, my, px, mx)
  32.                     vert(max_v_index).y = i
  33.                     max_v_index = max_v_index + 1
  34.                     IF max_v_index > INT(UBOUND(vert) * 0.8) THEN REDIM _PRESERVE vert(max_v_index * 2) AS vec2
  35.                 NEXT
  36.  
  37.             END IF
  38.             px = mx: py = my
  39.             _LIMIT 30
  40.         WEND
  41.     END IF
  42.  
  43.     _LIMIT 60
  44.  
  45. SUB _GL ()
  46.     STATIC glInit, clock
  47.     clock = clock + 0.03
  48.     IF glInit = 0 THEN
  49.         glInit = 1
  50.  
  51.     END IF
  52.     'set the gl screen so that it can work normal screen coordinates
  53.     _glTranslatef -1, 1, 0
  54.     _glScalef 1 / 400, -1 / 300, 1
  55.  
  56.     _glEnable _GL_BLEND
  57.  
  58.     _glBlendFunc _GL_SRC_ALPHA, _GL_ONE
  59.     _glEnableClientState _GL_VERTEX_ARRAY
  60.     _glVertexPointer 2, _GL_FLOAT, 0, _OFFSET(vert())
  61.     FOR j = 1 TO 15
  62.         _glColor4f rFactor!, gFactor!, bFactor!, 0.009 + 0.03 * ABS(SIN(clock))
  63.         _glPointSize j
  64.         _glDrawArrays _GL_POINTS, 10, max_v_index
  65.     NEXT
  66.     _glFlush
  67.  
  68. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  69.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  70.  
  71.  
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: NEON PEN
« Reply #18 on: November 22, 2020, 07:24:40 am »
@Ashish
Hi thanks for suggestion but I must say you that I have already a good master for Opengl
and I have travelled already his lessons to this Website https://ashishkingdom.github.io/OpenGL-Tutorials/
Now I need to use Opengl and  to pass again in the OpenGl travel to learn and memorize better.
Ripetita iuvant.

PS:
is your that website, master of OpenGl? 
;-)
Programming isn't difficult, only it's  consuming time and coffee

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: NEON PEN
« Reply #19 on: November 22, 2020, 03:45:04 pm »
Today I found _GL_LINE_STRIP so I turned your Neon Pen into making lines. It's not the same neon-look as you had before, but it's just something to learn. I also upped the vert DIM by a lot more. I found out that CLS or even a giant black box using LINE doesn't clear the screen for some reason. I'm still learning this stuff. I had to change your SUB to use the new _GL_LINE_STRIP, I'll post all of the code below. I should probably say too that I'm sure there's a much easier way to make this lines program without using OpenGL and without Dimming the memory. Or at least something very similar. This is just an OpenGL example is all. First click once on the screen, then click again to make your first line. Every line after that is connected to the end of your older line.
But first I want to say that people can also change the width of your Neon Pen (not this lines example below) to make wider lines or drawings by just changing the SUB's line For j=1 to 15 to something like For j=1 to 25.

 
Code: QB64: [Select]
  1. _TITLE "Neon Lines"
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3.  
  4. TYPE vec2
  5.     x AS SINGLE
  6.     y AS SINGLE
  7.  
  8. REDIM SHARED vert(200024) AS vec2, max_v_index
  9. DIM SHARED rFactor!, gFactor!, bFactor!
  10. rFactor! = 0.5: gFactor! = 2.5: bFactor! = 0.5
  11.     'CLS
  12.     LOCATE 1, 1: PRINT "VRAM Usage : "; vram; "KB"
  13.     LOCATE 2, 1: PRINT "Vertices Used : "; max_v_index; "/"; UBOUND(vert)
  14.     vram = (UBOUND(vert) * 4) / 1024
  15.     a$ = INKEY$
  16.     IF a$ = CHR$(27) THEN END
  17.  
  18.     m = _MOUSEBUTTON(1)
  19.     IF m = -1 THEN
  20.         t = t + 1
  21.         px = mx: py = my
  22.         mx = _MOUSEX: my = _MOUSEY
  23.         IF t < 2 THEN GOTO notthistime:
  24.         'px = mx: py = my
  25.         WHILE m = -1 AND max_v_index < UBOUND(vert)
  26.             WHILE _MOUSEINPUT: WEND
  27.             mx = _MOUSEX: my = _MOUSEY
  28.             IF ABS(px - mx) >= ABS(py - my) THEN
  29.                 IF mx >= px THEN s = 1 ELSE s = -1
  30.                 FOR i = px TO mx STEP s
  31.                     vert(max_v_index).x = i
  32.                     vert(max_v_index).y = map(i, px, mx, py, my)
  33.                     max_v_index = max_v_index + 1
  34.                     'IF max_v_index > UBOUND(vert) THEN REDIM _PRESERVE vert(max_v_index * 2) AS vec2
  35.                 NEXT
  36.             ELSE
  37.                 IF my >= py THEN s = 1 ELSE s = -1
  38.                 FOR i = py TO my STEP s
  39.                     vert(max_v_index).x = map(i, py, my, px, mx)
  40.                     vert(max_v_index).y = i
  41.                     max_v_index = max_v_index + 1
  42.                     'IF max_v_index > UBOUND(vert) THEN REDIM _PRESERVE vert(max_v_index * 2) AS vec2
  43.                 NEXT
  44.             END IF
  45.             'px = mx: py = my
  46.             notthistime:
  47.             m = 0
  48.         WEND
  49.     END IF
  50.     _LIMIT 200
  51.  
  52. 'This sub was changed from points to lines.
  53. SUB _GL ()
  54.     STATIC glInit
  55.     IF glInit = 0 THEN
  56.         glInit = 1
  57.  
  58.     END IF
  59.     'set the gl screen so that it can work normal screen coordinates
  60.     _glTranslatef -1, 1, 0
  61.     _glScalef 1 / 400, -1 / 300, 1
  62.  
  63.     _glEnable _GL_BLEND
  64.     _glBlendFunc _GL_SRC_ALPHA, _GL_ONE
  65.     _glEnableClientState _GL_VERTEX_ARRAY
  66.     _glVertexPointer 2, _GL_FLOAT, 0, _OFFSET(vert())
  67.     FOR j = 1 TO 30
  68.         'For j=1 to 15
  69.         '_glColor4f rFactor!, gFactor!, bFactor!, 0.015
  70.         _glColor4f rFactor!, gFactor!, bFactor!, 0.06
  71.         _glPointSize j
  72.         '_glDrawArrays _GL_POINTS, 10, max_v_index
  73.         _glLineWidth 10
  74.         _glDrawArrays _GL_LINE_STRIP, 0, max_v_index
  75.     NEXT
  76.     _glFlush
  77.  
  78. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  79.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  80.  
« Last Edit: November 22, 2020, 03:46:35 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: NEON PEN
« Reply #20 on: November 22, 2020, 04:35:05 pm »
Here's what your Neon Pen looks like with the wider length I mentioned in my last post. Oh I also had to add more to the Dim for the vert's on this too.

Open - Neon Pen.png
* Open - Neon Pen.png (Filesize: 63.45 KB, Dimensions: 799x626, Views: 202)
« Last Edit: November 22, 2020, 04:36:23 pm by SierraKen »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: NEON PEN
« Reply #21 on: November 22, 2020, 06:55:19 pm »
@SierraKen
Hi I'm seeing that you like it!

if you want clear screen in Opengl you must 1. set the color of clearing (say Black _rgb32(0,0,0,255)) with _glclearcolor and after 2 use _glclear what (generally _gl_color_buffer_bit)
as here
Code: QB64: [Select]
  1.     _GLCLEARCOLOR 1, .5, 0, 1
  2.     _GLCLEAR _GL_COLOR_BUFFER_BIT
the 4th parameter is Alpha channel, so if you want to see as background normal graphic (that made by LINE and erased by CLS) you can use a lower value at the place of 1 (0-1  in Opengl 0-255 in standard graphic).

But all these are info taken from my Opengl master  here https://ashishkingdom.github.io/OpenGL-Tutorials/.

If you want to learn how to mix normal graphic and Opengl graphic you can see the demo posted by Steve here:  https://www.qb64.org/forum/index.php?topic=3254.msg125353#msg125353
but I warning you it is just a little advanced. ;-)
Programming isn't difficult, only it's  consuming time and coffee

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: NEON PEN
« Reply #22 on: November 22, 2020, 09:42:34 pm »
Thanks TempodiBasic, but I don't know much more OpenGL I'm going to do. I rarely stay with anything I jump in the middle of. But thanks for the info.