Example #1
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);

            Batch.Render();
            TextureBatch.Render();
            AtlasBatch.Render();

            Context.SwapBuffers();

            base.OnRenderFrame(e);
        }
Example #2
0
        public virtual void Draw(SpriteBatch spriteBatch)
        {
            // Draw 3D groups
            if (DrawGroups.Count > 0)
            {
                // Set default states as using spritebatch can bork them
                GraphicsDevice dvc = parentGame.GraphicsDevice;
                dvc.SamplerStates[0]  = SamplerState.LinearWrap;
                dvc.RasterizerState   = RasterizerState.CullNone;
                dvc.BlendState        = BlendState.AlphaBlend;
                dvc.DepthStencilState = DepthStencilState.Default;

                // Draw 3D buckets
                foreach (KeyValuePair <int, List <IDrawable3D> > kvp in DrawGroups)
                {
                    // Call the group pre-draw if it exists
                    if (PreDrawGroup != null)
                    {
                        PreDrawGroup(kvp.Key);
                    }

                    foreach (IDrawable3D drawable3D in kvp.Value)
                    {
                        if (drawable3D.IsVisible)
                        {
                            drawable3D.Draw3D();
                        }
                    }

                    // After the IDrawable3D objects have beend drawn,
                    // call RenderBatch.Render() to flush any added triangles
                    if (renderBatch != null && renderBatch.HasTriangles)
                    {
                        Debug.Assert(camera3D != null);

                        Matrix view = camera3D.MatrixView;
                        Matrix proj = camera3D.MatrixProj;

                        renderBatch.Render(ref renderBatchWorldTransform, ref view, ref proj);
                        renderBatch.Reset();
                    }

                    // Call the group post-draw if it exists
                    if (PostDrawGroup != null)
                    {
                        PostDrawGroup(kvp.Key);
                    }
                }
            }


            // Draw 2D layers with SpriteBatch
            for (int i = Layers.Count - 1; i >= 0; --i)
            {
                Layer2D layer = Layers[i];
                if (layer.Sprites.Count > 0)
                {
                    if (Camera2D != null)
                    {
                        LastViewMatrix2D = Camera2D.GetViewMatrix(layer.Parallax);
                    }
                    spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied,
                                      null, null, null, null,
                                      LastViewMatrix2D);

                    foreach (IDrawable2D e in layer.Sprites)
                    {
                        if (e.IsVisible)
                        {
                            e.Draw2D(spriteBatch);
                        }
                    }
                    spriteBatch.End();
                }
            }

            if (Physics != null && Physics.DebugView != null && EnablePhysicsDebug)
            {
                float  worldScale = ConvertUnits.ToSimUnits(1f);
                Matrix view       = Camera2D.GetViewMatrix(new Vector2(worldScale));
                Physics.RenderDebugView(ref view);
            }
        }