Page 1 of 1

How to draw in a GLArea?

Posted: Sunday 17th March 2019 7:40pm
by jornmo
Hi!

Does anyone know how I can draw inside a GLArea? I tried some GL methods inside the GLArea's Draw event, but the area remains pitch black.
The farm has no examples, exept the ones using OpenGL combined with SDL, which is not what I want.
DuckDuckGo (ddg.gg) leaves me non the wiser as well...

I just want to experiment with some simple CAD drawing using OpenGL.

Re: How to draw in a GLArea?

Posted: Sunday 17th March 2019 8:53pm
by jornmo
I read some C++ examples and "figured it out".
' Gambas class file

Public Sub Form_Open()
  
  gl.ClearColor(0.0, 0.0, 0.0, 0.0)
  gl.Viewport(0, 0, 500, 500)
  gl.MatrixMode(gl.PROJECTION)
  gl.LoadIdentity()
  gl.Ortho(0, 500, 0, 500, 1, -1)
  gl.MatrixMode(gl.MODELVIEW)
  
End

Public Sub GLArea1_Draw()
  
  gl.Clear(gl.COLOR_BUFFER_BIT)
  gl.Begin(gl.LINES)
  gl.Vertex2i(-10, -10)
  gl.Vertex2i(250, 250)
  gl.End()
  gl.Flush()
  
End

Re: How to draw in a GLArea?

Posted: Sunday 17th March 2019 10:44pm
by Quincunxian
One of the best guides I found ages ago when I was experimenting with Open GL as from a guy called NeHe.
He wrote some of the examples for Gambas but like you, a search for "NeHe & Gambas" did not bring back much.

He does appear to have a bit more of a general site here.
and some legacy tutorials here but for windows - If you can translate from C to gambas it should provide some help.

Few posts on StackOverflow reference this as the best place to start.

I'm very interested in using OpenGL in Gambas.
I'm looking to be able to rotate in any dimension, a cluster of stars in a cubic area.
Also to display a simple textured wire frame of a item but again, from memory the G3 implementation did not have some of the more in-depth shader and texture processes translated when I was looking; but it was a few(several) years ago now.

Hope this helps.

Re: How to draw in a GLArea?

Posted: Monday 18th March 2019 9:00am
by jornmo
Hi Quin :)

Actually, NeHe is on the Farm. I used that for some insight on the GL code itself. But, it is cool seeing from where it came. Thanks!

It seeems when using the GLArea one needs to use .Begin() and .Flush() in addition to the code used in the NeHe app on the Farm. One also needs to be aware the the coordiante system is not '0, 0' in the top left corner. '0, 0' Is the middle of the screen. The coordinates are set in floats (there's probably a setting to get it in the normal mode. If not it is simple to write a function for that...), so the top left corner would be '-1, 1'.

Re: How to draw in a GLArea?

Posted: Monday 18th March 2019 11:39am
by jornmo
A good thing to notice is that 'Tracking' must be set to 'True' for the GLArea to receive MouseMove()ments.

Re: How to draw in a GLArea?

Posted: Monday 18th March 2019 11:42am
by jornmo
Quincunxian wrote: Sunday 17th March 2019 10:44pm
... from memory the G3 implementation did not have some of the more in-depth shader and texture processes translated when I was looking; but it was a few(several) years ago now.
It says in the documentation that the library/ies are fully supported as of now.

Re: How to draw in a GLArea?

Posted: Saturday 13th July 2019 7:20pm
by Technopeasant
Here is a bunch of code I had lying around for this. I really wish I had a version of my PS Tech alpha that worked from within QT 5, but have not had the wherewithal to try porting it myself from SDL.

http://icculus.org/~graham/Snippets/Too ... 0.1.tar.gz

I would also like to clarify that tommyline ported the NeHe examples to Gambas back in the day, and they were not posted by NeHe themselves. tommyline was a great help to me for as far as I have gotten with OpenGL, but he has since moved onto to coding in C++ for performance and more modern frameworks (OpenGL 2.1 is pretty much deprecated at this point).

Now a Vulkan component would be the bee's knees, but I guess one can only dream.