Quick question about this. Probably a dumb question, because I've given it literally 3 seconds of thought:
Couldn't one just use p/Invoke to make calls directly into OpenGL32.dll? Seems like an ultra-thin wrapper of static methods could be made in this way, and you wouldn't need to wrap the whole thing -- just the gl functions that are needed, and one could add to it over time as the project progresses.
Laztrezort is pretty much spot on. Doing that is essentially proposing that you write an entirely NEW
OpenGL wrapper, instead of using a tried and true one and working on your engine. You'd get so caught up developing a good OpenGL wrapper that you'd never have time for the engine, must less a game (SlimDX, for example, is a full-time affair for it's extremely talented and genius founders and developers)... Interop can be a very sophisticated subject, especially dealing with low-level graphics APIs, hardware and drivers, etc. I've written a few successful/working wrappers, the largest of which is a semi-complete wrapper for the Win32 APIs most important and low-level functions, and includes a customizable and extensible memory management system more conducive to game development than standard memory management by the Standard C Library and C++ runtime. It handles large amounts of frequent
memory allocations and deallocations, unlike the standard malloc function and C++ constructors; it provides a new smart pointer system, customizable garbage collection, defragmentation (and compression), multi-threaded streaming and quite a few other things. It's nowhere near a commercial-grade product, but doing all of that took freakin forever
... Speaking from experience you must be a very competent C, C++ and C# programmer to write a good wrapper; that's why those are the main three languages I know (excluding x86/64 [Intel Syntax] assembly language). I wanted to learn how to do that stuff and understand it, and it took considerable effort in learning those three languages to even begin. Even when you know what to do and know you can work it out, it's a long road and a monumental amount of labor to consider taking on. At some point I've gotta finish an engine and develop games with it. That's why I just wanna find a very nice, complete and stable OpenGL wrapper (as SlimDX is to DirectX) and get on with the show!
Keep in mind that interop code can get a bit messy, needs to be done correctly to be performant, and you still do not have a math library (vectors, matrices), input & window management system for each native OS you want to support, and probably a multitude of other intricacies I don't know about. And, of course, you miss out on a system that has been tried and tested.
Not to say it wouldn't be an interesting excercise, or that such a system wouldn't fit the OP's purpose. I personally would not enjoy (i.e. probably would never finish) rolling my own wrapper.
Correct. To remain platform-agnostic, I've implemented all of my own math, and vectors, matrices and everything else. My types are implicitly convertible with their SlimDX counterparts, and will be likewise with their OpenGL counterparts when I choose a wrapper to stick with. So that wouldn't be a huge problem. What would be a massive problem is all the performance testing and diagnostics, debugging, design, etc. I must admit I'd probably end up giving up and wishing I'd spent the time on something else.
It would certainly be interesting to just try wrapping the basic parts of OpenGL and rendering a small scene or "mini-tri" example. Would indeed let you learn a lot about OpenGL and interop, and become a better all-around programmer. I think writing a basic operating system is another such exercise all programmers can benefit from.
Edited by ATC, 11 September 2012 - 10:27 PM.