Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-CsGL无效枚举符_C#_Opengl - Fatal编程技术网

C#-CsGL无效枚举符

C#-CsGL无效枚举符,c#,opengl,C#,Opengl,我试图按照本教程在C#上制作OpenGL应用程序 后来,我尝试进行以下更改: class DrawObject : OpenGLControl { public override void glDraw() { GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); GL.glLoadIdentity(); GL.glBegin(GL.GL_LINE);

我试图按照本教程在C#上制作OpenGL应用程序

后来,我尝试进行以下更改:

class DrawObject : OpenGLControl
{
    public override void glDraw()
    {
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
        GL.glLoadIdentity();
        GL.glBegin(GL.GL_LINE);
        GL.glLineWidth(10.0f);
        GL.glVertex3f(-3.0f, 0.0f, 0.0f);
        GL.glVertex3f(3.0f, 0.0f, 0.0f);
        GL.glEnd();
        GL.glFlush();
    }

    protected override void InitGLContext()
    {
        GL.glShadeModel(GL.GL_SMOOTH);
        GL.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
        GL.glClearDepth(1.0f);
        GL.glEnable(GL.GL_DEPTH_TEST);
        GL.glDepthFunc(GL.GL_LEQUAL);
        GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
    }

    protected override void OnSizeChanged(EventArgs e)
    {
        base.OnSizeChanged(e);

        Size s = Size;
        double aspect_ratio = (double)s.Width / (double)s.Height;
        GL.glMatrixMode(GL.GL_PROJECTION);
        GL.glLoadIdentity();

        GL.gluPerspective(45.0f, aspect_ratio, 0.1f, 100.0f);

        GL.glMatrixMode(GL.GL_MODELVIEW);
        GL.glLoadIdentity();
    }
}

public class DrawLine : Form
{
    DrawObject newObject = new DrawObject();

    public DrawLine()
    {
        Text = "Draw a line";
        newObject.Dock = DockStyle.Fill;
        Controls.Add(newObject);
    }

    public static void Main()
    {
        DrawLine drawLine = new DrawLine();
        Application.Run(drawLine);
    }
}

出于某种原因,我将在Application.Run(drawLine)处得到一个“invalid enumerant”错误。基本上,我要做的是用一个给定2个顶点的线来替换在3个指定顶点上渲染一个点的部分。我不知道为什么点版不抛出这个异常,但是线版抛出了这个异常。我在我的参考资料中引用了csgl.dll,并添加了csgl.native.dll,并使其在每次编译解决方案时发布(否则整个过程根本不会运行)。

不要更改
glBegin
glEnd
中的状态(也就是说,不要调用
glLineWidth
)。从:



朱利安利的回答:
glBegin
必须使用
GL\u行
,而不是
GL\u行
。请参阅注释。

因此我应该将该行添加到InitGLContext?是的,或者就在调用
glBegin
之前。很抱歉,它仍然不起作用…现在看起来是这样的:GL.glLineWidth(10.0f);总帐总帐开始(总帐总帐行);我已经弄明白了,我应该用GL_线,而不是GL_线。谢谢你,Stefan
GL_INVALID_OPERATION is generated if glLineWidth is executed between 
the execution of glBegin and the corresponding execution of glEnd.