A OpenGL for .NET 2.0 header(alpha)

Hello,

I just finished the OpenGL header for .NET I was working on the last weekend. If you work with .NET, maybe you will be so kind to look on it and tell your opinion. I know that there are already some libraries like tao(but only for .NET 1.1) and this another toolkit for .NET 2.0, but my library features platform-independent rendering context support(with unified pixelformat/visual handling). All you need is a handle of your window. Support for linux is not there yet, but it will(i’t a half of hour work, but I have no linux installed to do it now :frowning: )

Features:

  • Supports ALL extensions ever
  • Platform-independent rendering contexts
  • Usable with Windows.Forms
  • for .NET 2.0 only
  • nice object-oriented syntax(all prefixes and suffixes stripped, the extension name is the class name)

Todo:

  • linux support
  • the pointer handling for arrays. Currently you must use custom marshalling

The Visual Studio C# solution(I simply zipped everything) is here

There is a small demo program included, but it doesn’t render anything. It just shows you how to do the setup.

I would love to hear some comments :slight_smile:

Have you tried this with C++/CLI yet? It seems I can’t do this:

ManagedGL::Configuration ^c1 = gcnew GLServer::SelectConfiguration( Select );
RenderingContext ^rc = gcnew RenderingContext::CreateContext( c1 );

I don’t know a lot about C++/CLI though. I don’t have Visual C# 2005 installed so I was hoping to get this to work with C++/CLI. I wouldn’t think this dll of yours would be C# only since it’s .net…

Hm, what does it say(i mean errors and such)? The ManagedGL.dll should be a valid .NET 2.0 assembly. Maybe you have .NET 1.1 installed? I am pretty new to .NET myself :wink: and I don’t know all the tricks yet… Maybe I’ll have to make it CLI-compliant…
You can download a free copy of visual studio here , if you need it… I did :wink:

Oh sorry, I was in a rush to leave so I forgot to put the errors, lol. I have Visual C++ 2005 express installed. I do have C# 2005 but not installed. :slight_smile: So I would think by having C++ 2005 I do have .net 2.0.

Anyway, the errors are:

error C2061: syntax error : identifier ‘SelectConfiguration’
error C2061: syntax error : identifier ‘CreateContext’

error C2039: ‘Accelerated’ : is not a member of ‘ManagedGL::Configuration’

etc…

The last error there (there’s more related to that actually) has to do with the Select function.

I guess I’ll just have to install C# 2005 anyway. :wink:

EDIT: Just for completion, here is my class I made.

ref class InitGL
{
public:

	static void Init()
	{
		ManagedGL::Configuration ^c1 = gcnew GLServer::SelectConfiguration( Select );
		RenderingContext ^rc = gcnew RenderingContext::CreateContext( c1 );

		Control ^co = gcnew Control();

		rc->MakeCurrent( co->Handle );

		GL::Load(11);
	}	

private:

	static bool Select( ManagedGL::Configuration ^c )
	{
		return c->Accelerated && 
                      (c->Depth >= 16) && 
                      (c->Stencil == 0) && 
                      (c->ColorAlpha == 0) && 
                      c->DoubleBuffer;
	}
};

-SirKnight

Try this one ManagedGL.dll

I recompiled it with CLS compliancy, hovewer, i run in some troubles :frowning: I had to place all tokens in GL.Tokens for a while, because they where colliding with the function names. I’ll se what I can do about it. Hovewer, I managed to use the library with chrome(a pascal .net compiler) so I guess it should be compartible now.
A stupid question: you did put the library as reference to your accembly, did you(I’m shure you did, but anyway…)

Originally posted by Zengar:
A stupid question: you did put the library as reference to your accembly, did you(I’m shure you did, but anyway…)
Yes I did.

I tried the new dll and now the only errors are the first two I mentioned. The others went away. For some reason SelectConfiguration and CreateContext give errors. It must be something with how C++/CLI does things. I’ll keep at it. I’m getting a big C++/CLI book next week in the mail so perhaps I’m just not doing something quite right. I really would like to use your dll. :slight_smile:

-SirKnight

What’s weird is that when I type the :: after GLServer or RenderingContext intellisence comes up and shows me these two functions in the menu box. I really don’t know.

Oh, I guess I know it now(I didn’t see it at the first time)

The gnew operator creates a new object, right? In that case, delete it - the methods are static and they return valid objects already. Maybe I’ll have to change the syntax a bit :-/

Ah, hmm. I wonder why I had gcnew in there. Weird. Maybe since I knew to use the ^ operator I thought I needed a gcnew. Now I look at your C# example I see no new. Doh!

Anyway taking out the gcnew got rid of those errors. Now it doesn’t like me passing the Select function to SelectConfiguration. So I’m working on figuring out why I’m getting the can’t convert from blah to blah error.

Alright it looks like that unlike in C#, I have to do this:

GLServer::SelectConfiguration( gcnew GLServer::ConfigurationValidator( &Select ) );

Kinda crazy looking but it works.

Here is my C++/CLI code for reference:

namespace MyGL
{
	using namespace ManagedGL;

	// ------------------------

	public ref class InitGL
	{
	public:

		static void Init()
		{
			ManagedGL::Configuration	^c1 = GLServer::SelectConfiguration( gcnew GLServer::ConfigurationValidator( &Select ) );
			RenderingContext			^rc = RenderingContext::CreateContext( c1 );

			Control ^co = gcnew Control();

			rc->MakeCurrent( co->Handle );

			GL::Load(11);
		}	

	private:	

		static bool Select( ManagedGL::Configuration ^c )
		{
			return c->Accelerated && (c->Depth >= 16) && (c->Stencil == 0) && (c->ColorAlpha == 0) && c->DoubleBuffer;
		}
	};
}

[STAThreadAttribute]
int main( array<System::String ^> ^args )
{
	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault( false ); 

	MyGL::InitGL::Init();

	// Create the main window and run it
	Application::Run( gcnew Form1() );

	return 0;
}

Now I’ll figure out how to render something to my form. :slight_smile:

Wow, C++ makes the things really messy :-/

Just for info: GL.Load(int) takes a parameter that specifies the OpenGL core version to be loaded.

I will update the headers currently to solve some troubles with names