如何使用OpenTK& amp;绘制立方体C#中的OpenGL

时间:2017-03-01 03:47:50

标签: c# opengl opentk

我正处于关于绘制Cube的危机中,正如标题所说。

我只在Unity中尝试了这个图形。但我完成了。在C#中使用OpenTK和OpenGL。

通过输入值来绘制球体是成功的。

在键入时绘制数组的值。

Ex)2by2 Array =>

OO

OO

这是关于绘制Sphere的代码

 void DrawSphere()
    {
     OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.Lighting);
        OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.Light0);
        OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.Normalize);
        OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.ColorMaterial);
        //OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.Texture2D);
        OpenTK.Graphics.OpenGL.GL.ShadeModel(OpenTK.Graphics.OpenGL.ShadingModel.Smooth);

        // Draw green sphere
        OpenTK.Graphics.OpenGL.GL.Color3(0.8f, 0.8f, 255.0f);
        //textureid = LoadTex("dd.png");
        float x, y, z;

        y = 0.0F;
        x = 0.0F;
        x = (((Properties.Settings.Default.simulRow * camera.rowGap) - camera.rowGap) / 2) * -1.0F;
        for (int i = 0; i < Properties.Settings.Default.simulRow; i++)
        {
            z = (((Properties.Settings.Default.simulCol * camera.colGap) - camera.colGap) / 2) * -1.0F;

            for (int j = 0; j < Properties.Settings.Default.simulCol; j++)
            {
                //y = ballImage[i, j].height / camera.calibrate_div;
                y = (camera.calibrate_div / 2.0f) - Math.Abs(ballImage[i, j].current_height);
                //System.Diagnostics.Debug.WriteLine(ballImage[0, 0].current_height);
                OpenTK.Graphics.OpenGL.GL.PushMatrix();
                OpenTK.Graphics.OpenGL.GL.Translate(x, y, z);
                //OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, textureid);

                //OpenTK.Graphics.Glu.QuadricTexture(esfera, true);
                OpenTK.Graphics.OpenGL.GL.Rotate(90, 1.0f, 0.0f, 0.0f);
                //OpenTK.Graphics.OpenGL.GL.Rotate(0.0f, 1.0f, 1.0f, 1.0f);
                OpenTK.Graphics.Glu.Sphere(esfera, 1.0f, 24, 24);
                //OpenTK.Graphics.Glu.Tex(esfera, 1.0f, 24, 24);
                OpenTK.Graphics.OpenGL.GL.PopMatrix();
                if (i == 5 && j == 5)
                {
                    // OpenTK.Graphics.Glu.Sphere(esfera, 100.0f, 24, 24);
                }

                z += camera.rowGap;
            }
            x += camera.colGap;

        }
}

0 个答案:

没有答案