glutWireCube() is the function for drawing a cube in C++, How about in OpenTK? Any function was used for replace 开发者_StackOverflow社区that?
glutWireCube is not an OpenGL function. It's part of GLUT a library oftenly mistaken for being part of OpenGL.
This function draws a solid cube using the old fixed function pipeline, modify it for your needs. I've written the variable declarations inside the function for brevity but you should move them out of the function if you want more performance. I would also recommend rewriting the function to use GL.DrawElements() instead.
private void DrawBox(float size)
{
float[,] n = new float[,]{
{-1.0f, 0.0f, 0.0f},
{0.0f, 1.0f, 0.0f},
{1.0f, 0.0f, 0.0f},
{0.0f, -1.0f, 0.0f},
{0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, -1.0f}
};
int[,] faces = new int[,]{
{0, 1, 2, 3},
{3, 2, 6, 7},
{7, 6, 5, 4},
{4, 5, 1, 0},
{5, 6, 2, 1},
{7, 4, 0, 3}
};
float[,] v = new float[8,3];
int i;
v[0,0] = v[1,0] = v[2,0] = v[3,0] = -size / 2;
v[4,0] = v[5,0] = v[6,0] = v[7,0] = size / 2;
v[0,1] = v[1,1] = v[4,1] = v[5,1] = -size / 2;
v[2,1] = v[3,1] = v[6,1] = v[7,1] = size / 2;
v[0,2] = v[3,2] = v[4,2] = v[7,2] = -size / 2;
v[1,2] = v[2,2] = v[5,2] = v[6,2] = size / 2;
GL.Begin(BeginMode.Quads);
for (i = 5; i >= 0; i--) {
GL.Normal3(ref n[i, 0]);
GL.Vertex3(ref v[faces[i, 0], 0]);
GL.Vertex3(ref v[faces[i, 1], 0]);
GL.Vertex3(ref v[faces[i, 2], 0]);
GL.Vertex3(ref v[faces[i, 3], 0]);
}
GL.End();
}
精彩评论