Example #1
0
        static void Render(IntPtr pParam)
        {
            string  txt = "Hello, world!";
            TColor4 color = TColor4.ColorWhite();
            uint    w, h;

            mainFont.GetTextDimensions(txt, out w, out h);
            mainFont.Draw2DSimple((int)((SCREEN_WIDTH - w) / 2), (int)((SCREEN_HEIGHT - h) / 2), txt, ref color);
        }
Example #2
0
        void Render(IntPtr pParam)
        {
            TColor4 c;
            uint    w, h;
            string  acTxt;

            // render game objects
            for (int i = 0; i < _clObjects.Count; i++)
            {
                _clObjects[i].Draw();
            }

            // render in-game user interface
            pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL);
            pFnt.SetScale(1f);

            // if player is dead draw message
            if (!IsPlayerExists())
            {
                acTxt = "You are dead! Press \"Enter\" to restart.";
                pFnt.GetTextDimensions(acTxt, out w, out h);
                c = TColor4.ColorRed();
                pFnt.Draw2DSimple((int)((Res.GameVpWidth - w) / 2), (int)(Res.GameVpHeight - h) / 2, acTxt, ref c);
            }

            // draw help before game start
            if (_uiScore == 0)
            {
                acTxt = "Use \"Arrows\" to move and \"Space Bar\" to shoot.";
                pFnt.GetTextDimensions(acTxt, out w, out h);
                c = TColor4.ColorWhite();
                pFnt.Draw2DSimple((int)((Res.GameVpWidth - w) / 2), (int)(Res.GameVpHeight - h), acTxt, ref c);
            }

            acTxt = "Score: " + _uiScore.ToString();
            pFnt.GetTextDimensions(acTxt, out w, out h);
            c = TColor4.ColorWhite();
            pFnt.Draw2DSimple((int)((Res.GameVpWidth - w) / 2), 0, acTxt, ref c);
        }
Example #3
0
        void Render(IntPtr pParam)
        {
            pTex.Draw2D(0, 0, ScreenWidth, ScreenHeight, 0, 0);

            uint width, height, framecount;

            TColor4 c = TColor4.ColorWhite();

            const string txt = AppCaption;

            pFont.GetTextDimensions(txt, out width, out height);
            pFont.Draw2DSimple((int)((ScreenWidth - width) / 2),
                               (int)((ScreenHeight - height) / 2), txt, ref c);

            pTexSprite.GetFrameSize(out width, out height);
            pTexSprite.FramesCount(out framecount);
            pTexSprite.Draw2DSimple((int)((ScreenWidth - width) / 2),
                                    5, (counter / 2) % framecount);
        }
Example #4
0
        void Render(IntPtr pParameter)
        {
            TRectF  sectionRect;
            uint    txt_w, txt_h;
            TColor4 white = TColor4.ColorWhite();;

            pRender2D.Begin2D();

            // First section with primitives. //
            sectionRect = new TRectF(0f, 0f, ScreenWidth / 2f, ScreenHeight / 2f);
            pRender.EnableScissor(ref sectionRect); // here and below scissor test is used to prevent drawing something to another section of the screen

            DrawPrimitives(sectionRect);
            pRender2D.DrawRectangle(ref sectionRect, ref white);

            const string txtSec1 = "Primitives";

            pFont.GetTextDimensions(txtSec1, out txt_w, out txt_h);
            // here and below draw section label near the end of each section
            pFont.Draw2DSimple((int)((ScreenWidth / 2 - txt_w) / 2), (int)(ScreenHeight / 2 - txt_h), txtSec1, ref white);

            // Second section with font rendering. //
            sectionRect = new TRectF(ScreenWidth / 2f, 0f, ScreenWidth / 2f, ScreenHeight / 2f);
            pRender.EnableScissor(ref sectionRect);

            DrawFont(sectionRect);
            pRender2D.DrawRectangle(ref sectionRect, ref white);

            const string txtSec2 = "Fonts";

            pFont.GetTextDimensions(txtSec2, out txt_w, out txt_h);
            pFont.Draw2DSimple((int)(ScreenWidth / 2 + (ScreenWidth / 2 - txt_w) / 2),
                               (int)(ScreenHeight / 2 - txt_h), txtSec2, ref white);

            // Third section with sprites. //
            sectionRect = new TRectF(0f, ScreenHeight / 2f, ScreenWidth / 2f, ScreenHeight / 2f);
            pRender.EnableScissor(ref sectionRect);

            DrawSprites(sectionRect);
            pRender2D.DrawRectangle(ref sectionRect, ref white);

            const string txtSec3 = "Sprites";

            pFont.GetTextDimensions(txtSec3, out txt_w, out txt_h);
            pFont.Draw2DSimple((int)((ScreenWidth / 2 - txt_w) / 2f), (int)(ScreenHeight - txt_h - 25), txtSec3, ref white);

            // Fourth section with advanced techniques. //
            sectionRect = new TRectF(ScreenWidth / 2f, ScreenHeight / 2f, ScreenWidth / 2f, ScreenHeight / 2f);
            pRender.EnableScissor(ref sectionRect);

            DrawAdvanced(sectionRect);
            pRender2D.DrawRectangle(ref sectionRect, ref white);

            const string txtSec4 = "Advanced";

            pFont.GetTextDimensions(txtSec4, out txt_w, out txt_h);
            pFont.Draw2DSimple((int)(ScreenWidth / 2 + (ScreenWidth / 2 - txt_w) / 2f), (int)(ScreenHeight - txt_h - 25), txtSec4, ref white);

            pRender.DisableScissor(); // The way to turn off scissor test, you must do it manually before the end of the frame.

            pRender2D.End2D();
        }