/// <summary> /// Creates a quad from screen coordinates. /// </summary> /// <param name="position">Position.</param> /// <param name="size">Size.</param> /// <param name="deviceNormalized">If set to <c>true</c> the position and size are already device normalized.</param> public void CreateQuad(Vector2 position, Vector2 size, bool deviceNormalized) { RVertexData2D[] vertices = new RVertexData2D[4]; short[] indices = new short[6] { 0, 1, 2, 0, 2, 3 }; if (!deviceNormalized) { // Kinda like a 2d unproject, screen coords to device normal coords... RViewport viewport = REngine.Instance._viewport; Vector2 w = new Vector2(viewport.Width, viewport.Height); Vector2 l = size; Vector2 d = (l / w); size.X = d.X; size.Y = d.Y; Vector2 p = (position / w); position.X = p.X; position.Y = p.Y; } vertices[0] = new RVertexData2D(new Vector2(position.X, position.Y), new Vector2(0, 0)); vertices[1] = new RVertexData2D(new Vector2(position.X, position.Y + size.Y), new Vector2(0, 1)); vertices[2] = new RVertexData2D(new Vector2(position.X + size.X, position.Y + size.Y), new Vector2(1, 1)); vertices[3] = new RVertexData2D(new Vector2(position.X + size.X, position.Y), new Vector2(1, 0)); VertexBuffer = new RVertexBuffer(vertices[0].Declaration, 4, RBufferUsage.WriteOnly); VertexBuffer.SetData <RVertexData2D>(vertices); _index = new RIndexBuffer(typeof(short), 6, RBufferUsage.WriteOnly); _index.SetData <short>(indices); }
internal void Init() { REngine.CheckGLError(); defaultShader = new RShader(); defaultShader.Load(RShaderResources.Basic2dEffectVert, RShaderResources.Basic2dEffectFrag, null); Fonts.Add(RFont.Default); quad = new RMeshBuilder(); quad.CreateQuad(new Vector2(0, 0), new Vector2(1, 1), true); quadVerts = new RVertexData2D[4]; quadVerts[0] = new RVertexData2D(new Vector2(-1, -1), new Vector2(0, 0)); quadVerts[1] = new RVertexData2D(new Vector2(1, -1), new Vector2(1, 0)); quadVerts[2] = new RVertexData2D(new Vector2(1, 1), new Vector2(1, 1)); quadVerts[3] = new RVertexData2D(new Vector2(-1, 1), new Vector2(0, 1)); vertexQuad2D = new RVertexBuffer(quadVerts[0].Declaration, 4, RBufferUsage.WriteOnly); vertexQuad2D.SetData <RVertexData2D>(quadVerts); indexQuad2D = new RIndexBuffer(typeof(short), 6, RBufferUsage.WriteOnly); indexQuad2D.SetData <short>(new short[6] { 0, 1, 2, 0, 2, 3 }, 0, 6); initialized = true; }