Click here to Skip to main content
6,304,948 members and growing! (19,076 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, Visual Studio, Dev
Version:2 (See All)
Posted:4 Nov 2002
Updated:15 Jan 2009
Views:215,743
Bookmarked:177 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
67 votes for this article.
Popularity: 8.38 Rating: 4.59 out of 5
3 votes, 4.9%
1

2
3 votes, 4.9%
3
6 votes, 9.8%
4
49 votes, 80.3%
5

Screenshot.jpg

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 five example applications in the download that show you how to use some common features. The SharpGL Website also has a set of tutorials that is regularly updated - as well as support information.

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

  • New website online - SharpGL, with new tutorials, support information and more!
  • 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.

More Tutorials & Features

I am currently spending a large amount of time on SharpGL, after a few very quiet years. If you want more tutorials or new features, now is the time to let me know! Either leave comments on this page or get in touch with me via the SharpGL Website .

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


Member

Occupation: Software Developer (Senior)
Company: Duck & Cover Media
Location: United Kingdom United Kingdom

Other popular OpenGL articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 139 (Total in Forum: 139) (Refresh)FirstPrevNext
GeneralWebsite down? Pinmembertjdetwiler11:27 9 Jun '09  
GeneralRe: Website down? Pinmemberayotunde3:21 16 Jun '09  
Question#D Game PinmemberMOSTAFApro22:09 21 Apr '09  
JokeRe: #D Game Pinmembermartin_bfg10k11:11 3 May '09  
GeneralOrthographic projection in SharpGL? Pinmembersanctus20998:13 21 Apr '09  
GeneralRe: Orthographic projection in SharpGL? PinmemberARon_5:34 19 May '09  
QuestionShould you give some comment about "C# wrapper for OpenGL" and SharpGL? PinmemberFrenet19:53 24 Mar '09  
QuestionHow to enable ortho view.. PinmemberMember 45959368:40 24 Mar '09  
AnswerRe: How to enable ortho view.. PinmemberARon_5:33 19 May '09  
Generaldouble buffering Pinmemberabhi48820:09 8 Feb '09  
GeneralRe: double buffering PinmemberDave Kerr9:23 10 Feb '09  
GeneralGiving you a 5 just for the screen shots! PinmemberSteven A. Lowe8:56 19 Jan '09  
GeneralUpdates & Tutorials PinmemberDave Kerr3:18 8 Jan '09  
GeneralMissing properties Pinmemberhain8:07 7 Jan '09  
GeneralRe: Missing properties PinmemberDave Kerr4:10 9 Jan '09  
GeneralRe: Missing properties Pinmemberhain5:13 9 Jan '09  
GeneralRe: Missing properties PinmemberDave Kerr5:52 9 Jan '09  
QuestionC# and OpenSG?! Pinmembernjss23:01 27 Nov '08  
AnswerRe: C# and OpenSG?! PinmemberDave Kerr4:11 9 Jan '09  
GeneralRe: C# and OpenSG?! Pinmembernjss9:03 9 Jan '09  
GeneralOpenGL-Control SetStyle missing (GDI-Paintings flicker) PinmemberRedGreenBlue12345:31 7 Sep '08  
GeneralRe: OpenGL-Control SetStyle missing (GDI-Paintings flicker) PinmemberDave Kerr4:12 9 Jan '09  
Generalgl.ReadPixels incorrect overriding Pinmemberkhdani4:53 14 Aug '08  
GeneralRe: gl.ReadPixels incorrect overriding PinmemberDave Kerr4:26 9 Jan '09  
QuestionHardware acceleration PinmemberMarkus Mayer7:29 12 Aug '08  

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

PermaLink | Privacy | Terms of Use
Last Updated: 15 Jan 2009
Editor: Sean Ewington
Copyright 2002 by Dave Kerr
Everything else Copyright © CodeProject, 1999-2009
Web12 | Advertise on the Code Project