Library tutorials & articles

OpenGL and C# - Part 1

Introduction

I’m glad to be the first one writing about OpenGL at this site. What I want to show you in this article is that it is fairly easy to setup a form that is capable of showing 3D. We will accomplish this with the OpenGLControl. So before we can start we (that means you) have to download CsGL here, or if it isn’t there anymore, from its project page. For this article I used the CsGL version 1.4.0 I think it will run on later versions though.

Ok let we start. First thing to do is make a new Windows Application. Which I called SimpelOpenGL but its not important. Ok when that done popup the “Solution explorer” and “add reference” the reference for CsGL must be in "D:\WINDOWS\system32\" which are called csgl.dll and csgl-base.dllnotice that there is .dll called csgl-native.dll but you don’t need it.

Ok import the following namespaces

  • System.Threading
  • CsGL.OpenGL

Comments

  1. 08 Aug 2009 at 14:08

    Hi All, I ran into some trouble with the thread above, but, I found a solution... Aperantly, while using Visual Studio 2008 such a cross thread action is considered unsafe. Anyway, the "Invoke" method can take care of that with just a few lines of code:

    private void OpenGL_Start() { if( this.view.InvokeRequired) { ThreadStart aDelegate = new ThreadStart(this.view.Refresh); for( ; ; ) { Thread.Sleep(1000); if( !thrOpenGL.IsAlive ) return; this.Invoke(aDelegate); } } else { for( ; ; ) { // infinity loop for rendering Thread.Sleep(1000); this.view.Refresh(); } } }

    The 'if' statement check to see if the action is done on the current thread or not and uses the "invoke" when necessary.

    I hope I saved someone the 60 minutes it took me... ;-)

  2. 08 Aug 2009 at 14:14

    (sorry for not marking the code as code in the comment above...)

    Hi Johnny, Still there? I know it's been a while since 2003... But if you are still around, or anyone else, I have a question:

    How do I draw two separate sets of drawing in parallel? I want to draw an Anaglyph. Let's say, a blue cube and a red cude. each in a different color and at a slightly different angle acording to two POV (points of view).

    Any suggestions?

    All the best. Amir

  3. 13 Aug 2009 at 11:01

    private void OpenGL_Start() { if( this.view.InvokeRequired) { ThreadStart aDelegate = new ThreadStart(this.view.Refresh); for( ; ; ) { Thread.Sleep(1000); if( !thrOpenGL.IsAlive ) return; this.Invoke(aDelegate); } } else { for( ; ; ) { // infinity loop for rendering Thread.Sleep(1000); this.view.Refresh(); } } }

  4. 01 Sep 2009 at 16:26

    the solution i know is:

        CheckForIllegalCrossThreadCalls = false;
    

    which is simpler

  5. 01 Sep 2009 at 16:27

    the solution i know is:

        CheckForIllegalCrossThreadCalls = false;
    

    which is simpler

  6. 10 Sep 2009 at 23:49

    First of all there is no csgl-base.dll in a package csgl.dll.zip downloaded from project site. Secound of all can anybody tell me why it doesn't work? Sometimes I have to change widnow size to see the scene, sometimes it never showes up :| why? What I'm doing wrong? uffff F1 F1 F1 HELP!

  7. 12 Sep 2009 at 20:54

    Strange, I've added a menu in the top of the window and now everything works perfectly :) thx for the tutorial. Without it I would never start. We Polish used to say "The first step is the hardest"

  8. 07 Oct 2009 at 09:29

    Thanks for the tutorial, unfortunately it does not work for me. All I see is white background with a red cross of which I don't know where it comes from... Thanks for any help...

  9. 13 May 2010 at 18:58

    hi! i have a problem... i can't seem to work it out to use Open GL library in my C# project. i downloaded csgl.1.4.1.dll archive from the net ( http://sourceforge.net/project/showfiles.php?group_id=33241) copied those 3 files (csgl, csgl.dll and csgl.native.dll) to C:\WINDOWS\system32\ then i made a reference from my project to that files i remembered before, and put at the beginning : using System.Threading; using CsGL.OpenGl;

    BUT

    it doesn't recognize the OpenGL from CsGL.

    what should i do to fix it?

Leave a comment

Sign in or Join us (it's free).

Johnny I'm doing first year Informatica at academy of Amsterdam

Related discussion

Related podcasts

  • OnMicrosoft from InformIT: Promise and adoption of LINQ (Audio)

    Published 1 year ago, running time 0h15m

    Mads Torgersen, C# language spec owner interviews the co-authors of Essential LINQ - Charlie Calvert and Dinesh Kulkarni. of, linq, adoption, audio

Related jobs

Events coming up

  • Sep 4

    iPhone Coding Dojo, Building Apps 4 iPhone using MonoTouch

    Cambridge, United Kingdom

    Relaxing end to another hard week with good Beer, laptops, friends, and coffee , 6:30 till whenever ... Every Friday at CB2 Bistro. (check the website each week to confirm the venue, will be exploring some other venues soon.)The challenge for tonight as a coding Dojo is to build an App for a Jailbroken IPhone using Monotouch.

Want to stay in touch with what's going on? Follow us on twitter or Facebook!