[英]Draw a triangle with OpenGL and GLKViewController with Xamarin
我想畫一個三角形打招呼(或四)與GLViewController就像在這個 Xamarin例如對OpenGL
該示例創建了自己的FrameBuffers和其他邏輯,據我了解,GLView已通過閱讀此處的Apple文檔完成了此操作
我正在使用從主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;
我正在使用OpenGLES2初始化EAGL上下文,更改為OpenGLES1解決了該問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.