/// スプライト描画 public static void DrawSprite(Sprite sprite, int offsetX = 0, int offsetY = 0, float alphaRate = 1.0f) { if (!sprite.Visible) { return; } var modelMatrix = sprite.CreateModelMatrix(offsetX, offsetY); var worldViewProj = projectionMatrix * viewMatrix * modelMatrix; textureShaderProgram.SetUniformValue(0, ref worldViewProj); int alphaRateId = textureShaderProgram.FindUniform("AlphaRate"); if (alphaRateId >= 0) { textureShaderProgram.SetUniformValue(alphaRateId, alphaRate); } graphics.SetShaderProgram(textureShaderProgram); graphics.SetVertexBuffer(0, sprite.Vertices); graphics.SetTexture(0, sprite.Texture); graphics.Enable(EnableMode.Blend); graphics.Disable(EnableMode.DepthTest); graphics.Disable(EnableMode.CullFace); graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.OneMinusSrcAlpha); graphics.DrawArrays(DrawMode.TriangleFan, 0, 4); }
/// 描画処理 public override bool DoDraw2(DemoGame.GraphicsDevice graphDev, Vector3 BasePos) { if (!sprite.Visible) { return(false); } // sprite.SetDrawRect(0,0,10,10); var currentMatrix = CalcSpriteMatrix(graphDev.GetCurrentCamera().Pos, BasePos); var modelMatrix = sprite.CreateModelMatrix(0, 0); var worldViewProj = graphDev.GetCurrentCamera().Projection *graphDev.GetCurrentCamera().View *currentMatrix *modelMatrix; textureShaderProgram.SetUniformValue(0, ref worldViewProj); float alphaRate = 1.0f; int alphaRateId = textureShaderProgram.FindUniform("AlphaRate"); if (alphaRateId >= 0) { textureShaderProgram.SetUniformValue(alphaRateId, alphaRate); } graphDev.Graphics.SetShaderProgram(textureShaderProgram); graphDev.Graphics.SetVertexBuffer(0, sprite.Vertices); graphDev.Graphics.SetTexture(0, sprite.Texture); graphDev.Graphics.Enable(EnableMode.Blend); graphDev.Graphics.Disable(EnableMode.DepthTest); graphDev.Graphics.Disable(EnableMode.CullFace); graphDev.Graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.OneMinusSrcAlpha); graphDev.Graphics.DrawArrays(DrawMode.TriangleFan, 0, 4); return(true); }
/// スプライト描画 public static void DrawSprite(Sprite sprite, int offsetX = 0, int offsetY = 0, float alphaRate = 1.0f) { if(!sprite.Visible){ return; } var modelMatrix = sprite.CreateModelMatrix(offsetX, offsetY); var worldViewProj = projectionMatrix * viewMatrix * modelMatrix; textureShaderProgram.SetUniformValue(0, ref worldViewProj); int alphaRateId = textureShaderProgram.FindUniform("AlphaRate"); if (alphaRateId >= 0) { textureShaderProgram.SetUniformValue(alphaRateId, alphaRate); } graphics.SetShaderProgram(textureShaderProgram); graphics.SetVertexBuffer(0, sprite.Vertices); graphics.SetTexture(0, sprite.Texture); graphics.Enable(EnableMode.Blend); graphics.Disable(EnableMode.DepthTest); graphics.Disable(EnableMode.CullFace); graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.OneMinusSrcAlpha); graphics.DrawArrays(DrawMode.TriangleFan, 0, 4); }