Author Topic: Deformed Sphere (3D)  (Read 7564 times)

0 Members and 1 Guest are viewing this topic.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Deformed Sphere (3D)
« Reply #15 on: July 08, 2019, 09:45:53 am »
@Petr
Well... You can render OpenGL context directly on software screen.
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: Deformed Sphere (3D)
« Reply #16 on: July 08, 2019, 09:54:23 am »
Really? So i try it again. My goal is therefore a screen with visible hardware elements and visible GLRender elements.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Deformed Sphere (3D)
« Reply #17 on: July 08, 2019, 10:04:37 am »
Yes. With _mem, you can copy OpenGL pixel data to main screen.
I already created a SUB RenderGLToSoftwareScreen which take the handle of destination image as argument.
In the below code, if you press the key, the gl context is retained on screen.

Code: QB64: [Select]
  1. 'OpenGL context capture example
  2. 'by Ashish Kushwaha
  3.  
  4. _TITLE "Rendering OpenGL Context on Software"
  5. SCREEN _NEWIMAGE(600, 600, 32)
  6.  
  7. DIM SHARED glAllow AS _BYTE
  8. DIM SHARED GL_Color_Buffer~%%(_WIDTH * _HEIGHT * 4 - 1)
  9. DIM SHARED keyHit AS LONG, BufferDone
  10.  
  11. BufferDone = 1
  12. ' CLS , _RGB(255,0,0)
  13. ' _DISPLAYORDER _SOFTWARE 'this is hide opengl screen
  14. glAllow = -1
  15.         _DISPLAY
  16.     _LIMIT 48
  17. LOOP UNTIL INKEY$<>""
  18.  
  19.  
  20. SUB _GL ()
  21.     STATIC fps AS LONG, tt#
  22.  
  23.     IF NOT glAllow THEN EXIT SUB
  24.        
  25.  
  26.  
  27.     _glClearColor 0, 0, 0, 1
  28.     _glClear _GL_COLOR_BUFFER_BIT
  29.  
  30.     _glMatrixMode _GL_MODELVIEW
  31.  
  32.     _glRotatef fps, 0, 0, 1
  33.  
  34.     _glBegin _GL_TRIANGLES
  35.  
  36.     _glColor3f 1, 0, 0
  37.     _glVertex2f 0, 1
  38.     _glColor3f 0, 1, 0
  39.     _glVertex2f -1, -1
  40.     _glColor3f 0, 0, 1
  41.     _glVertex2f 1, -1
  42.     _glEnd
  43.        
  44.          RenderGLToSoftwareScreen 0 : tt# = timer
  45.  
  46.     _glFlush
  47.  
  48.     fps = fps + 1
  49.  
  50. SUB RenderGLToSoftwareScreen (dest&)
  51.  
  52.     ' $CHECKING:OFF
  53.  
  54.     'storing GL Color Buffer in our  GL_Color_Buffer() array
  55.     _glReadBuffer _GL_BACK
  56.     _glPixelStorei _GL_UNPACK_ALIGNMENT, 1
  57.     _glReadPixels 0, 0, _WIDTH, _HEIGHT, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, _OFFSET(GL_Color_Buffer~%%())
  58.     DIM m AS _MEM, m2 as _MEM
  59.         tmp& = _NEWIMAGE(_width(dest&), _HEIGHT(dest&), 32)
  60.     m2 = _MEMIMAGE(tmp&) 'store it in memory
  61.         m = _MEM(GL_Color_Buffer~%%())
  62.         _MEMCOPY m, m.OFFSET, m.SIZE TO m2, m2.OFFSET
  63.        
  64.     _MEMFREE m
  65.         ' _CLEARCOLOR _RGBA(0,0,0,255), tmp&
  66.         _PUTIMAGE (0, _HEIGHT(dest&)-1)-(_width(dest&)-1, 0), tmp&, dest&
  67.         _MEMFREE m2
  68.         _FREEIMAGE tmp&
  69.  
  70.  
« Last Edit: July 08, 2019, 10:06:33 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 SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Deformed Sphere (3D)
« Reply #18 on: July 08, 2019, 10:25:49 am »
Yes. With _mem, you can copy OpenGL pixel data to main screen.
I already created a SUB RenderGLToSoftwareScreen which take the handle of destination image as argument.
In the below code, if you press the key, the gl context is retained on screen.

This content should probably be added as an option to _COPYIMAGE so that someone can easily copy a hardware image to a software screen.  Maybe someone with a little more free time than me, could look into the addition for us.   ;D
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Deformed Sphere (3D)
« Reply #19 on: July 08, 2019, 10:29:08 am »
This content should probably be added as an option to _COPYIMAGE so that someone can easily copy a hardware image to a software screen.  Maybe someone with a little more free time than me, could look into the addition for us.   ;D
That will be very cool and very useful, Steve.
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: Deformed Sphere (3D)
« Reply #20 on: July 08, 2019, 10:45:42 am »
Yes, but.... what objects depth? Is not accepted for Hardware images. Or is something wrong here? I add _DISPLAYORDER, so now is visible OpenGL content and Hardware layer. But objects depth is not accepted for hardware images (is always visible, even though the triangle that is in front of the hardware image should cover it.



Code: QB64: [Select]
  1. 'OpenGL context capture example
  2. 'by Ashish Kushwaha
  3.  
  4.  
  5. W = _WIDTH(img)
  6. H = _HEIGHT(img)
  7.  
  8.  
  9.  
  10.  
  11. _TITLE "Rendering OpenGL Context on Software"
  12. SCREEN _NEWIMAGE(800, 600, 32)
  13. PRINT "Software screen text"
  14. DIM SHARED glAllow AS _BYTE
  15. DIM SHARED GL_Color_Buffer~%%(_WIDTH * _HEIGHT * 4 - 1)
  16. DIM SHARED keyHit AS LONG, BufferDone
  17.  
  18. BufferDone = 1
  19. ' CLS , _RGB(255,0,0)
  20. _DISPLAYORDER _GLRENDER , _HARDWARE ', _SOFTWARE 'this is hide opengl screen
  21. glAllow = -1
  22.     'try insert hardware image
  23.     _MAPTRIANGLE (0, 0)-(W, 0)-(0, H), img TO(-3, 1, -5)-(-2, 1, -5)-(-3, -1, -5)
  24.     _MAPTRIANGLE (W, 0)-(0, H)-(W, H), img TO(-2, 1, -5)-(-3, -1, -5)-(-2, -1, -5)
  25.  
  26.     'is always visible, but the triangle is in smaller depth.
  27.     _DISPLAY
  28.     _LIMIT 48
  29.  
  30.  
  31. SUB _GL ()
  32.     STATIC fps AS LONG, tt#
  33.  
  34.     IF NOT glAllow THEN EXIT SUB
  35.  
  36.  
  37.  
  38.     _glClearColor 0, 0, 0, 1
  39.     _glClear _GL_COLOR_BUFFER_BIT
  40.  
  41.     _glMatrixMode _GL_MODELVIEW
  42.  
  43.     _glRotatef fps, 0, 0, 1
  44.  
  45.     _glBegin _GL_TRIANGLES
  46.  
  47.     _glColor3f 1, 0, 0
  48.     _glVertex3f 0, 1, -1
  49.     _glColor3f 0, 1, 0
  50.     _glVertex3f -1, -1, -1
  51.     _glColor3f 0, 0, 1
  52.     _glVertex3f 1, -1, -1
  53.     _glEnd
  54.  
  55.     RenderGLToSoftwareScreen 0: tt# = TIMER
  56.  
  57.     _glFlush
  58.  
  59.     fps = fps + 1
  60.  
  61. SUB RenderGLToSoftwareScreen (dest&)
  62.  
  63.     ' $CHECKING:OFF
  64.  
  65.     'storing GL Color Buffer in our  GL_Color_Buffer() array
  66.     _glReadBuffer _GL_BACK
  67.     _glPixelStorei _GL_UNPACK_ALIGNMENT, 1
  68.     _glReadPixels 0, 0, _WIDTH, _HEIGHT, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, _OFFSET(GL_Color_Buffer~%%())
  69.     DIM m AS _MEM, m2 AS _MEM
  70.     tmp& = _NEWIMAGE(_WIDTH(dest&), _HEIGHT(dest&), 32)
  71.     m2 = _MEMIMAGE(tmp&) 'store it in memory
  72.     m = _MEM(GL_Color_Buffer~%%())
  73.     _MEMCOPY m, m.OFFSET, m.SIZE TO m2, m2.OFFSET
  74.  
  75.     _MEMFREE m
  76.     ' _CLEARCOLOR _RGBA(0,0,0,255), tmp&
  77.     _PUTIMAGE (0, _HEIGHT(dest&) - 1)-(_WIDTH(dest&) - 1, 0), tmp&, dest&
  78.     _MEMFREE m2
  79.     _FREEIMAGE tmp&
  80.  
  81.  
  82.  
  83.  

« Last Edit: July 08, 2019, 10:47:59 am by Petr »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Deformed Sphere (3D)
« Reply #21 on: July 08, 2019, 10:54:00 am »
@Petr
What are you trying to say? Your code is working as expected.
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: Deformed Sphere (3D)
« Reply #22 on: July 08, 2019, 11:08:35 am »
It is a combination of 3D OpenGL and a combination of 3D hardware. This is not what I expect. If I combine both of these methods, I need the body that is closer to the screen to hide the body behind it. Regardless of the method it is assembled.
How we talked about at the beginning. Why did I make a ball through MAPTRIANGLE as a hardware image. I did it because I can't mix the Hardware method and the OpenGL method. Your program will display the OpenGL layer together with the hardware layer. It is well. To do this, I still need to compare the depth of the bodies and hide what is hidden behind the body closer. This would mean reading the Z-axis depths for the solids on both layers and writing only those to really see into the resulting layer.
You see, it's one complication after another. That's why I didn't choose OpenGL for the ball.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Deformed Sphere (3D)
« Reply #23 on: July 20, 2019, 08:55:00 am »
Yes, but.... what objects depth? Is not accepted for Hardware images. Or is something wrong here? I add _DISPLAYORDER, so now is visible OpenGL content and Hardware layer. But objects depth is not accepted for hardware images (is always visible, even though the triangle that is in front of the hardware image should cover it.



Code: QB64: [Select]
  1. 'OpenGL context capture example
  2. 'by Ashish Kushwaha
  3.  
  4.  
  5. W = _WIDTH(img)
  6. H = _HEIGHT(img)
  7.  
  8.  
  9.  
  10.  
  11. _TITLE "Rendering OpenGL Context on Software"
  12. SCREEN _NEWIMAGE(800, 600, 32)
  13. PRINT "Software screen text"
  14. DIM SHARED glAllow AS _BYTE
  15. DIM SHARED GL_Color_Buffer~%%(_WIDTH * _HEIGHT * 4 - 1)
  16. DIM SHARED keyHit AS LONG, BufferDone
  17.  
  18. BufferDone = 1
  19. ' CLS , _RGB(255,0,0)
  20. _DISPLAYORDER _GLRENDER , _HARDWARE ', _SOFTWARE 'this is hide opengl screen
  21. glAllow = -1
  22.     'try insert hardware image
  23.     _MAPTRIANGLE (0, 0)-(W, 0)-(0, H), img TO(-3, 1, -5)-(-2, 1, -5)-(-3, -1, -5)
  24.     _MAPTRIANGLE (W, 0)-(0, H)-(W, H), img TO(-2, 1, -5)-(-3, -1, -5)-(-2, -1, -5)
  25.  
  26.     'is always visible, but the triangle is in smaller depth.
  27.     _DISPLAY
  28.     _LIMIT 48
  29.  
  30.  
  31. SUB _GL ()
  32.     STATIC fps AS LONG, tt#
  33.  
  34.     IF NOT glAllow THEN EXIT SUB
  35.  
  36.  
  37.  
  38.     _glClearColor 0, 0, 0, 1
  39.     _glClear _GL_COLOR_BUFFER_BIT
  40.  
  41.     _glMatrixMode _GL_MODELVIEW
  42.  
  43.     _glRotatef fps, 0, 0, 1
  44.  
  45.     _glBegin _GL_TRIANGLES
  46.  
  47.     _glColor3f 1, 0, 0
  48.     _glVertex3f 0, 1, -1
  49.     _glColor3f 0, 1, 0
  50.     _glVertex3f -1, -1, -1
  51.     _glColor3f 0, 0, 1
  52.     _glVertex3f 1, -1, -1
  53.     _glEnd
  54.  
  55.     RenderGLToSoftwareScreen 0: tt# = TIMER
  56.  
  57.     _glFlush
  58.  
  59.     fps = fps + 1
  60.  
  61. SUB RenderGLToSoftwareScreen (dest&)
  62.  
  63.     ' $CHECKING:OFF
  64.  
  65.     'storing GL Color Buffer in our  GL_Color_Buffer() array
  66.     _glReadBuffer _GL_BACK
  67.     _glPixelStorei _GL_UNPACK_ALIGNMENT, 1
  68.     _glReadPixels 0, 0, _WIDTH, _HEIGHT, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, _OFFSET(GL_Color_Buffer~%%())
  69.     DIM m AS _MEM, m2 AS _MEM
  70.     tmp& = _NEWIMAGE(_WIDTH(dest&), _HEIGHT(dest&), 32)
  71.     m2 = _MEMIMAGE(tmp&) 'store it in memory
  72.     m = _MEM(GL_Color_Buffer~%%())
  73.     _MEMCOPY m, m.OFFSET, m.SIZE TO m2, m2.OFFSET
  74.  
  75.     _MEMFREE m
  76.     ' _CLEARCOLOR _RGBA(0,0,0,255), tmp&
  77.     _PUTIMAGE (0, _HEIGHT(dest&) - 1)-(_WIDTH(dest&) - 1, 0), tmp&, dest&
  78.     _MEMFREE m2
  79.     _FREEIMAGE tmp&
  80.  
  81.  
  82.  
  83.  
RenderGLToSoftwareScreen only copies the pixel color data of OpenGL context on the software screen. It does not copy the depth data.
Actually, it is my mistake. I gave wrong name to the SUB. It must be CopyGLPixelsToSoftware.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


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