public static void DrawTexturedQuad(Matrix4 transform, Texture2D texture, Vector2 size, Vector4 texCoords, float yOffset = 0) { bool wasTexEnabled = GL.IsEnabled(EnableCap.Texture2D); GL.Enable(EnableCap.Texture2D); var positions = new Vector4(0, 0, size.X, size.Y); VertVT CreateVert(Vector2 pos, Vector2 tex) { return(new VertVT(new Vector3(pos.X, yOffset, pos.Y), tex)); } var quadVerts = new VertVT[] { CreateVert(positions.Xy, texCoords.Xy), CreateVert(positions.Xw, texCoords.Xw), CreateVert(positions.Zw, texCoords.Zw), CreateVert(positions.Zy, texCoords.Zy) }; SimpleTextureShader.Use(); SimpleTextureShader.ModelMatrix.Set(transform); texture.Bind(TextureUnit.Texture5); SimpleTextureShader.Texture.Set(TextureUnit.Texture5); //SimpleTextureShader.Texture.BindTexture(TextureUnit.Texture5, texture); var vertBuffer = new VertexArrayBuffer <VertVT>(); vertBuffer.SetElements(quadVerts); vertBuffer.Bind(); vertBuffer.BindAttribute(SimpleTextureShader.Position, 0); vertBuffer.BindAttribute(SimpleTextureShader.TexCoord, 12); vertBuffer.DrawArray(PrimitiveType.Quads, 0, 4); vertBuffer.Dispose(); SimpleTextureShader.Texture.Set(TextureUnit.Texture0); texture.Bind(TextureUnit.Texture0); if (!wasTexEnabled) { GL.Disable(EnableCap.Texture2D); } }
public static void ReleaseResources() { if (ColorShader != null) { ColorShader.Dispose(); ColorShader = null; } if (WireframeShader != null) { WireframeShader.Dispose(); WireframeShader = null; } if (WireframeShader2 != null) { WireframeShader2.Dispose(); WireframeShader2 = null; } if (ModelShader != null) { ModelShader.Dispose(); ModelShader = null; } if (StudConnectionShader != null) { StudConnectionShader.Dispose(); StudConnectionShader = null; } if (SimpleTextureShader != null) { SimpleTextureShader.Dispose(); SimpleTextureShader = null; } if (GridShader != null) { GridShader.Dispose(); GridShader = null; } }
public static void InitializeMatrices(Camera camera) { var viewMatrix = camera.GetViewMatrix(); var projection = camera.GetProjectionMatrix(); WireframeShader.Use(); WireframeShader.ViewMatrix.Set(viewMatrix); WireframeShader.Projection.Set(projection); WireframeShader2.Use(); WireframeShader2.ViewMatrix.Set(viewMatrix); WireframeShader2.Projection.Set(projection); ColorShader.Use(); ColorShader.ViewMatrix.Set(viewMatrix); ColorShader.Projection.Set(projection); ModelShader.Use(); ModelShader.ViewMatrix.Set(viewMatrix); ModelShader.Projection.Set(projection); ModelShader.ViewPosition.Set(camera.Position); StudConnectionShader.Use(); StudConnectionShader.ViewMatrix.Set(viewMatrix); StudConnectionShader.Projection.Set(projection); SimpleTextureShader.Use(); SimpleTextureShader.ViewMatrix.Set(viewMatrix); SimpleTextureShader.Projection.Set(projection); if (UIRenderHelper.Freetype6Loaded) { UIRenderHelper.TextRenderer.ProjectionMatrix = projection; UIRenderHelper.TextRenderer.DrawingPrimitives.Clear(); } TextViewMatrix = viewMatrix; GL.UseProgram(0); }