c# wglGetProcAdress and OpenGL extensions

How can I call an extension function ( like wglAllocateMemoryNV ) WITHOUT using an external C++ DLL or parser like CsGL?

I saw c# “delegates” to make function pointers… but I dont know if this is possible…

I know this is probably the MOST difficult ask you ever found…

I’m pretty sure C# doesn’t have direct support for OpenGL, it does Direct 3D though. So you will have to use a library some of kind. Or even mix languaged together like C# and managed c++. There is an article on codeproject.com that mixes C# with MFC with managed c++ for OpenGL rendering. It’s found here: http://www.codeproject.com/csharp/csOpenGL.asp

Delegates are type-safe function pointers in C#.

-SirKnight

“WITHOUT using an external C++ DLL or parser like CsGL”, hehe

btw, currently I have a full-funcitonal OpenGL class working in c#, but without the GL extensions like VAR, hp_occlusion_test …

Here is my idea… ( BUT doesn´t work, it´s only an “idea” ):

[CLSCompliantAttribute(false)]
unsafe protected delegate void* pwglAllocateMemoryNV(int size, float readFq, float writeFq, float priority);

[DllImport(OGLDLL),CLSCompliantAttribute(false)]protected static extern pwglAllocateMemoryNV wglGetProcAddress(string name);

pwglAllocateMemoryNV wglAllocateMemoryNV = new pwglAllocateMemoryNV(wglGetProcAddress(“wglAllocateMemoryNV”));

this code is compiled, but generate a “Function pointer was not created by a Delegate” runtime exception.

Is there any chance to make a c# delegate with a (void*) pointer instead the void*(int,float,float,float). I tryed a simple cast, but cant compile…

I really can´t explain why the extensions are called with a “call memorydirection obtained from wglGetProcAddress”… I think is better to export these functions directly from opengl32.dll… perhaps was a design error in the 199X years…

Hehe and why why why why why why have I to create BEFORE the RC to call wglGetProcAddress without fail???

DESIGN ERRORS!!

[This message has been edited by santyhammer (edited 06-10-2003).]

Hey SGI, Java/c#/perl/VB users wanna make programs with OpenGL, so pls do something … is it fair that we have to use a f…ing C++ DLL parser to use the openGL extensions? come on, that´s not serious. 3th parties can die (look at lokiG), and then… what? SGI should move for ya! There are tons of other programming languages that aren´t C/C++ … wrappers are evil, DLL hell is bad.

[This message has been edited by santyhammer (edited 06-10-2003).]

That would have make extension writers beholden to Microsoft. Consider that they haven’t upadted OpenGL32.dll, pretty much, since it came out. Would you like to still be stuck with GL 1.1?

This way, the interface to GL32.dll is constant, but extendable. Granted, it poses a problem for languages like C#, but you can get around this easily enough by building a Managed C++ project (maybe even an unmanaged one) that can get these function pointers for you.

If it helps, there’s a code snippet on the dotnet forums that shows how to use LoadLibrary and GetProcAddress from C# using a small piece of IL code. I haven’t looked in much detail but you may be able to use a similar approach for wglGetProcAddress?

Here’s the link -
http://groups.google.com/groups?hl=en&lr…SFTNGP10&rnum=4

Originally posted by santyhammer:
Hey SGI, Java/c#/perl/VB users wanna make programs with OpenGL, so pls do something …

Not sure about extensions, but you can use OpenGL with VB through this typelibrary or either OCX:
http://is6.pacific.net.hk/~edx/contents.htm

I tried it some time ago, and… it doesn’t seem to work better than C/C++ though…

[This message has been edited by matt_weird (edited 06-10-2003).]

I think the VB OCX doesn´t support advanced ogl1.4 extensions like NV_vertex_program2, NV_vertex_array_range2…

Rog, I´ll try the MSIL code. Looks like a good idea, thx.

[This message has been edited by santyhammer (edited 06-10-2003).]

What’s C# ?

got it partially! I can call any method by using IL language. The question is… how can I to call MSIL code inside c# without compiling a DLL outside my class? Can I do

public class myClass
{
protected bool Init()
{
DoSomething();
}

[useMSIL]
.method public static int32 wglAllocateMemoryNV ( native int pfn, int size, float rprio, float wprio, float prio )
{
ldarg.0 // push pfn
ldarg.1 // push size
ldarg.2 // push rprio
ldarg.3 // push wprio
ldarg.4 // push prio
calli unmanaged stdcall int32(int,float,float,float)
ret
}
}

???

How can I do a C+±style __asm in C# without invoking dynamically Reflection?

[This message has been edited by santyhammer (edited 06-10-2003).]

Originally posted by knackered:
What’s C# ?

C# is a VEEERY powerful programming language ( from Microsoft ). Looks like java, but it´s more powerful.

But pls, tell me how can I do a __asm(msil) in c#!!!

[This message has been edited by santyhammer (edited 06-10-2003).]

Originally posted by santyhammer:
I think the VB OCX doesn´t support advanced ogl1.4 extensions like NV_vertex_program2, NV_vertex_array_range2…

well, have you tried to email EDX, maybe he has some useful tips on it:

“Please send suggestions, bug reports, and such to: edx@pacific.net.hk

Well, I’ll email him, but really dont wanna use an external DLL/OCX wrapper and enter the DLL hell, OCX registration, VB/MSV7 dll copy to system32… i waaaaaant a PURE c# solution ( if exists, hehe ).

[This message has been edited by santyhammer (edited 06-10-2003).]

[This message has been edited by santyhammer (edited 06-10-2003).]

isn’t this what are you looking for:

public string AssemblerListingLocation {get; set;}

I think the AssemblerListingLocation is only for C/C++ tool… and not sure what is for, but looks like other thing than __asm(msil)…

Originally posted by santyhammer:
I think the AssemblerListingLocation is only for C/C++ tool… and not sure what is for, but looks like other thing than __asm(msil)…

heh, this seems to be for creating the asm listing file during the code compiling, so now i see it’s really not what you was looking for

so it seems the only way to use asm in C# – is to write a DLL(or whatever else you can connect to C# written in C/C++) wrapper incapsulating the inline assembler inside of it =) (The same goes to OpenGL )

C# is a VEEERY powerful programming language ( from Microsoft ). Looks like java, but it´s more powerful.

Or, put in a less enthusiastic, but more accurate, way, C# is a Java-like language that compiles to the .NET interpreter. As such, it has full access to all of the services provided by various .NET objects. The language itself is very similar to Java; what makes it a nice (Windows-specific) alternative is that it can be extended much easier than Java. Writing a .NET object is trivial compared to writing C/C++ extensions to Java.

i waaaaaant a PURE c# solution ( if exists, hehe ).

You do realize that, by now, you could have written a .NET object that provides access to all the extension functions you need? This is not a difficult undertaking.

And no, there is no pure C# solution; the language isn’t designed to handle this kind of thing.