/// <summary>Draws a 3D cube</summary> /// <param name="VAO"></param> /// <param name="Position">The position in world-space</param> /// <param name="Direction">The direction vector</param> /// <param name="Up">The up vector</param> /// <param name="Side">The side vector</param> /// <param name="Size">A 3D vector describing the size of the cube</param> /// <param name="Camera">The camera position</param> /// <param name="TextureIndex">The texture to apply</param> private void DrawRetained(VertexArrayObject VAO, Vector3 Position, Vector3 Direction, Vector3 Up, Vector3 Side, Vector3 Size, Vector3 Camera, Texture TextureIndex) { renderer.DefaultShader.Activate(); renderer.ResetShader(renderer.DefaultShader); // matrix renderer.DefaultShader.SetCurrentProjectionMatrix(renderer.CurrentProjectionMatrix); renderer.DefaultShader.SetCurrentModelViewMatrix(Matrix4D.Scale(Size) * (Matrix4D) new Transformation(Direction, Up, Side) * Matrix4D.CreateTranslation(Position.X - Camera.X, Position.Y - Camera.Y, -Position.Z + Camera.Z) * renderer.CurrentViewMatrix); // texture if (TextureIndex != null && renderer.currentHost.LoadTexture(TextureIndex, OpenGlTextureWrapMode.ClampClamp)) { renderer.DefaultShader.SetIsTexture(true); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, TextureIndex.OpenGlTextures[(int)OpenGlTextureWrapMode.ClampClamp].Name); } else { GL.Disable(EnableCap.Texture2D); } // render polygon VAO.Bind(); VAO.Draw(PrimitiveType.Quads); renderer.lastVAO = -1; VAO.UnBind(); renderer.DefaultShader.Deactivate(); GL.Disable(EnableCap.Texture2D); }
/// <summary>Renders a static frustrum based background</summary> /// <param name="data">The background to render</param> /// <param name="alpha">The alpha level</param> /// <param name="scale">The scale</param> private void RenderStaticBackgroundRetained(StaticBackground data, float alpha, float scale) { Texture t = data.Texture; if (data.Texture != null && renderer.currentHost.LoadTexture(ref t, OpenGlTextureWrapMode.RepeatClamp)) { renderer.LastBoundTexture = t.OpenGlTextures[(int)OpenGlTextureWrapMode.RepeatClamp]; if (alpha == 1.0f) { GL.Disable(EnableCap.Blend); } else { GL.Enable(EnableCap.Blend); } if (data.VAO == null) { data.CreateVAO(renderer.DefaultShader.VertexLayout, renderer); } renderer.DefaultShader.Activate(); renderer.ResetShader(renderer.DefaultShader); // matrix renderer.DefaultShader.SetCurrentProjectionMatrix(renderer.CurrentProjectionMatrix); renderer.DefaultShader.SetCurrentModelViewMatrix(Matrix4D.Scale(scale) * renderer.CurrentViewMatrix); // fog if (renderer.OptionFog) { renderer.DefaultShader.SetIsFog(true); renderer.DefaultShader.SetFog(renderer.Fog); } // texture GL.BindTexture(TextureTarget.Texture2D, t.OpenGlTextures[(int)OpenGlTextureWrapMode.RepeatClamp].Name); renderer.LastBoundTexture = null; // alpha test renderer.SetAlphaFunc(AlphaFunction.Greater, 0.0f); // blend mode renderer.DefaultShader.SetOpacity(alpha); // render polygon VertexArrayObject VAO = (VertexArrayObject)data.VAO; VAO.Bind(); renderer.lastVAO = VAO.handle; for (int i = 0; i + 11 < 32 * 12; i += 12) { VAO.Draw(PrimitiveType.Triangles, i, 12); } renderer.RestoreBlendFunc(); } }
/// <summary>Renders a static frustrum based background</summary> /// <param name="data">The background to render</param> /// <param name="alpha">The alpha level</param> /// <param name="scale">The scale</param> private void RenderStaticBackground(StaticBackground data, float alpha, float scale) { if (data.Texture != null && renderer.currentHost.LoadTexture(data.Texture, OpenGlTextureWrapMode.RepeatClamp)) { GL.Enable(EnableCap.Texture2D); if (alpha == 1.0f) { GL.Disable(EnableCap.Blend); } else { GL.Enable(EnableCap.Blend); } if (data.VAO == null) { data.CreateVAO(); } renderer.DefaultShader.Activate(); renderer.ResetShader(renderer.DefaultShader); // matrix renderer.DefaultShader.SetCurrentProjectionMatrix(renderer.CurrentProjectionMatrix); renderer.DefaultShader.SetCurrentModelViewMatrix(Matrix4D.Scale(scale) * renderer.CurrentViewMatrix); // fog if (renderer.OptionFog) { renderer.DefaultShader.SetIsFog(true); renderer.DefaultShader.SetFogStart(renderer.Fog.Start); renderer.DefaultShader.SetFogEnd(renderer.Fog.End); renderer.DefaultShader.SetFogColor(new Color4(renderer.Fog.Color.R, renderer.Fog.Color.G, renderer.Fog.Color.B, 255)); } // texture renderer.DefaultShader.SetIsTexture(true); renderer.DefaultShader.SetTexture(0); GL.BindTexture(TextureTarget.Texture2D, data.Texture.OpenGlTextures[(int)OpenGlTextureWrapMode.RepeatClamp].Name); // alpha test renderer.SetAlphaFunc(AlphaFunction.Greater, 0.0f); // blend mode renderer.DefaultShader.SetOpacity(alpha); // render polygon VertexArrayObject VAO = (VertexArrayObject)data.VAO; VAO.Bind(); for (int i = 0; i + 9 < 32 * 10; i += 10) { VAO.Draw(renderer.DefaultShader.VertexLayout, PrimitiveType.Quads, i, 4); VAO.Draw(renderer.DefaultShader.VertexLayout, PrimitiveType.Triangles, i + 4, 3); VAO.Draw(renderer.DefaultShader.VertexLayout, PrimitiveType.Triangles, i + 7, 3); } VAO.UnBind(); GL.BindTexture(TextureTarget.Texture2D, 0); renderer.DefaultShader.Deactivate(); GL.Disable(EnableCap.Texture2D); renderer.RestoreBlendFunc(); } }