简体   繁体   English

如何在Vs 2008中运行OpenTk?

[英]How to run OpenTk in Vs 2008?

i try to learn OpenTk (Old Version Tao Framework) But i can not simple draw Line : 我尝试学习OpenTk(旧版Tao框架),但我不能简单地画出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 not run open tk in vs 2008? 我认为无法在vs 2008中运行open tk? what is your best advise? 您最好的建议是什么?

Several things : 几件事:

  • This has nothing to do with Visual C# 2008, which is perfectly capable of compiling C# code. 这与完全能够编译C#代码的Visual C#2008没有任何关系。
  • You do not set the color in which you want to paint the line. 您没有设置要绘制线条的颜色。 Write GL.Color3(1,0,0); 写GL.Color3(1,0,0); just before GL.Begin 就在GL.Begin之前
  • SwapBuffers puts what you've just drawn onscreen. SwapBuffers将您刚刚绘制的内容显示在屏幕上。 In your case, it is the result of glClear = a white screen. 在您的情况下,这是glClear =白色屏幕的结果。 Your following commands are anihilated by the glClearColor that happens just after (1rst line of your function) 紧随其后的glClearColor破坏了您的以下命令(函数的第一行)
  • You need to tell OpenGL how to transform your vertices in space. 您需要告诉OpenGL如何在空间上变换顶点。 ( 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) ) 在任何教程中阅读有关glMatrixMode,glLoadIdentity,glOrtho / gluLookAt,glTranslate的信息(基本上是:matrixmode(PROJECTION); loadidentity; glOrtho(-1,1,-1,1,-1,1); matrixmode(MODELVIEW); loadIdentity; translate (如你所愿) )

It will run in VS2008. 它将在VS2008中运行。

There's some good OpenTK starting code here that walks you through proper setup of a Winform + GLControl and some simple rendering. 这里有一些不错的OpenTK起始代码,可指导您正确设置Winform + GLControl和一些简单的呈现。 (It should be enough to let you sort out the various issues Calvin pointed out.) (足以让您理清卡尔文指出的各种问题。)

http://www.opentk.com/doc/chapter/2/glcontrol http://www.opentk.com/doc/chapter/2/glcontrol

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM