papageorge's picture

'OpenTK.Platform.Windows.Wgl' is not accessible in this context because it is 'Friend'.

Hello,

I am writting a project in visual basic using OpenGl. Previously I used to work with TAO but I decided to use openTK. My problem is that I can not use GDI and WGL because it throws this exception "'OpenTK.Platform.Windows.Wgl' is not accessible in this context because it is 'Friend'. ". I use the code as here : http://nio.astronomy.cz/vb/triangle_tao_control.zip. Bellow I show you where I have problem :

Imports OpenTK.Graphics.OpenGL
Imports OpenTK.Platform.Windows
Imports System
 
Module OpenGL
 
    Public Declare Sub ZeroMemory Lib "kernel32.dll" Alias "RtlZeroMemory" (ByVal Destination As Gdi.PIXELFORMATDESCRIPTOR, ByVal Length As Integer)
 
    Dim hRC As System.IntPtr
 
    Public Sub EnableOpenGL(ByVal ghDC As System.IntPtr)
        Dim pfd As PixelFormatDescriptor
        Dim PixelFormat As Integer
 
        ZeroMemory(pfd, Len(pfd))
        pfd.Size = Len(pfd)
        pfd.Version = 1
        pfd.Flags = PFD_DRAW_TO_WINDOW Or PFD_SUPPORT_OPENGL Or PFD_DOUBLEBUFFER
        pfd.PixelType = PFD_TYPE_RGBA
        pfd.ColorBits = 32
        pfd.DepthBits = 32
        pfd.StencilBits = 32
        pfd.LayerType = Gdi.PFD_MAIN_PLANE
 
        PixelFormat = Gdi.ChoosePixelFormat(ghDC, pfd)
 
        If PixelFormat = 0 Then
            MsgBox("Unable to retrieve pixel format")
            End
        End If
        If Not (Gdi.SetPixelFormat(ghDC, PixelFormat, pfd)) Then
            MsgBox("Unable to set pixel format")
            End
        End If
        hRC = Wgl.wglCreateContext(ghDC)
        If hRC.ToInt32 = 0 Then
            MsgBox("Unable to get rendering context")
            End
        End If
        If Not (Wgl.wglMakeCurrent(ghDC, hRC)) Then
            MsgBox("Unable to make rendering context current")
            End
        End If
 
    End Sub
 
    Sub DisableOpenGL()
        Wgl.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero)
        Wgl.wglDeleteContext(hRC)
    End Sub
 
End Module

thanks


Comments

Comment viewing options

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

OpenTK doesn't provide access to Wgl or Gdi.

Besides, the code you list is unnecessary in OpenTK. I assume you are using WinForms? In that case, just drag&drop an OpenTK.GLControl onto your main Form.

Alternatively, use a GameWindow or (more advanced and also unnecessary) create and attach a GraphicsContext to any window you like.

papageorge's picture

Ok. I tried to import the OpenTK.dll but it says that this component could not be loaded. Moreover There is not a OpenTK.GLControl class to import

the Fiddler's picture

More information, please!

Which version of OpenTK? What operating system? Have you added OpenTK.GLControl to your project references?

There is a comprehensive tutorial here: http://www.opentk.com/doc/chapter/2/glcontrol

papageorge's picture

I use windows vista openTK 1.0 and visual basic.net. Anyway I found the problem. Thanks for your help :)

c2woody's picture
papageorge wrote:

I use windows vista openTK 1.0 and visual basic.net. Anyway I found the problem. Thanks for your help :)

Would be nice if you posted the solution so the thread is not completely useless. Other people may benefit from this.

papageorge's picture

I do not believe that the post is completely useless :) I did what we discused. So as conclusion if you want I would say that :

OpenTK doesn't provide access to Wgl or Gdi and alternatively I could include the OpenTK.GLControl.dll file in order to use the GLControl component.