« oh, the joy won't stop. | Main | Windows Programming Sucks »
Friday
May272005

progress with windows and opengl... towards a solution!

SharpGL works, and I'm learning about how to call unmanaged C++ from managed C#. It's all about loading libraries and those windows-specific tags. First there's a class, Imports, whose job is specifying and importing all the dll's, and establishing the structure of a few important types, such as PixelFormat. With that accomplished, a class called SharpGL.SceneGraph.OpenGL imports most of the OpenGL functions, and then wraps them with a public interface.

This line, from SharpGL...


public class OpenGL : Imports {
....
[DllImport(LIBRARY_OPENGL)] protected static extern void glVertex3f (float x, float y, float z);
...
}

...means that I can do this, in C#:
 
OpenGL.glVertex3f(x, y, z);

...but that's a protected function, so what I really need to do to call this code from another package is

myOpenGL.Vertex(x, y, z);

This is good, this is progress, but I don't want to write a molecule renderer in straight OpenGL. SharpGL provides a .NET component with a scene graph and lighting controls and camera controls and built-in shape classes, which is very helpful... but I want to use G3D, not SharpGL. G3D exists, and I know it, and I know its maintainers, and I know it is fast, and I know it works. Corey Taylor (one of the maintainers) says he'll try to help, but he's under a crazy workload... so I'm going to keep trying to do this myself.

My current approach:



  1. Keep my current C# class, MolecularModel, as the data structure for describing molecules. Unmanaged C++ can access managed, public C# classes.


  2. Write a small, unmanaged C++ class which renders a MolecularModel to an offscreen bitmap using G3D. Tag just the public interface of this class as dllexports.


  3. Write a small managed C# class which wraps my unmanaged C++ molecule renderer, by dll-importing the public interface which I exported in step 2. This managed class will not be a control; it's just a wrapper class. This wrapper's fundamental functionality will be to render a MolecularModel into a Bitmap.

  4. Replace the internals of the current ChemPad molecule viewer control, which is a .NET component, with calls to the managed molecule renderer wrapper. On Paint events, draw the Bitmap created by G3D onto this control's Graphics. Now instead of jmol-net generating the 3D image, G3D will be generating the 3D image.

This approach is different from my previous attempts in that it adds a layer which exposes a small API from unmanaged C++ to managed code. The compiler options will still be fairly hellish, and this isn't as good as really making all of G3D accessible from C#... but it keeps a very clean boundary between the chemistry part of the application and the rendering part of the application. Yikes. Wish me luck.

References (20)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    In place of the small man they had the system of multiple trading and red toms the co-operative store michael kors backpack s making it increasingly difficult for him to hold his own in face of increasing competition,red toms. He also said that he wished Wozniacki all the ...
  • Response
    Response: Continued
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    Response: thepennyrose.com
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    Response: 667816.com
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    Response: realgreatgames.com
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    Response: sofas
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    Response: instructables.com
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    Response: Related Site
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    openben - shinyblog - progress with windows and opengl... towards a solution!
  • Response
    Response: horizon.hosteko.ru
    openben - shinyblog - progress with windows and opengl... towards a solution!

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>