从VBO绘制编辑的顶点值

时间:2019-04-07 19:57:50

标签: c# opengl opentk

我可能做的事情确实很愚蠢,所以请纠正我。 我正在尝试使顶点移动,以便...

OnLoad中,我将按照您的设置来设置VBO。 在OnFrameRender中,我尝试编辑顶点,然后执行drawArrays。 但是我无法在OpenTk窗口中看到此更改。进行ConsoleWrite(prymi.vertOne)可以告诉我struct已被编辑(我的确从0到20犯罪),因此我假设此值未在GPU上更新。我尝试了每个VBO BufferUsageHint(动态/静态/流(复制/绘制/读取)),但事实并非如此。我已经读到我应该使用BufferSubData(我还不知道这个概念(所以任何帮助都将是有帮助的),但是编辑通过VBO StreamDraw作为引用传递的对象也应该做到这一点...还是我错了? 谢谢大家:)

struct TrianglePrymi
{

    public Vector2 vertOne;

    public Vector2 vertSec;

    public Vector2 VertThird;

    public TrianglePrymi(Vector2 fi, Vector2 sec, Vector2 thi )
    {
        vertOne = fi;
        vertSec = sec;
        VertThird = thi;
    }
    public void edit(Vector2 a)
    {
        vertOne = a;
    }
    public static int retSize()
    {
        return (3 * Vector2.SizeInBytes);
    }

}
protected override void OnLoad(EventArgs e)
    {

        prymi = new TrianglePrymi(new Vector2(20,20),new Vector2(300,200), new Vector2(530,420));
        ttttt = TrianglePrymi.retSize();
        VBO = GL.GenBuffer();
        GL.BindVertexArray(VAO);
        GL.BindBuffer(BufferTarget.ArrayBuffer, VBO);
        GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)ttttt,ref prymi, BufferUsageHint.DynamicDraw);
        GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
        base.OnLoad(e);

    }



    protected override void OnRenderFrame(FrameEventArgs e)
    {
        Console.WriteLine(prymi.vertOne[0]);
        //Console.WriteLine(prymi.vertSec);
        //Console.WriteLine(prymi.VertThird);
        magicNumber += 1.00f;
        float x = Math.Abs(20 * (float)Math.Sin(magicNumber));
        float y = Math.Abs(20 * (float)Math.Cos(magicNumber));


        GL.EnableClientState(ArrayCap.VertexArray);
        GL.Clear(ClearBufferMask.ColorBufferBit|ClearBufferMask.DepthBufferBit);





        GL.ClearColor(Color.Gray);

        prymi.edit(new Vector2(x, y));
        Vector2 vec = new Vector2(magicNumber, 450);
        Matrix4 world = Matrix4.CreateOrthographicOffCenter(0, widX, 0, heiY, 0, 2000);
        GL.LoadMatrix(ref world);

        GL.Color3(Color.Yellow);
        prymi.vertOne = vec;
        GL.BindBuffer(BufferTarget.ArrayBuffer, VBO);

        GL.VertexPointer(2, VertexPointerType.Float,Vector2.SizeInBytes, 0);

        GL.DrawArrays(BeginMode.Triangles, 0, 3);

        GL.End();
        GL.Flush();
        base.OnRenderFrame(e);
        this.SwapBuffers();
    }

0 个答案:

没有答案