Author Topic: a mysmatched error in Opengl mode  (Read 2831 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
a mysmatched error in Opengl mode
« on: October 17, 2020, 07:01:01 pm »
Hi friends

I post here this experience to share results and thinking...

please copy this code and paste it into QB64 IDE
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.  
  3.  
  4.  
  5.  
  6. SUB gl ()
as you can see the IDE gives back this message of error
Syntax error on line 8 (or if you put the cursor on line 8 of the code : Syntax error on current line).
I think that this kind of error message can be lead to misunderstandment...
the real error is NOT the line 8 of code, but the line 7 in which the name of the SUB is wrong... just if you want type the sub of Opengl that is _GL() and not GL()....
BUT in this case why IDE doesn't give a more specific error message like keyword out of _GL() sub or You cannot place this here
Why is this correction  useful? For the same reason that the IDE advices the user if DATA instructions are in the wrong place.
Thanks to read
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: a mysmatched error in Opengl mode
« Reply #1 on: October 17, 2020, 07:20:33 pm »
Nothing wrong with your SUB gl.  The only problem is you don’t have a sub _gl

SCREEN _NEWIMAGE(800, 600, 32)
 
 
 
END
 
SUB gl ()
   _GLVIEWPORT(0,0,_WIDTH, _HEIGHT)
END SUB

SUB _GL
   gl
END SUB

I’m thinking the above should work without any issues, unless there’s perhaps a naming conflict.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: a mysmatched error in Opengl mode
« Reply #2 on: October 18, 2020, 09:51:12 am »
Some of these error codes are a treat to decipher. In this case "No sub _gl found" would more enlightning. I would guess that it may be a huge task to try and describe every possible error condition arising from a particular line of code but it does feel like, the more the language expands the less insightful the error code message.

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: a mysmatched error in Opengl mode
« Reply #3 on: October 25, 2020, 02:56:14 am »
Quote
Some of these error codes are a treat to decipher. In this case "No sub _gl found" would more enlightning. I would guess that it may be a huge task to try and describe every possible error condition arising from a particular line of code but it does feel like, the more the language expands the less insightful the error code message.

QB64's implementation of GL is a hack....the fact that we have to use a seperate sub to use GL calls makes coding GL projects quite tedious especially as we cant actually control when the GL sub is called only handle if it gets to do anything with an AllowGL variable. Also annoying is the fact that all variables that get used by the _GL sub need to be Shared or Stactic and as you've found out you cant overload the GL function!

Quote
the real error is NOT the line 8 of code, but the line 7
I've noticed this too, the error line always seems to be one line off.

If you're really interested in OpenGl and want to use it for more than anything basic i'd suggest coding in C++. If not i've attached the basic setup i use for all my GL programs and included a basic sample that renders a coloured triangle.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(400, 300, 32)
  2.  
  3.  
  4. _FPS 30 '    // Set maximium frames per second
  5.  
  6. DIM SHARED CamX!, CamY!, CamZ!, CamXRot%, CamYRot%, CamZRot%
  7.  
  8. '// Initial camera settings
  9. CamZ! = -10
  10.  
  11.   _LIMIT 30
  12.  
  13.  
  14.  
  15.  
  16. SUB _GL
  17.  
  18.   _glClearColor 0, 0, 0, 1 '// Set background (clear) color to black
  19.   _glClearDepth 1 '                 // Set clear depth value to farthest
  20.   _glEnable _GL_DEPTH_TEST '         // Enables depth buffer for hidden surface removal
  21.  
  22.   '// Setup a perspective view
  23.   _glMatrixMode _GL_PROJECTION
  24.   _gluPerspective 60, 400 / 300, .1, 400
  25.   _glMatrixMode _GL_MODELVIEW
  26.  
  27.   _glClear _GL_COLOR_BUFFER_BIT OR _GL_DEPTH_BUFFER_BIT '// Clear screen and depth buffers
  28.  
  29.   '// Set the view to the cameras position
  30.   _glRotatef CamXRot%, 1, 0, 0
  31.   _glRotatef CamYRot%, 0, 1, 0
  32.   _glRotatef CamZRot%, 0, 0, 1
  33.   _glTranslatef CamX!, CamY!, CamZ!
  34.  
  35.   '// Draw the triangle
  36.   _glBegin _GL_TRIANGLES
  37.   _glColor3f 1, 0, 0
  38.   _glVertex3f -1, -1, 0
  39.   _glColor3f 0, 1, 0
  40.   _glVertex3f 0, 1, 0
  41.   _glColor3f 0, 0, 1
  42.   _glVertex3f 1, -1, 0
  43.  
  44.  
  45.  
  46.  


Code: QB64: [Select]
  1. '// GDK_GL_2 Base Code - By John Onyon a.k.a Unseen Machine \\
  2. '/////////////////////////////////////////////////////////////////////////////////
  3.  
  4. REM $INCLUDE:'GDK_GL\GDK_GL.bi' '// Include a reference to the GDK_GL.bi library
  5. '/////////////////////////////////////////////////////////////////////////////////
  6.  
  7. DIM SHARED Mouse(1) AS MouseState, Kb(1) AS KeyBoardState '// For Input capture
  8. DIM SHARED CamVec AS VECTOR_GL, RadHelp#, Init_GL, Allow_GL AS _BYTE '// For Camera, Movement and GL initialisation
  9.  
  10. '// Initial Setup \\
  11. SCREEN _NEWIMAGE(800, 600, 32) '// Create a 32 bit screen
  12. _DISPLAY '// Turn off auto display
  13. _DISPLAYORDER _GLRENDER , _SOFTWARE '// Set the display to render GL stuff then Software stuff
  14. _FPS 30 '    // Set maximum frames per second
  15.  
  16. '// Define a variable to assist in first person camera movement caluclations
  17. RadHelp# = (4 * ATN(1)) / 180
  18.  
  19. '// Now everything is set up we can allow SUB _GL, first we initialise it. \\
  20. Init_GL = True
  21. Allow_GL = True
  22.  
  23.  
  24. '// Main program loop
  25.  
  26.  _LIMIT 30 '// Limit the loop to a maximum of 30 loops per second \\
  27.  
  28.  
  29.  '// Get the state off input devices \\
  30.  GDK_Mouse_GetState Mouse(0) '// Get the mouse state
  31.  GDK_Keyboard_GetState Kb(0) '// Get keyboard state
  32.  
  33.  '// Do game logic here \\
  34.  
  35.  
  36.  '// Copy the mousestate/keyboardstate for comparisons next loop \\
  37.  Mouse(1) = Mouse(0)
  38.  Kb(1) = Kb(0)
  39.  
  40.  
  41.  
  42. '// End of main program loop
  43.  
  44.  
  45. SUB _GL
  46.  
  47.  IF Allow_GL THEN
  48.  
  49.   _glClearColor 0, 0, 0, 1 '// Set background (clear) color to black
  50.   _glClearDepth 1 '         // Set clear depth value to farthest
  51.   _glEnable _GL_DEPTH_TEST '// Enables depth buffer for hidden surface removal
  52.   _glEnable _GL_TEXTURE_2D '// Allow Texturing
  53.  
  54.   '// Setup a perspective view
  55.   _glMatrixMode _GL_PROJECTION
  56.   _glLoadIdentity '// Reset the stack
  57.   _gluPerspective 80, 800 / 600, 1, 400 '// Field of view, Aspect ratio, near depth, far depth
  58.   _glMatrixMode _GL_MODELVIEW
  59.  
  60.   IF Init_GL = True THEN '// If GL is in initialisation mode (Loading stuff such as model and textures)
  61.  
  62.    '// Load everything here
  63.  
  64.  
  65.  
  66.    '// Change the GL mode setting
  67.    Init_GL = False
  68.  
  69.   ELSE '// GL is in
  70.  
  71.    '// Clear the depth buffer and reset the view matrix (effectively CLS)
  72.    GDK_GL_CLS
  73.  
  74.    '// Set enviroment to camera coordinates/Rotation
  75.    GDK_GL_VECTOR_APPLY_RT CamVec
  76.  
  77.   END IF
  78.  
  79.  
  80. '// library inclusions
  81. REM $INCLUDE:'GDK_GL\GDK_GL.BM'
  82. REM $INCLUDE:'UnseenGDK.bm'
  83.  
  84.  

Happy coding.

Unseen


Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: a mysmatched error in Opengl mode
« Reply #4 on: October 26, 2020, 06:19:58 pm »
Hi Unseen Machine

thanks for your feedbacks and suggestions coming out from your wide experience...
I must leave QB64 for C++ for a good OpenGl program! It is hard to choose.
For now I download you code posted here .

Surely I can affirm that my little experience in Opengl (I have used Opengl only now from within QB64) let me think OpenGl like a Batch language little flexible and much robust.
But maybe it appears so because in this manner is implemented into QB64...I'll discover this on going on
Programming isn't difficult, only it's  consuming time and coffee