vmelkon's picture

Visual Basic .NET

I downloaded and checked the instructions, I looked into the documentation and did a few web searches. I'm still not clear on what I'm suppose to do.
I'm using what MS called the Development Environment 2003.
So where do I put the files so that it will recognize code like OpenGL.GL.glEnable(GL_xxxxxx).

Also, I'm getting the impression that OpenTK is for C# only.
Do I have to use Tao. Isn't Tao old?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

SwapBuffers is a member function of GLControl, i.e. GLControl1.SwapBuffers().

vmelkon's picture

Thanks

vmelkon's picture

Hi, it seems that Mike O is right.
If I try to setup the GL states in the initialization function, it crashes.

Public Sub New()
 
        ' This call is required by the designer.
        InitializeComponent()
 
        ' Add any initialization after the InitializeComponent() call.
 
 
        'This is where the program starts
        GL calls here such as glEnable(GL_DEPTH_TEST)
 
 
    End Sub

This is not good. In the C++ Win32 world, we had a WM_CREATE message which we could handle.
In VB.NET, is the only way to wait for resize to be called?

Private Sub GlControl1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles GlControl1.Resize

the Fiddler's picture

Hook the 'Load' event of the *GLControl* and place your initialization logic there.

Alternatively, you could force the GLControl to be constructed, like this:

Public Sub New()
 
        ' This call is required by the designer.
        InitializeComponent()
 
        ' Add any initialization after the InitializeComponent() call.
        glControl1.CreateControl()
        ' GL calls are safe to make now
 
End Sub

Which feels a little hacky.

vmelkon's picture

This one didn't work but I left it there anyway
glControl1.CreateControl()

Hooking into the control's Load worked. I'll keep this solution.

A thing I noticed is that one of my functions says the GL version is 2.1.
This is weird since the same code in C++ and also in VB6 says GL 3.3.
Is OpenTK returning a fake value?

I am not creating a context with that modern wglCreateContextARB in my C++ and VB6.

the Fiddler's picture

Sorry, no idea.

OpenTK uses wglCreateContextAttribsARB if available and falls back to wglCreateContext if not. Maybe that's the source of the difference . You can see the code in Source/OpenTK/Platform/Windows/WinGLContext.cs.

c2woody's picture
Quote:

one of my functions says the GL version is 2.1.

Which function is that? In the code you posted anything below 3.0 is correct since you're requesting a non-3.x+ context.

vmelkon's picture

I guess something special is happening.

AftPeakTank's picture

Ok, so i came up with problems when i started to implementing the GlControl in a User Control.
Finally i got it work and i am posting the code.

Notes:

1. For some reason it seems better to inherit the glcontrol to a class and create in there your extra stuff
2. It seems also that the designer doesnt like a lot the new control soemtimes so i ended up adding the control programmatically. To have an idea of where it will be positioned, i use a panel to host it. So in my interface i see the panel in place of the new glcontrol
3. I am not a proffesional programmer and i luck a lot of knowledge. I hope i dotn have a lot of extra stuff and ugly stuff in my code.
4. You need:
1. A new class (aoGLControl.vb) that will inherit the glcotnrol
2. A form (Form1.vb) that will contain the new user control
3. A panel (Panel_aoGLControl_host) that will host the control

The code for the form is:

Imports OpenTK
Imports OpenTK.GLControl
Imports OpenTK.Platform
Imports OpenTK.Graphics.OpenGL
 
Public Class Form1
    Dim aoGLControl1 As New aoGLControl
 
 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' Initialisation Calls
        InitialiseAoGLControl()
 
    End Sub
 
 
 
#Region "Initialisation Routines"
 
    Private Sub InitialiseAoGLControl()
        ' Set Colors
        aoGLControl1.glBackColorProp = Color.Black
 
        ' Set Widths
 
        ' Set LineTypes
 
        ' Add the Control
        Panel_aoGLControl_host.Controls.Add(aoGLControl1)
        aoGLControl1.Dock = DockStyle.Fill
    End Sub
 
#End Region
 
 
End Class

The code for the new class (aoGLControl.vb)

Imports OpenTK
Imports OpenTK.Platform
Imports OpenTK.Graphics.OpenGL
 
Public Class aoGLControl
    Inherits GLControl
 
    Dim _STARTED As Boolean = False
 
 
#Region "Properties for the User"
 
    ' Background Color
    Private glbackcolor As Color
    Public Property glBackColorProp() As Color
        Get
            Return glbackcolor
        End Get
        Set(ByVal value As Color)
            glbackcolor = value
        End Set
    End Property
 
#End Region
 
 
 
 
 
 
    Private Sub aoGLControl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _STARTED = True
        GL.ClearColor(glbackcolor)
        SetupViewport()
    End Sub
 
    Private Sub aoGLControl_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        If Not _STARTED Then Return
        render()
    End Sub
 
    Private Sub ResizeGL()
        SetupViewport()
        Me.Invalidate()
    End Sub
 
    Private Sub SetupViewport()
        Dim w As Integer = Me.Width
        Dim h As Integer = Me.Height
        GL.MatrixMode(MatrixMode.Projection)
        GL.LoadIdentity()
        GL.Ortho(0, w, 0, h, -1, 1)
        GL.Viewport(0, 0, w, h)
    End Sub
 
    Private Sub render()
        ' Clear screen
        GL.Clear(ClearBufferMask.ColorBufferBit)
        GL.Clear(ClearBufferMask.DepthBufferBit)
 
        ' Here Pass the data of what it is to be drawn
        DrawLines()
 
        ' Draw it!!!!
        Me.SwapBuffers()
    End Sub
 
    Private Sub DrawLines()
        GL.MatrixMode(MatrixMode.Modelview)
        GL.LoadIdentity()
 
        'Add Translations   : ex. GL.Translate(x, 0, 0)
 
 
        'Add Rotations      : ex. GL.Rotate(rotation, Vector3.UnitZ)
 
 
        'Add Colors         : ex. GL.Color3(Color.Yellow)
 
 
 
        ' Add Geometry with above Translation/Rotation/Color
        GL.Begin(BeginMode.Triangles)   'Depending on type of object
 
 
        ' Add Geometry      : ex. GL.Vertex2(10, 20)
        '                         GL.Vertex2(100, 20)
        '                         GL.Vertex2(100, 50)
 
 
        GL.End()
    End Sub
 
 
 
End Class

Sorry for the unnecessary comments.
It Works like a charm for the moment.

Best Regards