mayor86's picture

VB.NET (mono) and Opengl Macos support

Hi, i'm trying to learn how i can write code in VB using opengl for linux,macos and windows.

I wrote this simple code:

Imports System
Imports OpenTK.Graphics.OpenGL
 
Public Class Form1
    Public x As Integer
    Friend WithEvents GlControl2 As GLControl
 
 
    Public Sub SetupViewport()
        Dim w As Double
        Dim h As Double
        w = GlControl2.Width
        h = GlControl2.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 Form1_Load(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Load
        Me.GlControl2 = New OpenTK.GLControl
        Me.Controls.Add(Me.GlControl2)
 
 
    End Sub
 
 
    Private Sub GlControl2_Load1(ByVal sender As Object, ByVal e As EventArgs) Handles GlControl2.Load
        SetupViewport()
    End Sub
 
    Private Sub GlControl2_Paint1(ByVal sender As Object, ByVal e As PaintEventArgs) Handles GlControl2.Paint
 
        GlControl2.BackColor = Color.Black
        GL.Clear(ClearBufferMask.ColorBufferBit Or ClearBufferMask.DepthBufferBit)
        GL.MatrixMode(MatrixMode.Modelview)
        GL.LoadIdentity()
        GL.Translate(x, 0, 0)
        If (GlControl2.Focused) Then
            GL.Color3(Color.Yellow)
        Else
            GL.Color3(Color.Blue)
        End If
        GL.Begin(BeginMode.Triangles)
        GL.Vertex2(10, 20)
        GL.Vertex2(100, 20)
        GL.Vertex2(100, 50)
 
        GlControl2.SwapBuffers()
        GL.End()
    End Sub
End Class

It works on windows.
On macos form1 starts (using mono) but opengl isn't inizialized.

I add Opentk.dll.config to the reference of the project and to the path of binary but it dont works...

Someone could help me plz? ty


Comments

Comment viewing options

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

What do you mean when you say it doesn't work? Any error message? What is output to the console?

I recall a bug on Mac OS which I think I never figured out to fix which was that the very first frame rendered to a context gets dropped, but all subsequent frames render fine. Since you don't have any kind of loop for rendering it may be that this is your problem.

mayor86's picture

In windows form1 shows a little yellow triangle. In mac os you can see this:

mayor86's picture

so none can help me? tnx

kanato's picture

See if you still have the same problem once your code is rendering more than just a single frame.

mayor86's picture

i think event GlControl2.Paint dont works in macos

do u know a tutorial that use opentk and mono in macos?

opentk it's a wonderfull project but i dont find a lot about development in macos platform.

tnx for your advice...

kanato's picture

GLControl.Paint works in Mac OS. Like I said, try running code that renders more than a single frame and see if it works.