I have created a project in Gambas with components : gb.opengl, and gb.opengl.glu.
FOllowing the NeHe tutorials, I have the following code : (glArea1 is the form component for opegl applications.)
Public Sub GLArea1_Open()
gl.ClearDepth(100.0)
Gl.ClearColor(20, 40, 20, 0.70)
Gl.DepthFunc(Gl.LESS) ' The type of depth test to do
Gl.Enable(Gl.DEPTH_TEST) ' Enables depth testing
End
Public Sub GLArea1_Draw()
gl.Clear(gl.COLOR_BUFFER_BIT Or gl.DEPTH_BUFFER_BIT)
' Clear The Screen And The Depth Buffer
gl.Viewport(0, 0, GLArea1.Width, GLArea1.Height)
gl.MatrixMode(Gl.PROJECTION)
gl.LoadIdentity() 'Reset The Projection Matrix
gL.Translatef(0, GLArea1.Width / 2, 0)
gl.LineWidth(1.0)
gl.begin(gl.LINES)
gl.Color3f(1.0, 1.0, 0.2)
gl.Vertex3f(0, GLArea1.Height / 2, 0)
gl.Vertex3f(GLArea1.Width / 2, GLArea1.Height / 2, 0)
gl.End()
End
I would expect this code to draw a line, but the screen remains blank. A source archive is attached : http://www.filedropper.com/glline-001tar
How do I drAw lines in an openGl area in gambas 3? More specifically i want to start by drawing the Axes in the viewport. Please help.
Your vertices are most probably outside of your screen. If no projection is set, the visible coordinate range is from [-1,-1] to [1,1].
Maybe the confusion comes from the call to gl.Viewport, but this does not change the visible area. In general you get after applying all transformations and projections so called Normalized Device Coordinates (NDC). These coordinates range from [-1,-1,-1] to [1,1,1]. In this space now clipping happens and throws away everything outside of the valid range. The viewport transformation is now applied afterwards to the NDCs to get the final pixel coordinates.
In your case you can do two things: You can specify your line in NDC (-1 - 1 on each axis) or you can use a orthographic projection.
Another general comment: If there is no restriction on the used OpenGL version, you should definitely not use the fixed function pipeline (drawing with glBegin/...) anymore, since this methods are deprecated. You may want to look for a OpenGL > 3.2 Core Profile tutorial.