Click here to Skip to main content
11,437,397 members (34,746 online)
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Revisions

SharpGL: a C# OpenGL class library

, 22 Sep 2011 GPL3
Rate this:
Please Sign up or sign in to vote.
SharpGL is a very simple, very powerful C# OpenGL class library, Included is a Windows OpenGL control and Component for direct editing in the visual environment
This is an old version of the currently published article.

Screenshot.jpg

Keeping Track of SharpGL

SharpGL 2.0 will be released very shortly - it provides some much needed updates such as: 

  • Hardware Acceleration
  • OpenGL Extension Support 
  • 'Render Context Providers', allowing one to use DIB Sections, Native Windows, Offscreen Windows or even Framebuffer Extensions to render a scene  
SharpGL is now hosted on CodePlex, at:

http://sharpgl.codeplex.com  

The CodePlex site has more information and the latest source code. I am also writing about the various challenges of creating the new version on my blog at:

http://www.dwmkerr.com  

Both of these sites contain up to date information on SharpGL and how it is progressing. Once SharpGL 2.0 is ready this main page will also be updated with examples and more documentation. 

Introduction 

Use OpenGL in your C# applications with SharpGL, it's a breeze! Just drag an OpenGLControl onto your Windows Form and handle the 'OpenGLDraw' function - now just call ordinary OpenGL functions!

SharpGL provides you with two controls for designing forms. The OpenGLControl, which lets you do standard OpenGL drawing in a C# application, and the SceneControl, which does the same with added support for polygons/persistence/picking and more. The screenshot above shows the SceneControl in action, with the supplied 'SceneBuilder' application. The screenshot below shows some 'old fasioned' OpenGL drawing, with calls to 'glBegin' and 'glEnd' etc.

Screenshot-Small.jpg

If you want to get OpenGL in your application quickly, there's no easier way. There are eight example applications in the download that show you how to use some common features. 

Getting Started

Create a Windows Forms application, use the SharpGL DLL as a reference, and drop an OpenGLControl onto the form. Then handle the 'OpenGLDraw' event and you're ready to go!

Calls that in C++ would look like:

glBegin(GL_LINES);
    glVertex3f(1.0f, 1.0f, 1.0f); ...etc...

Will have to look like:

OpenGL gl = someForm.someOpenGLControl.OpenGL;

gl.Begin(OpenGL.LINES); 
		gl.Vertex(1, 1, 1); ...etc...

Porting over existing OpenGL code is therefore trivial. Every OpenGL and GLU library function has been imported and fully commented - no need to look through reference books for function parameters, the Code Hints will show you everything you need to see!

screenshot_codehints.jpg

The Scene Graph

The Scene Graph contains classes like 'Texture' and 'Camera' to make working with certain types of object much easier. You don't have to use them, you can use certain components or you can use the whole lot. Or you can mix and match. There is an example application that shows how to do texturing with the Scene Graph.

New Code and Updates

New to SharpGL v1.83 

  • Five example applications in the download.
  • Numerous bug fixes, updates and optimisations.

New to SharpGL v1.8

  • Three new example applications.
  • Significant improvements to texturing code.
  • Rollup Controls in SceneBuilder keep the interface clutter free.
  • A new materials editor in the Modify tab allows quick material editing.
  • All SceneObjects in SharpGL now automatically optimise themselves to use display lists. This has made the Scene drawing extremely fast.
  • An overhaul of the GDI code by Lee Davies and myself has removed the large memory leak and hugely increased the overall performace of the library and application.
  • Many more minor updates and bug fixes are documented in the updates document in the project.

You can now automatically load simple 3D objects from Caligari trueSpace files. This makes creating applications a bit more simple, as you can test the polygon classes with real objects. A Polygon in the SharpGL scene graph is very powerful, they can cast real time shadows. A set of 'Builders' have been added to the SceneBuilder application, allowing you to build polygons from scratch, play around with materials etc.

SceneBuilder (the Test Application) is a simple application showing some of what SharpGL can do, and all the sourcecode is bundled with it, you can use it to build many aspects of a scene.

Points of Interest

The library is great to use, the Scene Graph 'Scene' object lets you do picking, you can control objects via the mouse, even parts of objects, such as the control points of NURBS and evaluators can be moved around. The polygons can be edited by Face, Vertex or as whole objects, and cast shadows over other objects.

Many of the 'kludgy' aspects of OpenGL such as the limits on the number of lights have been smoothed over. Using lights as an example, when the scene is created, the maximum number of lights is ascertained, and you cannot go over that limit. The extent of Mouse control is amazing, and very easy to implement in your own classes. The Persistence code is some of the best code I've ever written, you can call a function in the persistence engine, passing a type of object, and immediately a File Open / Save dialog will be shown with all the available file formats there for the user to select from, then the object will be created from the file or saved to the file. This means in the SceneBuilder app, it takes about two lines to be able to load a polygon from file, with all the possible formats automatically shown.

Keep Up To Date 

Up to date information on SharpGL development is available from the CodePlex site and my own blog: 

SharpGL is now hosted on CodePlex, at:

http://sharpgl.codeplex.com   

http://www.dwmkerr.com   

Feature Requests

I am looking for feature requests for SharpGL 2.0 and the roadmap! Add feature requests from the CodePlex page's 'Issues' section or via the comments below. 

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Dave Kerr
Software Developer
United Kingdom United Kingdom
Follow my blog at www.dwmkerr.com and find out about my charity at www.childrenshomesnepal.org.
Follow on   Twitter

Comments and Discussions


Discussions posted for the Published version of this article. Posting a message here will take you to the publicly available article in order to continue your conversation in public.
 
GeneralThanks Pin
ARandomGuy26-Feb-15 5:00
memberARandomGuy26-Feb-15 5:00 
GeneralRe: Thanks Pin
Dave Kerr26-Feb-15 5:46
mvpDave Kerr26-Feb-15 5:46 
QuestionVS 2013 Extension Pin
smjones-home4-Dec-14 10:03
membersmjones-home4-Dec-14 10:03 
AnswerRe: VS 2013 Extension Pin
Dave Kerr8-Dec-14 18:50
mvpDave Kerr8-Dec-14 18:50 
QuestionVSIX Installation failed - Visual Studio Express Editions Pin
AORD17-Nov-14 23:30
memberAORD17-Nov-14 23:30 
AnswerRe: VSIX Installation failed - Visual Studio Express Editions Pin
Dave Kerr19-Nov-14 4:23
mvpDave Kerr19-Nov-14 4:23 
AnswerRe: VSIX Installation failed - Visual Studio Express Editions Pin
Dave Kerr25-Jan-15 2:12
mvpDave Kerr25-Jan-15 2:12 
GeneralRe: VSIX Installation failed - Visual Studio Express Editions Pin
AORD25-Jan-15 8:23
memberAORD25-Jan-15 8:23 
GeneralRe: VSIX Installation failed - Visual Studio Express Editions Pin
Dave Kerr26-Jan-15 22:45
mvpDave Kerr26-Jan-15 22:45 
QuestionSharpGL tutorial & 3D rendering?? [modified] Pin
Member 1088161316-Jun-14 23:56
memberMember 1088161316-Jun-14 23:56 
AnswerRe: SharpGL tutorial & 3D rendering?? Pin
Dave Kerr22-Jun-14 8:52
mvpDave Kerr22-Jun-14 8:52 
QuestionRe: SharpGL tutorial & 3D rendering?? Pin
Member 1088161326-Jun-14 0:04
memberMember 1088161326-Jun-14 0:04 
AnswerRe: SharpGL tutorial & 3D rendering?? Pin
Dave Kerr27-Jun-14 5:41
mvpDave Kerr27-Jun-14 5:41 
GeneralRe: SharpGL tutorial & 3D rendering?? Pin
Member 108816131-Jul-14 21:19
memberMember 108816131-Jul-14 21:19 
GeneralRe: SharpGL tutorial & 3D rendering?? Pin
Dave Kerr21-Jul-14 7:48
mvpDave Kerr21-Jul-14 7:48 
QuestionRe: SharpGL tutorial & 3D rendering?? Pin
Member 1088161328-Jul-14 21:53
memberMember 1088161328-Jul-14 21:53 
QuestionHow to use the WGS84 (Latitude, Longitude) projection Pin
AhmedGis201114-Apr-14 8:28
memberAhmedGis201114-Apr-14 8:28 
AnswerRe: How to use the WGS84 (Latitude, Longitude) projection Pin
Dave Kerr14-Apr-14 8:59
mvpDave Kerr14-Apr-14 8:59 
QuestionWhich OpenGL version? Pin
Leonardo Bouchan12-Apr-14 11:04
memberLeonardo Bouchan12-Apr-14 11:04 
AnswerRe: Which OpenGL version? Pin
Dave Kerr12-Apr-14 21:54
mvpDave Kerr12-Apr-14 21:54 
QuestionLicense Pin
moritz949-Apr-14 6:32
membermoritz949-Apr-14 6:32 
AnswerRe: License Pin
Dave Kerr9-Apr-14 6:36
mvpDave Kerr9-Apr-14 6:36 
GeneralRe: License Pin
LittleFox949-Apr-14 6:57
memberLittleFox949-Apr-14 6:57 
QuestionDrawText could not show Chinese! Pin
ydongydong11-Mar-14 3:48
memberydongydong11-Mar-14 3:48 
AnswerRe: DrawText could not show Chinese! Pin
Dave Kerr11-Mar-14 6:56
mvpDave Kerr11-Mar-14 6:56 
GeneralRe: DrawText could not show Chinese! Pin
ydongydong12-Mar-14 16:53
memberydongydong12-Mar-14 16:53 
QuestionCan't Install VSIX With VS2012 Pin
Ashley Staggs15-Sep-13 1:33
memberAshley Staggs15-Sep-13 1:33 
AnswerRe: Can't Install VSIX With VS2012 Pin
Dave Kerr15-Sep-13 6:37
mvpDave Kerr15-Sep-13 6:37 
QuestionZooming in and out Pin
MWBate27-Jul-13 17:18
memberMWBate27-Jul-13 17:18 
AnswerRe: Zooming in and out Pin
Dave Kerr28-Jul-13 9:37
mvpDave Kerr28-Jul-13 9:37 
QuestionHow to make it work with visual studio 2008 Pin
jiabin.me14-Jul-13 4:09
memberjiabin.me14-Jul-13 4:09 
AnswerRe: How to make it work with visual studio 2008 Pin
Dave Kerr14-Jul-13 13:05
mvpDave Kerr14-Jul-13 13:05 
AnswerRe: How to make it work with visual studio 2008 Pin
AORD13-Nov-13 7:49
memberAORD13-Nov-13 7:49 
GeneralQuite Cool Pin
Brisingr Aerowing15-May-13 16:05
professionalBrisingr Aerowing15-May-13 16:05 
GeneralRe: Quite Cool Pin
Dave Kerr16-May-13 3:27
mvpDave Kerr16-May-13 3:27 
GeneralMy vote of 5 Pin
Max Holder18-Apr-13 3:25
memberMax Holder18-Apr-13 3:25 
GeneralRe: My vote of 5 Pin
Dave Kerr18-Apr-13 3:32
mvpDave Kerr18-Apr-13 3:32 
BugWhat if (frameRate is 0) but (timerDrawing.Enabled is false) @OpenGLControl.SetupDrawingTimer() ? Pin
bitzhuwei16-Apr-13 17:05
memberbitzhuwei16-Apr-13 17:05 
GeneralRe: What if (frameRate is 0) but (timerDrawing.Enabled is false) @OpenGLControl.SetupDrawingTimer() ? Pin
Dave Kerr16-Apr-13 22:25
mvpDave Kerr16-Apr-13 22:25 
GeneralFantastic stuff thank you. Pin
makaveli_000020-Feb-13 8:33
membermakaveli_000020-Feb-13 8:33 
GeneralRe: Fantastic stuff thank you. Pin
Dave Kerr20-Feb-13 22:37
mvpDave Kerr20-Feb-13 22:37 
GeneralRe: Fantastic stuff thank you. Pin
Juan Manuel Romero Martin7-Apr-13 13:12
memberJuan Manuel Romero Martin7-Apr-13 13:12 
GeneralRe: Fantastic stuff thank you. Pin
makaveli_00007-Apr-13 14:23
membermakaveli_00007-Apr-13 14:23 
Questiontext in 3d space Pin
tcpmv1-Jan-13 11:15
membertcpmv1-Jan-13 11:15 
AnswerRe: text in 3d space Pin
Dave Kerr2-Jan-13 22:32
mvpDave Kerr2-Jan-13 22:32 
Generaltext in 3d space Pin
tcpmv3-Jan-13 5:58
membertcpmv3-Jan-13 5:58 
GeneralRe: text in 3d space Pin
Dave Kerr3-Jan-13 8:10
mvpDave Kerr3-Jan-13 8:10 
QuestionWhen I initialize the OpenGL, why I must Translate the modelview. Pin
zy3327197942-Dec-12 16:23
memberzy3327197942-Dec-12 16:23 
AnswerRe: When I initialize the OpenGL, why I must Translate the modelview. Pin
Dave Kerr4-Dec-12 4:12
mvpDave Kerr4-Dec-12 4:12 
QuestionCan't get started Pin
MWBate29-Nov-12 9:01
memberMWBate29-Nov-12 9:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150428.2 | Last Updated 22 Sep 2011
Article Copyright 2002 by Dave Kerr
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid