Click here to Skip to main content
5,787,682 members and growing! (17,574 online)
Email Password   helpLost your password?
Multimedia » OpenGL » General     Intermediate License: The GNU General Public License (GPL)

SharpGL: a C# OpenGL class library

By Dave Kerr

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
C#, Windows, .NET 1.0, .NET, Visual Studio, Dev

Posted: 4 Nov 2002
Updated: 3 Jul 2007
Views: 185,845
Bookmarked: 135 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
51 votes for this Article.
Popularity: 7.63 Rating: 4.47 out of 5
3 votes, 6.7%
1
0 votes, 0.0%
2
3 votes, 6.7%
3
6 votes, 13.3%
4
33 votes, 73.3%
5

Screenshot - Screenshot.jpg

Introduction

SharpGL provides you with two controls for designing forms. The OpenGLControl lets you do standard OpenGL drawing in a C# application and the SceneControl 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, glEnd, etc.

Screenshot - Screenshot-Small.jpg

If you want to get OpenGL in your application quickly, there's no easier way. There are four example applications that show you how to use some common features and my website has a tutorials section that is regularly updated.

Getting started

First, 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 this:

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

Will have to look like this:

OpenGL gl = someForm.someOpenGLControl.OpenGL;
gl.Begin(OpenGL.LINES); 
    gl.Vertex(1, 1, 1); //etc... 

Porting over existing OpenGL code is therefore pretty easy. Also, all of the OpenGL functions have full comments on parameters, etc., so it's very easy to find information on a certain function you might need. The library also wraps GLU, the OpenGL utility library.

Scene Graph

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

Until now, the SharpGL code hadn't been updated for a good two years. I have updated it recently to make it more simple, so that people can do old fashioned OpenGL style drawing nice and quickly. Much of the Scene Graph code could do with a tidying up, but I am expecting to be able to play with it over the next few months. So, check back soon for details.

New code and updates

New to SharpGL v1.8:

  • Tutorials are online here.
  • There are three new example applications.
  • Significant improvements have been made 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 Scene drawing extremely fast.
  • An overhaul of the GDI code by Lee Davies and myself has removed the large memory leak, as well as hugely increased the overall performance 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; it can cast real-time shadows. A set of Builders have been added to the SceneBuilder application, allowing you to build polygons from scratch and play around with materials. SceneBuilder, the test application, is a simple application showing some of what SharpGL can do. All of the source code is bundled with it, so 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 the picking. You can also 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 can 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 are for the user to select from. Then the object will be created from the file or saved to the file. This means that in the SceneBuilder application it takes about 2 lines to be able to load a polygon from file, with all of the possible formats automatically shown.

History

  • 5 November, 2002 -- Original version posted
  • 3 July, 2007 -- Updated

License

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

About the Author

Dave Kerr



Occupation: Web Developer
Location: United Kingdom United Kingdom

Other popular OpenGL articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 115 (Total in Forum: 115) (Refresh)FirstPrevNext
GeneralUpdates & TutorialsmemberDave Kerr12hrs 24mins ago 
GeneralMissing propertiesmemberhain8:07 7 Jan '09  
QuestionC# and OpenSG?!membernjss23:01 27 Nov '08  
GeneralOpenGL-Control SetStyle missing (GDI-Paintings flicker)memberRedGreenBlue12345:31 7 Sep '08  
Generalgl.ReadPixels incorrect overridingmemberkhdani4:53 14 Aug '08  
QuestionHardware accelerationmemberMarkus Mayer7:29 12 Aug '08  
AnswerRe: Hardware accelerationmemberDmitri Nesteruk1:06 16 Nov '08  
Generalseeking for starting tipsmemberrhash19:48 22 Jul '08  
GeneralUsing stereoscopic shutter glassesmembermartinsantiago3:52 14 Jul '08  
RantNice jobmemberLilit Yenokyan9:35 16 May '08  
QuestionEvent handlingmemberAmidos0:13 26 Apr '08  
QuestionOpenGLControl resize zooms inmemberbestey1721:50 26 Dec '07  
GeneralUrgent Hepl!memberM.N.9:01 28 Sep '07  
GeneralTo see in Ortho and Perspective viewmembersachinbd4:26 18 Sep '07  
GeneralHow to set Aspect Ratiomemberkangaloosh5:20 9 Aug '07  
GeneralRe: How to set Aspect RatiomemberDave Kerr6:40 9 Aug '07  
GeneralRe: How to set Aspect Ratiomemberkangaloosh23:19 9 Aug '07  
GeneralRe: How to set Aspect RatiomemberDave Kerr1:21 10 Aug '07  
GeneralTransparent objectsmemberkangaloosh0:46 25 Jul '07  
GeneralRe: Transparent objectsmemberDave Kerr1:23 25 Jul '07  
GeneralRe: Transparent objectsmemberkangaloosh10:56 26 Jul '07  
GeneralNicememberPaul Conrad8:54 15 Jul '07  
GeneralRe: NicememberDave Kerr2:00 16 Jul '07  
GeneralRe: NicememberPaul Conrad8:28 16 Jul '07  
GeneralGreat!memberAmro Khasawneh13:17 11 Jul '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 3 Jul 2007
Editor: Genevieve Sovereign
Copyright 2002 by Dave Kerr
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project