We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 40,922 times

Contents

Related Categories

OpenGL in C# - Using OpenGL in a Wizard generated Windows applica

Bill Burris

Using OpenGL in a Wizard generated Windows applica

Create a new C# Windows Application Project called DotsDemo, and add the class MyView to the project and add the following code:

using System;
using System.Drawing;
using System.Windows.Forms;
using CsGL.OpenGL;
namespace DotsDemo
{
public class MyView : OpenGLControl
{
    public override void glDraw()
    {
        GL.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT ); // Clear Screen And Depth Buffer
        GL.glBegin( GL.GL_POINTS );
        GL.glVertex2i( 100, 50 );
        GL.glVertex2i( 100, 130 );
        GL.glVertex2i( 150, 130 );
        GL.glEnd();
        GL.glFlush();
    }
    protected override void InitGLContext()
    {
        GL.glClearColor( 1.0f, 1.0f, 1.0f, 0.0f );
        GL.glColor3f( 0.0f, 0.0f, 0.0f );
        GL.glPointSize( 4.0f );
    }
    protected override void OnSizeChanged(EventArgs e)
    {
        base.OnSizeChanged(e);
        GL.glMatrixMode(GL.GL_PROJECTION);
        GL.glLoadIdentity();
        GL.gluOrtho2D( 0.0, Size.Width, 0.0, Size.Height );
    }
}
}

Modify the Form1 code so that is looks like the following:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DotsDemo
{
public class Form1 : System.Windows.Forms.Form
{
    MyView view = new MyView();
    private System.ComponentModel.Container components = null;
    public Form1()
    {
        InitializeComponent();
        view.Dock = DockStyle.Fill;
        Controls.Add( view );
    }
    protected override void Dispose( bool disposing )
    {
        if( disposing )
        {
            if (components != null)
            {
                components.Dispose();
            }
        }
        base.Dispose( disposing );
    }
    #region Windows Form Designer generated code
    [STAThread]
    static void Main()
    {
        Application.Run(new Form1());
    }
}
}

Using this technique you can add other controls and menus to your application using the Visual Studio form designer.

Comments

  • Re: [3823] OpenGL in C#

    Posted by ubnaseem on 22 Jun 2008

    how can i draw a line between two user controls on panel


    how can i change the shape of the usercontrol as diamond shape and triangel shape