Library tutorials & articles
OpenGL in C#
- Introduction
- My First OpenGL in C# Program
- Using OpenGL in a Wizard generated Windows applica
My First OpenGL in C# Program
I converted the first example in Computer Graphics Using Open GL to C#, using the examples from the download as a template.
Here is the result:
using System;
using System.Drawing;
using System.Windows.Forms;
using CsGL.OpenGL;
public class DotsDemo : Form
{
MyView view = new MyView();
public DotsDemo()
{
Text = "Dots demo !";
view.Dock = DockStyle.Fill;
Controls.Add( view );
}
public static void Main()
{
DotsDemo di = new DotsDemo();
Application.Run( di );
}
}
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 );
}
}
Be sure to add references to the OpenGL dlls: csgl-base, csgl-extensions, & csgl-opengl.
The program draws 3 dots in the lower left corner of the window.
Related articles
Related discussion
-
OpenGL and C# - Part 1
by wuseltum (7 replies)
-
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records
by virtualking (0 replies)
-
How to optimize mysql subquery performance?
by Jayaram P (0 replies)
-
C# video Editing/rendering
by pkuchaliya (0 replies)
-
How to Fill DataSet with more records (around 1 lakh) in a faster way
by Jayaram P (0 replies)
Related podcasts
-
Object-Oriented Programming in Ruby
In this episode, I talk with Scott Bellware about object-oriented programming in Ruby, and Ruby's object model. This is taken from a private conversation, and the audio quality suffers at times. Much thanks to Scott for allowing this to be released.This episode of the Alt.NET Podcast is bro...
Comments
Leave a comment
Sign in or Join us (it's free).