\
Now, the above is useful for folks who might want to use SUB _GL in a program and have encountered various issues. The problem is, some of our graphic commands and SUB _GL don't necessary play nice together. The simple solution around these issues is one like the above:
Turn off _GL drawing.
Do the problematic command (_SCREENMOVE _MIDDLE, _DESKTOPHEIGHT, _DESKTOPWIDTH, probably others)
Turn on _GL drawing.
It's simple and it seems to work for me without any real issues. If you're having trouble with these type commands, this might just be what you've been looking for and you didn't even know it.
And for those wanting to see the glitch in action, simply set the value of GL_on to anything non-zero, before calling that _SCREENMOVE _MIDDLE statement. The program will freeze up and do absolutely nothing for you.
Code: (Select All)
Screen _NewImage(640, 480, 32)
GL_Render 0 'don't render to GL, as the next command will lock up and freeze the program if you do
_ScreenMove _Middle
GL_Render -1 'turn that GL rendering back on
Do
_Limit 30 'A simple loop to see our GL display before ESC is hit
Loop Until _KeyDown(27)
Sub GL_Render (GL_go)
Select Case GL_go
Case 0 'disable GL rendering
_DisplayOrder _Software
Case -1 'enable GL rendering
_DisplayOrder _Software , _Hardware , _GLRender
End Select
_Delay .2
End Sub
Sub _GL
Static rtri, rquad
_glViewport 0, 0, _Width, _Height
_glMatrixMode _GL_PROJECTION ' Set projection matrix
_glLoadIdentity ' Matrix reset
_gluPerspective 45.0F, _Width / _Height, 0.1F, 100.0F ' Perspective calculation
_glMatrixMode _GL_MODELVIEW ' set modelview matrix
_glLoadIdentity
_glShadeModel _GL_SMOOTH ' allow smooth shading
_glClearColor 0.0F, 0.0F, 0.0F, 0.5F
_glClearDepth 1.0F ' set depth buffer
_glEnable _GL_DEPTH_TEST ' allow depth testing
_glDepthFunc _GL_LEQUAL ' set depth testing method
_glHint _GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ' set nicest projection matrix
_glClear _GL_COLOR_BUFFER_BIT: _glClear _GL_DEPTH_BUFFER_BIT 'clear screen and depth buffer
_glLoadIdentity ' matrix reset
' draw primitives here
_glTranslatef -1.5F, 0.0F, -6.0F ' Shift to the left and to the depth - be careful, every other shift on the screen moves from the place where we moved before!
_glRotatef rtri, 0.0F, 1.0F, 0.0F ' Rotate the triangle around the y-axis
_glBegin _GL_TRIANGLES ' The beginning of drawing the PYRAMID
_glColor3f 1.0F, 0.0F, 0.0F ' Red color (it is as _glColor3f Red, Green, Blue and values can be calculated as 1 / 255)
_glVertex3f 0.0F, 1.0F, 0.0F ' Upper point
_glColor3f 0.0F, 1.0F, 0.0F ' Green color
_glVertex3f -1.0F, -1.0F, 1.0F ' left bottom point
_glColor3f 0.0F, 0.0F, 1.0F ' blue color
_glVertex3f 1.0F, -1.0F, 1.0F ' right bottom point
_glColor3f 1.0F, 0.0F, 0.0F ' red color
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point (right wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue color
_glVertex3f 1.0F, -1.0F, 1.0F 'left point (right wall)
_glColor3f 0.0F, 1.0F, 0.0F ' green
_glVertex3f 1.0F, -1.0F, -1.0F ' right point (right wall) '
_glColor3f 1.0F, 0.0F, 0.0F ' red
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point (rear wall)
_glColor3f 0.0F, 1.0F, 0.0F ' green
_glVertex3f 1.0F, -1.0F, -1.0F ' left point (rear wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue
_glVertex3f -1.0F, -1.0F, -1.0F 'right point (rear wall)
_glColor3f 1.0F, 0.0F, 0.0F ' red
_glVertex3f 0.0F, 1.0F, 0.0F ' upper point (back wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue
_glVertex3f -1.0F, -1.0F, -1.0F 'left point (left wall)
_glColor3f 0.0F, 1.0F, 0.0F ' green
_glVertex3f -1.0F, -1.0F, 1.0F ' right point (left wall)
_glEnd 'triangle draw end
_glTranslatef 3.0F, 0.0F, 0.0F 'we will move in the x-axis by 1.5 to the center and 1.5 to the right, where we will paint a quad
'FOR THE ENTIRE OBJECT IN ONE COLOR:
_glLoadIdentity ' we call it to align the X Y Z axes to the original direction, without it it would default to the previous rotated state
_glTranslatef 1.5F, 0.0F, -7.0F ' The displacement of the origin is higher than in a quad
_glRotatef rquad, 1.0F, 1.0F, 1.0F 'Rotate the quad around the x-axis
_glBegin _GL_QUADS ' begin draw quad
_glColor3f 0.0F, 1.0F, 0.0F ' green color
_glVertex3f 1.0F, 1.0F, -1.0F ' left upper point
_glVertex3f -1.0F, 1.0F, -1.0F ' right upper point
_glVertex3f -1.0F, 1.0F, 1.0F ' right bottom point
_glVertex3f 1.0F, 1.0F, 1.0F ' left bottom point
_glColor3f 1.0F, 0.5F, 0.0F ' orange color
_glVertex3f 1.0F, -1.0F, 1.0F ' right upper point (bottom wall)
_glVertex3f -1.0F, -1.0F, 1.0F ' left upper point (bottom wall)
_glVertex3f -1.0F, -1.0F, -1.0F ' left bottom point (bottom wall)
_glVertex3f 1.0F, -1.0F, -1.0F ' right bottm point (bottom wall)
_glColor3f 1.0F, 0.0F, 0.0F ' red
_glVertex3f 1.0F, 1.0F, 1.0F ' right upper point (front wall)
_glVertex3f -1.0F, 1.0F, 1.0F ' Left upper point (front wall)
_glVertex3f -1.0F, -1.0F, 1.0F ' left bottom point (front wall)
_glVertex3f 1.0F, -1.0F, 1.0F ' right bottom point (front wall)
_glColor3f 1.0F, 1.0F, 0.0F ' yellow
_glVertex3f 1.0F, -1.0F, -1.0F ' right upper point (rear wall)
_glVertex3f -1.0F, -1.0F, -1.0F ' left upper point (rear wall)
_glVertex3f -1.0F, 1.0F, -1.0F ' left bottom point (rear wall)
_glVertex3f 1.0F, 1.0F, -1.0F ' right bottom point (rear wall)
_glColor3f 0.0F, 0.0F, 1.0F ' blue
_glVertex3f -1.0F, 1.0F, 1.0F ' right upper point (left wall)
_glVertex3f -1.0F, 1.0F, -1.0F ' left upper point (left wall)
_glVertex3f -1.0F, -1.0F, -1.0F ' left bottom point (left wall)
_glVertex3f -1.0F, -1.0F, 1.0F ' right bottom point (left wall)
_glColor3f 1.0F, 0.0F, 1.0F ' purple
_glVertex3f 1.0F, 1.0F, -1.0F ' right upper point (right wall)
_glVertex3f 1.0F, 1.0F, 1.0F ' left upper point (right wall)
_glVertex3f 1.0F, -1.0F, 1.0F 'Left bottom point (right wall)
_glVertex3f 1.0F, -1.0F, -1.0F 'Right bottom point (right wall)
_glEnd 'quad draw end
rtri = rtri + 0.52F 'Incrementing the angle of rotation of the triangle
rquad = rquad - 0.515F 'Incrementing the angle of rotation of the quad
'it is important to RESET THE AXES so that they are rotated to the basic setting (otherwise the X axis can move to the Y axis) using _glLoadIdentity,
'and it is EXTREMELY IMPORTANT to always move in the scene to the beginning of the scene using _glTranslateF
'moving the object in openGL is not done by recalculating _glVertex, but by moving the start of rendering using _glTranslatef
End Sub
Now, the above is useful for folks who might want to use SUB _GL in a program and have encountered various issues. The problem is, some of our graphic commands and SUB _GL don't necessary play nice together. The simple solution around these issues is one like the above:
Turn off _GL drawing.
Do the problematic command (_SCREENMOVE _MIDDLE, _DESKTOPHEIGHT, _DESKTOPWIDTH, probably others)
Turn on _GL drawing.
It's simple and it seems to work for me without any real issues. If you're having trouble with these type commands, this might just be what you've been looking for and you didn't even know it.
And for those wanting to see the glitch in action, simply set the value of GL_on to anything non-zero, before calling that _SCREENMOVE _MIDDLE statement. The program will freeze up and do absolutely nothing for you.