0

I'm in crisis about draw Cube, as the title says.

I tried the graphic only in Unity. But I was done. Using OpenTK and OpenGL in C#.

It was successful to draw the sphere by inputting the value.

Draw the values of the array as you type.

Ex) 2by2 Array =>

oo

oo

this is my code about draw 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;

        }
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
Minsoo Son
  • 31
  • 5

0 Answers0