【问题标题】:Draw a triangle with OpenGL and GLKViewController with Xamarin使用 OpenGL 绘制三角形,使用 Xamarin 绘制 GLKViewController
【发布时间】:2015-01-09 21:27:13
【问题描述】:

我正在尝试使用 GLViewController 绘制一个你好三角形(或四边形),就像在 OpenGL 的 this Xamarin 示例中一样

该示例创建自己的 FrameBuffers 和其他逻辑,据我了解,GLView 通过阅读 Apple 文档here 已经完成了@

我正在使用从主 Storyboard 中的 GLKViewController 派生的类

该类应该用动画的黑色到红色清除背景(实际上可以工作)并在屏幕上绘制一个四边形(不是)

这是我目前得到的代码:

partial class GpuImageView : MonoTouch.GLKit.GLKViewController
{
    public GpuImageView (IntPtr handle) : base (handle)
    {

    }

    GLKView glkView;
    EAGLContext Context;

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        //create the rendering context
        Context = new EAGLContext(EAGLRenderingAPI.OpenGLES2);

        //get the view:
        glkView = (GLKView)this.View;

        glkView.Context = Context;
        glkView.MultipleTouchEnabled = true;

        glkView.DrawInRect  += Draw;

    }

    public override void Update()
    {
        color = ( color > 1.0F ) ? (0F ) : (color +   1.0F / 30.0F);
    }

    float color ;
    void Draw (object sender, GLKViewDrawEventArgs e)
    {
        GL.Viewport(0, 0, glkView.DrawableWidth, glkView.DrawableHeight);

        //this matrix initialization is copied from the OpenGLES example:
        GL.MatrixMode (All.Projection);
        GL.LoadIdentity ();
        GL.Ortho (-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
        GL.MatrixMode(All.Modelview);
        GL.LoadIdentity();

        float[] squareVertices = {
            -0.5f, -0.5f,
            0.5f, -0.5f,
            -0.5f, 0.5f, 
            0.5f, 0.5f,
        };
        byte[] squareColors = {
            255, 255,   0, 255,
            0,   255, 255, 255,
            0,     0,    0,  0,
            255,   0,  255, 255,
        };


        //The color clear is working fine :)
        GL.ClearColor(color, 0F, 0F, 1F);
        GL.Clear( ClearBufferMask.ColorBufferBit |  ClearBufferMask.DepthBufferBit);

        //The quad never draws:
        GL.VertexPointer (2, All.Float, 0, squareVertices);
        GL.EnableClientState (All.VertexArray);
        GL.ColorPointer (4, All.UnsignedByte, 0, squareColors);
        GL.EnableClientState (All.ColorArray);

        GL.DrawArrays (All.TriangleStrip, 0, 4);
    }

这是我正在使用的库(在项目中添加了“OpenTK-1.0”):

using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.CodeDom.Compiler;
using MonoTouch.OpenGLES;
using MonoTouch.GLKit;
using OpenTK.Graphics.ES11;
using MonoTouch.CoreAnimation;

【问题讨论】:

    标签: opengl xamarin geometry glkit


    【解决方案1】:

    我用 OpenGLES2 初始化 EAGL 上下文,改成 OpenGLES1 解决了问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-07
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 2020-12-08
      • 2015-05-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多