Author Topic: _DISPLAYORDER Query  (Read 1397 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
_DISPLAYORDER Query
« on: July 20, 2019, 03:19:37 am »
Hi. I have a question for developers. When you use the _DISPLAYORDER _SOFTWARE command, operations executed from SUB _GL are completely terminated. Probably because of the speed because it does not require the operation of the OpenGL part of the application when it is not visible. Is this my guess true? This, of course, makes it impossible to read the OpenGL screen using OpenGL commands to use it on the Software screen. I checked this assumption with a simple test. Without using the _DISPLAYORDER command, with the addition of SOUND 300, .1 to SUB _GL, the drawn tone was + OpenGL image. After adding _DISPLAYORDER _SOFTWARE, the tone was not and OpenGL image is logical unvisible. Unfortunately, when you need to generate an OpenGL context on a software screen, when you use _DISPLAYORDER _GLRENDER, _SOFTWARE (even in reverse order), the program ends up in white death - a white window and a Windows message that the program has stopped working.

So my question is this. How to run OpenGL in the background so it won't be visible when I want the software screen in the foreground but  _DISPLAYORDER probably turns off OpenGL traffic in SUB GL.

Unfortunately, _GLRENDER _BEHIND also causes an error - Windows quits the program with the message that the program has stopped working.
« Last Edit: July 20, 2019, 03:41:24 am by Petr »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
Re: _DISPLAYORDER Query
« Reply #1 on: July 20, 2019, 08:42:59 am »
Hi. I have a question for developers. When you use the _DISPLAYORDER _SOFTWARE command, operations executed from SUB _GL are completely terminated. Probably because of the speed because it does not require the operation of the OpenGL part of the application when it is not visible. Is this my guess true?
I think you are wrong. _DISPLAYORDER _SOFTWARE makes only the software layer to render on screen.
For example, if you use _DISPLAYORDER _GLRENDER then only OpenGL context will be rendered on the screen.

So my question is this. How to run OpenGL in the background so it won't be visible when I want the software screen in the foreground but  _DISPLAYORDER probably turns off OpenGL traffic in SUB GL.
Simply use _GLRENDER _BEHIND or _DISPLAYORDER _GLRENDER, _SOFTWARE

Unfortunately, _GLRENDER _BEHIND also causes an error - Windows quits the program with the message that the program has stopped working.
I am 75% sure that this error is not because of _GLRENDER _BEHIND. When using OpenGL, there are several factors which can be responsible
for the error.
For example, You can not use INPUT command when using SUB _GL. IDK why but it makes the program screen white.

Can you share the code?

« Last Edit: July 20, 2019, 08:45:36 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 Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: _DISPLAYORDER Query
« Reply #2 on: July 20, 2019, 09:34:49 am »
Hi Ashish, i am in Prague now, So i can post it later. Please look to your email, i post you Yesterday query with your code. In fact it Is this code add to my 3D object editor, which do this errors.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: _DISPLAYORDER Query
« Reply #3 on: July 20, 2019, 01:47:30 pm »
Hi again, Ashish.

I did other experiments with your code with the following result.
1) _DISPLAYORDER _SOFTWARE will definitely shut down _GL completely
2) _GLRENDER _BEHIND make off the previous _DISPLAYORDER _SOFTWARE call and turns it off, then the _GL part works. If the software screen contains a transparent background, then the OpenGL layer is also visible. This is fine (because also the hardware layer is visible even on the text screen).
3) Your program works perfectly, all I missed was _GLRENDER _BEHIND.
4) There is a strange behavior (and maybe it will cause the program to crash when used with my editor) if I add some software drawing to the main loop. It should be one, but it is not. In the enclosed code, uncomment the three rows with the CIRCLE and run it. After the first spin of OpenGL content, it begins to tear. The reason is unknown to me.

I reduced the output of your function for test, that really watching the software layer.

Code: QB64: [Select]
  1.  
  2. 'OpenGL context capture example
  3. 'by Ashish Kushwaha
  4.  
  5.  
  6. W = _WIDTH(img)
  7. H = _HEIGHT(img)
  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 _SOFTWARE '                                                         Easy  test.  IF is this row enabled, program do none sound. So i think, SUB _GL is ignored?  Comment this row, then is visible OpenGL Layer and program do sounds.
  21. glAllow = -1 '                                                                    Therefore my query.
  22. g = 1
  23.  
  24.     'if this three rows are enbled, program after time work very bad
  25.     '    f = f + g: IF f > 150 OR f < 1 THEN g = g * -1
  26.     '    IF SGN(g) = 1 THEN CIRCLE (_WIDTH / 2, _HEIGHT / 2), &HFFFF0000, f 'do something SOFTWARE
  27.     '   IF SGN(g) = -1 THEN CIRCLE (_WIDTH / 2, _HEIGHT / 2), &HFF000000, f 'do something SOFTWARE
  28.  
  29.     '    CLS , &H99000000 'in backgroud is visible OpenGL content
  30.     'CLS
  31.     LOCATE 1, 1: PRINT TIME$
  32.     ' _GLRENDER _BEHIND
  33.     _DISPLAY
  34.     _LIMIT 48
  35.  
  36.  
  37. SUB _GL ()
  38.     IF oldTimer <> INT(TIMER) THEN SOUND 355, .1: oldTimer = TIMER
  39.  
  40.     STATIC fps AS LONG, tt#
  41.  
  42.     IF NOT glAllow THEN EXIT SUB
  43.  
  44.  
  45.  
  46.     _glClearColor 0, 0, 0, 1
  47.     _glClear _GL_COLOR_BUFFER_BIT
  48.  
  49.     _glMatrixMode _GL_MODELVIEW
  50.  
  51.     _glRotatef fps, 0, 0, 1
  52.  
  53.     _glBegin _GL_TRIANGLES
  54.  
  55.     _glColor4f 1, 0, 0, .5
  56.     _glVertex3f 0, 1, -1
  57.     _glColor4f 0, 1, 0, .5
  58.     _glVertex3f -1, -1, -1
  59.     _glColor4f 0, 0, 1, .5
  60.     _glVertex3f 1, -1, -1
  61.     _glEnd
  62.  
  63.     RenderGLToSoftwareScreen 0: tt# = TIMER
  64.  
  65.     _glFlush
  66.  
  67.     fps = fps + 1
  68.  
  69. SUB RenderGLToSoftwareScreen (dest&)
  70.  
  71.     ' $CHECKING:OFF
  72.  
  73.     'storing GL Color Buffer in our  GL_Color_Buffer() array
  74.     _glReadBuffer _GL_BACK
  75.     _glPixelStorei _GL_UNPACK_ALIGNMENT, 1
  76.     _glReadPixels 0, 0, _WIDTH, _HEIGHT, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, _OFFSET(GL_Color_Buffer~%%())
  77.     DIM m AS _MEM, m2 AS _MEM
  78.     tmp& = _NEWIMAGE(_WIDTH(dest&), _HEIGHT(dest&), 32)
  79.     m2 = _MEMIMAGE(tmp&) 'store it in memory
  80.     m = _MEM(GL_Color_Buffer~%%())
  81.     _MEMCOPY m, m.OFFSET, m.SIZE TO m2, m2.OFFSET
  82.  
  83.     _MEMFREE m
  84.     ' _CLEARCOLOR _RGBA(0,0,0,255), tmp&
  85.     _DEST tmp&
  86.     _PRINTSTRING (_WIDTH / 2, _HEIGHT / 2), "Software"
  87.     _DEST 0
  88.     ' _PUTIMAGE (0, 0)-(_WIDTH(dest&) - 1, _HEIGHT(dest&) - 1), tmp&, dest&
  89.     _PUTIMAGE (0, 0)-(100, 100), tmp&, dest&
  90.     _MEMFREE m2
  91.     _FREEIMAGE tmp&
  92.     REDIM GL_Color_Buffer~%%(_WIDTH * _HEIGHT * 4 - 1)
  93.     '  $CHECKING:ON
  94.  
  95.  

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
Re: _DISPLAYORDER Query
« Reply #4 on: July 21, 2019, 12:58:40 am »
Hi Petr! Good Morning!
When using _DISPLAYORDER _SOFTWARE, the program does not call SUB _GL()
For example, try the following code -
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(600, 600, 32)
  2.     PRINT TIMER
  3.     _LIMIT 40
  4. SUB _GL ()
  5.     END
  6.  
If SUB _GL() was to be called in the above program, then the program must have been teriminated immediately.



I think it is natural to make silly mistake when coding for long hours.
Petr, You are using wrong syntax with CIRCLE command. The argument for radius comes before the color argument.
Here the correct code -
Code: QB64: [Select]
  1.  
  2. 'OpenGL context capture example
  3. 'by Ashish Kushwaha
  4.  
  5.  
  6. W = _WIDTH(img)
  7. H = _HEIGHT(img)
  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 _SOFTWARE '                                                         Easy  test.  IF is this row enabled, program do none sound. So i think, SUB _GL is ignored?  Comment this row, then is visible OpenGL Layer and program do sounds.
  21. glAllow = -1 '                                                                    Therefore my query.
  22. g = 1
  23.  
  24.     'if this three rows are enbled, program after time work very bad
  25.     f = f + g: IF f > 150 OR f < 1 THEN g = g * -1
  26.     IF SGN(g) = 1 THEN CIRCLE (_WIDTH / 2, _HEIGHT / 2), f, &HFFFF0000 'do something SOFTWARE
  27.     IF SGN(g) = -1 THEN CIRCLE (_WIDTH / 2, _HEIGHT / 2), f, &HFF000000 'do something SOFTWARE
  28.  
  29.     '    CLS , &H99000000 'in backgroud is visible OpenGL content
  30.     'CLS
  31.     LOCATE 1, 1: PRINT TIME$
  32.     ' _GLRENDER _BEHIND
  33.     _DISPLAY
  34.     _LIMIT 48
  35.  
  36.  
  37. SUB _GL ()
  38.  
  39.     IF oldTimer <> INT(TIMER) THEN SOUND 355, .1: oldTimer = TIMER
  40.  
  41.     STATIC fps AS LONG, tt#
  42.  
  43.     IF NOT glAllow THEN EXIT SUB
  44.  
  45.  
  46.  
  47.     _glClearColor 0, 0, 0, 1
  48.     _glClear _GL_COLOR_BUFFER_BIT
  49.  
  50.     _glMatrixMode _GL_MODELVIEW
  51.  
  52.     _glRotatef fps, 0, 0, 1
  53.  
  54.     _glBegin _GL_TRIANGLES
  55.  
  56.     _glColor4f 1, 0, 0, .5
  57.     _glVertex3f 0, 1, -1
  58.     _glColor4f 0, 1, 0, .5
  59.     _glVertex3f -1, -1, -1
  60.     _glColor4f 0, 0, 1, .5
  61.     _glVertex3f 1, -1, -1
  62.     _glEnd
  63.  
  64.     RenderGLToSoftwareScreen 0: tt# = TIMER
  65.  
  66.     _glFlush
  67.  
  68.     fps = fps + 1
  69.  
  70. SUB RenderGLToSoftwareScreen (dest&)
  71.  
  72.     ' $CHECKING:OFF
  73.  
  74.     'storing GL Color Buffer in our  GL_Color_Buffer() array
  75.     _glReadBuffer _GL_BACK
  76.     _glPixelStorei _GL_UNPACK_ALIGNMENT, 1
  77.     _glReadPixels 0, 0, _WIDTH, _HEIGHT, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, _OFFSET(GL_Color_Buffer~%%())
  78.     DIM m AS _MEM, m2 AS _MEM
  79.     tmp& = _NEWIMAGE(_WIDTH(dest&), _HEIGHT(dest&), 32)
  80.     m2 = _MEMIMAGE(tmp&) 'store it in memory
  81.     m = _MEM(GL_Color_Buffer~%%())
  82.     _MEMCOPY m, m.OFFSET, m.SIZE TO m2, m2.OFFSET
  83.  
  84.     _MEMFREE m
  85.     ' _CLEARCOLOR _RGBA(0,0,0,255), tmp&
  86.     _DEST tmp&
  87.     _PRINTSTRING (_WIDTH / 2, _HEIGHT / 2), "Software"
  88.     _DEST 0
  89.     ' _PUTIMAGE (0, 0)-(_WIDTH(dest&) - 1, _HEIGHT(dest&) - 1), tmp&, dest&
  90.     _PUTIMAGE (0, 0)-(100, 100), tmp&, dest&
  91.     _MEMFREE m2
  92.     _FREEIMAGE tmp&
  93.     REDIM GL_Color_Buffer~%%(_WIDTH * _HEIGHT * 4 - 1)
  94.     '  $CHECKING:ON
  95.  
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.
Re: _DISPLAYORDER Query
« Reply #5 on: July 21, 2019, 02:38:37 am »
Thank you Ashish for the answer. Such a mistake! :-D Okay. I have to study my program deeply, because it just has to work. It will definitely be some stupidity somewhere in the last code. Importantly, I have clarified for me,  how the OpenGL conversion program works for the Software Screen.