Hey does anybody know how to make window forms using openGL in c sharp. Or know of a tutorial online, i've looked but turned up nothing useful, just that csGL is a good library to use for openGL projects.

Thanks

Recommended Answers

All 6 Replies

Hi

This is a sample C# app which draws a line using csGL. I hope it helps.

using System;
using System.Drawing;
using System.Windows.Forms;
using CsGL.OpenGL;

public class GLCanvas : Form
{
View view = new View();

public GLCanvas()
{
Text = "C# OpenGL Merhaba Dünya";
view.Dock = DockStyle.Fill;
Controls.Add(view);
}

public static void Main()
{
GLCanvas glc = new GLCanvas();
Application.Run(glc);
}
}


class View : OpenGLControl
{
public override void glDraw()
{
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
GL.glLoadIdentity();
GL.glTranslatef( 0.0f, 0.0f, -10.0f );
GL.glColor3f(0.5f, 1, 1);

GL.glBegin(GL.GL_LINES);
GL.glVertex3d(0.0, 0.0, 0.0);
GL.glVertex3d(2.0, 2.0, 0.0);
GL.glEnd();
}

protected override void InitGLContext()
{
GL.glShadeModel(GL.GL_SMOOTH);
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
GL.glClearDepth(1.0f);
GL.glEnable(GL.GL_DEPTH_TEST);
GL.glDepthFunc(GL.GL_LEQUAL);
GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
}

protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);

Size s = Size;
double aspect_ratio = (double)s.Width /(double) s.Height;

GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
GL.gluPerspective(45.0f, aspect_ratio, 0.1f, 100.0f);

GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glLoadIdentity();
}
}

Loren Soth

what about making like GUI's using csGL and c#, do you know any tutorials for that?

Hi,

I'm sorry I don't know one, but check GLScene (OpenGL Framework for Delphi) they have a cool OpenGL GUI subsystem with all the windows controls and HUD support, if you don't mind porting from Delphi to C#.

Loren Soth

What about directX, can you make a GUI from that?

Hi,

There are some frameworks on top of DirectX 9 Managed SDK but I am not familiar.

Loren Soth

Do you know where I could find an API for that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.