Using OpenGL extensions in Visual Basic

Anyone know the equivalent of wglGetProcAddress in Visual Basic? How would you go about accessing OpenGL extensions in a Visual Basic program…?

I’m not sure how to do exactly what you want, but I can give you some info you might not want to hear…

VB doesn’t have any real sense of function pointers the way C/C++ do. wglGetAddressProc requires use of function pointers. VB has an AddressOf operator, but I don’t think it’s going to help you with this, but I could be wrong.

I do a lot of programming with both VB and C++. (VB programming isn’t by choice, it’s what I use at work.) There are a lot of ugly things with VB that make it a less than ideal environment for using OpenGL. (The wglGetProcAddress is one example.)

the person who provides you the dll must provide you a fonction for all the extension plus a fonction like IsExtensionSupported(string) which says if an extension is supported or not.

If the extension is supported, than it is safe to use the provided fonction, if it is not supported, then it is not safe.

The fonctions exported to VB encapsulate the fonction pointers which should be set during the dll loading.

I am sure someone have written such a dll an API. If you browse around the web(www.google.com) you’ll probably find what you need. Or try asking on gamedev.net.

You don’t need your own DLL to use VB with OpenGL. There is a type-library available that uses OpenGL32.dll, and even if there wasn’t it’s easy enough to create your own (though time consuming.) An example of doing this with DescribePixelFormat would be this (pulled from API viewer).

Public Declare Function DescribePixelFormat Lib “gdi32” Alias “DescribePixelFormat” (ByVal hDC As Long, ByVal n As Long, ByVal un As Long, lpPixelFormatDescriptor As PIXELFORMATDESCRIPTOR) As Long

The problem is that extensions aren’t exported in OpenGL32.dll, so you can’t use that same mechanism to get them. I can’t really suggest trying to get them from the vendor specific DLLs for the following reasons:

a) It might not even be possible.
b) You’d need to do this for each vendor’s version, which is ugly, and since you can’t conditionally do this, your app may try to bind the function to a dll that doesn’t exist, which would probably result in your app crashing.

The AddressOf operator I mentioned before works for passing a function pointer for a callback function, but only if you are passing it as a parameter to the function, so it wouldn’t work for wglGetProcAddress.

The only real solution might be to use what Gorg suggests, by creating your own dll in C/C++ for getting those, but not to the extent he proposes since that really wouldn’t be necessary.

Any chance of VB.Net (VB7) being able to provide the functionality we’re looking for? From what I hear, it is now a truly OOP environment…

Not sure what version of VB you use, so this may not help but you never know.

You may be interested in this

http://www.devdept.com/code/oglf/index.php

Download the C# OpenGL Framework for .NET 2.0:

Take a look at the OpenGL.cs file, I have not used the extensions but it’s looks like the function ‘LoadExtensions’ may be of interest.

Of course its in C# but it’s not difficult to convert.

In fact I have made this ‘OpenGL.cs’ into a Class library (dll) and I use it in my VB project. I works just as well as if it was in a C# project, there are couple of edits needed due to case issues, but that’s it. Within 1 hour I had the full OpenGL implimenation at my fingure tips!!

Of course you will need to move to VS 2005, but this is a free download from Microsoft

Hope this is of help

Talyrond.

Oh well, 4 years later is better than never I suppose…

Hah, I didn’t even realize this thread was that old until sqrt[-1] pointed that out. :slight_smile:

Hmm, this thread was going on around april/may of 2001…I was just finishing (or just finshed) my second semester of college! :smiley:

How embarrassing!! I swear this thread was at the top of the list when I replied, but now I’m thinking I was looking at some search results!!