How to run OpenTk in Vs 2008?
i try to learn OpenTk (Old Version Tao Framework) But i can not simple draw Line :
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Audio;
using OpenTK.Audio.OpenAL;
using OpenTK.Input;
namespace Test1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void glControl1_Paint(object sender, PaintEventArgs e)
{
// COORDINATE SYSTEM ALGORITHM:
GL.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
GL.ShadeModel(ShadingModel.Flat);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
glControl1.SwapBuffers();
GL.Begin(BeginMode.Lines);
GL.Vertex2(0.0, -1.0);
GL.Vertex2(0.0, 1.0);
GL.Vertex2(1.0, 0.0);
GL.Vertex2(-1.0, 0.0);
GL.End();
}
}
}
i can not watch coordinate system. i think that can 开发者_StackOverflownot run open tk in vs 2008? what is your best advise?
Several things :
- This has nothing to do with Visual C# 2008, which is perfectly capable of compiling C# code.
- You do not set the color in which you want to paint the line. Write GL.Color3(1,0,0); just before GL.Begin
- SwapBuffers puts what you've just drawn onscreen. In your case, it is the result of glClear = a white screen. Your following commands are anihilated by the glClearColor that happens just after (1rst line of your function)
- You need to tell OpenGL how to transform your vertices in space. ( In this case, it should work, but that's a coincidence ). Read about glMatrixMode, glLoadIdentity, glOrtho/gluLookAt, glTranslate in any tutorial (basically : matrixmode(PROJECTION); loadidentity; glOrtho(-1,1,-1,1,-1,1);matrixmode(MODELVIEW);loadIdentity;translate(asYouWish) )
It will run in VS2008.
There's some good OpenTK starting code here that walks you through proper setup of a Winform + GLControl and some simple rendering. (It should be enough to let you sort out the various issues Calvin pointed out.)
http://www.opentk.com/doc/chapter/2/glcontrol
精彩评论