OpenGL and C# - Part 1

csharp , opengl
This is a comment thread discussing Learn OpenGL and C#
  • 11 years ago

    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... ;-)

  • 11 years ago

    (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

  • 11 years ago

    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(); } } }

  • 11 years ago

    the solution i know is:

        CheckForIllegalCrossThreadCalls = false;
    

    which is simpler

  • 11 years ago

    the solution i know is:

        CheckForIllegalCrossThreadCalls = false;
    

    which is simpler

  • 11 years ago

    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!

  • 11 years ago

    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"

  • 11 years ago

    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...

  • 10 years ago

    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?

Post a reply

Enter your message below

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

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.”