void Update(IntPtr pParameter) { // render into the texture for advanced example part RenderPlanetInToTexture(); // create water polygon for advanced example part TRectF section_adv_rect = new TRectF(ScreenWidth / 2f, ScreenHeight / 2f, ScreenWidth / 2f, ScreenHeight / 2f); float bottom_y = section_adv_rect.y + section_adv_rect.height; float right_x = section_adv_rect.x + section_adv_rect.width; float texture_coord_koeff = 75f; waterWaves.Clear(); waterWaves.Add(new TVertex2((int)section_adv_rect.x, (int)bottom_y, (int)(section_adv_rect.x / texture_coord_koeff), (int)(bottom_y / texture_coord_koeff), (int)0.274f, (int)0.863f, (int)0.863f, (int)1f)); for (int i = 0; i < 33; ++i) { float x = section_adv_rect.x + i * section_adv_rect.width / 32f, y = (float)((section_adv_rect.y + section_adv_rect.height / 2f) + Math.Sin((float)counter / 20f + (float)i * 50f) * 15f); waterWaves.Add(new TVertex2(x, y, x / texture_coord_koeff, y / texture_coord_koeff, 0.274f, 0.863f, 0.863f, 1f)); } waterWaves.Add(new TVertex2(right_x, bottom_y, right_x / texture_coord_koeff, bottom_y / texture_coord_koeff, 0.274f, 0.863f, 0.863f, 1f)); // other stuff stRandomCol = new TColor4((byte)(rand.Next(255)), (byte)(rand.Next(255)), (byte)(rand.Next(255)), 255); ++counter; }
void DrawFont(TRectF screen) { string txt; uint width, height; TColor4 c; txt = "I'm rotating... +_+"; pFontBold.GetTextDimensions(txt, out width, out height); c = TColor4.ColorWhite(); pFontBold.Draw2D(screen.x + screen.width - width - 10f, 200, txt, ref c, counter % 360); txt = "I'm just right aligned text. -_-"; pFontBold.GetTextDimensions(txt, out width, out height); pFontBold.Draw2D((int)(screen.x + screen.width - width), 10, txt, ref c); txt = "I have a shadow! ;-)"; pFontBold.GetTextDimensions(txt, out width, out height); c = TColor4.ColorBlack(); pFontBold.Draw2D((int)(screen.x + screen.width - width - 7f), 53, txt, ref c); c = TColor4.ColorWhite(); pFontBold.Draw2D((int)(screen.x + screen.width - width - 10f), 50, txt, ref c); txt = "Cool colored me! ^_^"; pFontBold.GetTextDimensions(txt, out width, out height); TColor4 c1 = TColor4.ColorRed(); TColor4 c2 = TColor4.ColorGreen(); pRender2D.SetVerticesColors(ref c1, ref c2, ref c1, ref c2); c = TColor4.ColorWhite(); pFontBold.Draw2D(screen.x + screen.width - width - 10f, 100f, txt, ref c, 0, true); txt = "I'm randomly colored... >_<"; pFont.Draw2D(screen.x + 5f, 10, txt, ref stRandomCol); txt = "I'm per vertex colored! -_0"; TColor4 c3 = TColor4.ColorAqua(); TColor4 c4 = TColor4.ColorOrange(); pRender2D.SetVerticesColors(ref c3, ref c3, ref c4, ref c4); c = TColor4.ColorWhite(); pFontBold.Draw2D(screen.x + 5f, 50f, txt, ref c, 0, true); txt = "А я могу говорить по-русски! [:-|"; c = TColor4.ColorRed(); pFont.Draw2D(screen.x + 5f, 100, txt, ref c); txt = "I'm scaling... o_O"; pFontBold.SetScale((float)Math.Abs(Math.Sin(counter / 50f)) * 2f); c = TColor4.ColorWhite(); pFontBold.Draw2D(screen.x + 5f, 200, txt, ref c); pFontBold.SetScale(1f); txt = "I am just very brutal..!"; pFontHard.GetTextDimensions(txt, out width, out height); c = TColor4.ColorOfficialOrange(); pFontHard.Draw2D((int)(screen.x + (screen.width - width) / 2f), 300f, txt, ref c); }
void DrawAdvanced(TRectF screen) { pTexBg.Draw2D((int)screen.x, (int)screen.y, (uint)screen.width, (uint)screen.height, 0, 0); TPoint2 pos = new TPoint2(screen.x + screen.width - 160f, screen.y + 20f); TPoint2 dim = new TPoint2(128f, 128f); pRender2D.DrawTexture(pTexPlanetRenderIn, ref pos, ref dim, 0, E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_FLIP_VERTICALLY /* because render targets are flipped */); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); // not to triangulate complex polygon every frame we can batch it this way and triangulation will be done only after update tick pRender2D.BeginBatch(false); pRender2D.DrawPolygon(pTexAnimWater[counter / 5 % 11], ref waterWaves.ToArray()[0], (uint)waterWaves.Count, E_PRIMITIVE2D_FLAGS.PF_FILL); pRender2D.EndBatch(); uint w, h; pTexJellyFish.GetDimensions(out w, out h); float x_offset = (float)(Math.Abs(Math.Cos(counter / 20f)) * 50); float y_offset = (float)(Math.Sin(counter / 10f) * 75); TPoint2 jellyPos = new TPoint2(screen.x + 175f, screen.y + 200f); TPoint2 vert1 = new TPoint2(); TPoint2 vert2 = new TPoint2(); TPoint2 vert3 = new TPoint2(x_offset, -y_offset); TPoint2 vert4 = new TPoint2(-x_offset, -y_offset); pRender2D.SetVerticesOffsets(ref vert1, ref vert2, ref vert3, ref vert4); TColor4 c = TColor4.ColorViolet(); pRender2D.SetColorMix(ref c); dim = new TPoint2(w / 2f, h / 2f); pRender2D.DrawTexture(pTexJellyFish, ref jellyPos, ref dim, -45f, E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_VERTICES_OFFSETS | E_EFFECT2D_FLAGS.EF_COLOR_MIX); pTexLightRound.GetDimensions(out w, out h); pos = jellyPos - new TPoint2(90f, 15f); dim = new TPoint2(w, h); pRender2D.DrawTexture(pTexLightRound, ref pos, ref dim, 0, E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX); }
void DrawSprites(TRectF screen) { pTexGrass.Draw2D((int)screen.x, (int)screen.y, (uint)screen.width, (uint)screen.height, 0, 0); pTexGirl.Draw2DSimple((int)(screen.x + 400), (int)(screen.y + 30), (counter / 5) % 16); // simpliest way to draw animated sprite // draw tank uint width, height; TPoint2 scale = new TPoint2(2f, 2f); // scale X and Y axes by two pRender2D.SetScale(ref scale); pTexTankBody.GetDimensions(out width, out height); TPoint2 pos = new TPoint2(screen.x + 50f, screen.y + 150f); TPoint2 dimension = new TPoint2(width, height); pRender2D.DrawTexture(pTexTankBody, ref pos, ref dimension, 0, E_EFFECT2D_FLAGS.EF_ALPHA_TEST /* better than blending if we want to have sharp edges */ | E_EFFECT2D_FLAGS.EF_SCALE); pTexTankTurret.GetDimensions(out width, out height); TPoint2 rot = new TPoint2(48f, 64f); pRender2D.SetRotationPoint(ref rot); // rotate turret around it's base center, not the center of the image TPoint2 turretCenter = new TPoint2(screen.x + 50f - 10f, screen.y + 150f + 18f); float turretAngle = (float)(-30f + Math.Sin(counter / 15f) * 20f); dimension = new TPoint2(width, height); pRender2D.DrawTexture(pTexTankTurret, ref turretCenter, ref dimension, turretAngle, E_EFFECT2D_FLAGS.EF_ALPHA_TEST | E_EFFECT2D_FLAGS.EF_SCALE | E_EFFECT2D_FLAGS.EF_ROTATION_POINT); // draw light at the end of tank cannon pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); pTexLight.GetFrameSize(out width, out height); dimension = new TPoint2(width, height); pos = turretCenter + new TPoint2((float)Math.Cos(ToRad(turretAngle)) * 165f, (float)(Math.Sin(ToRad(turretAngle - 15f)) * 165f)); pRender2D.DrawTextureSprite(pTexLight, ref pos, ref dimension, (counter / 2) % 14, 0, E_EFFECT2D_FLAGS.EF_BLEND); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); // switch back blending mode to common one }
void Render(IntPtr pParam) { if (pRender2D == null) { return; } pRender2D.Begin2D(); // Draw sky TPoint2 ps = new TPoint2(); TPoint2 pt = new TPoint2(GAME_VP_WIDTH, GAME_VP_HEIGHT); pRender2D.DrawTexture(pSky, ref ps, ref pt, 0, E_EFFECT2D_FLAGS.EF_NONE); // Draw background ps = new TPoint2(cameraPosition.x / 1.5f, cameraPosition.y / 1.5f); pt = new TPoint2(cameraScale, cameraScale); pRender2D.SetCamera(ref ps, cameraAngle, ref pt); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); ps = new TPoint2(-200f, 150f); pt = new TPoint2(1399f, 517f); TRectF rect = new TRectF(0f, 905f, 1399f, 517f); pRender2D.DrawTextureCropped(pBg, ref ps, ref pt, ref rect, 0.0f, E_EFFECT2D_FLAGS.EF_BLEND); // Draw moving fog on background ps = new TPoint2(cameraPosition.x / 1.2f, cameraPosition.y / 1.2f); pt = new TPoint2(cameraScale, cameraScale); pRender2D.SetCamera(ref ps, cameraAngle, ref pt); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); // Sometimes it's better to batch a lot of similar objects. pRender2D.BeginBatch(); TColor4 col = new TColor4(255, 255, 255, 64); pRender2D.SetColorMix(ref col); for (uint i = 0; i < 22; ++i) { for (uint j = 0; j < 2; ++j) { ps = new TPoint2((float)(500f + Math.Sin((float)i) * 600f - Math.Cos((float)counter / 50f) * 10f * (i % 4)), (float)(475f + Math.Sin((float)j * 2.5f) * 150f - Math.Sin((float)counter / 50f) * 20f * (i % 3))); pt = new TPoint2(250f, 150f); pRender2D.DrawTexture(pFog, ref ps, ref pt, 0f, (E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX)); } } pRender2D.EndBatch(); // Draw foreground scene // Setup camera and blending pt = new TPoint2(cameraScale, cameraScale); pRender2D.SetCamera(ref cameraPosition, cameraAngle, ref pt); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); // Owl col = new TColor4(150, 150, 150, 255); pRender2D.SetColorMix(ref col); // make sprite little darker ps = new TPoint2(owlX, 425f); pt = new TPoint2(48f, 128f); E_EFFECT2D_FLAGS EEF = (E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX | (owlGoLeft ? E_EFFECT2D_FLAGS.EF_FLIP_HORIZONTALLY : E_EFFECT2D_FLAGS.EF_DEFAULT)); pRender2D.DrawTextureSprite(pOwl, ref ps, ref pt, (uint)(counter / 3) % 15, 0f, EEF); // Draw tree ps = new TPoint2(); pt = new TPoint2(1399f, 900f); rect = new TRectF(0f, 0f, 1399f, 900f); pRender2D.DrawTextureCropped(pBg, ref ps, ref pt, ref rect, 0f, E_EFFECT2D_FLAGS.EF_BLEND); // Glowing disc under moving light pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); ps = new TPoint2(-100f, 0f); pt = new TPoint2(); pRender2D.SetVerticesOffsets(ref ps, ref ps, ref pt, ref pt); col = new TColor4(65, 59, 193, 255); pRender2D.SetColorMix(ref col); ps = new TPoint2(lights[0].x - 32f, lights[0].y + 64f); pt = new TPoint2(256f, 256f); pRender2D.DrawTexture(pLightRound, ref ps, ref pt, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_OFFSETS | E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX)); // Girl Shadow pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); ps = new TPoint2(-150f + (float)Math.Cos((float)counter / 100f) * 100f, -55f); pt = new TPoint2(-50f + (float)Math.Cos((float)counter / 100f) * 100f, -55f); TPoint2 pp = new TPoint2(15f, 5f); pRender2D.SetVerticesOffsets(ref ps, ref pt, ref pp, ref pp); col = new TColor4(0, 0, 0, 128); pRender2D.SetColorMix(ref col); ps = new TPoint2(550f, 725f); pt = new TPoint2(60f, 120f); pRender2D.DrawTextureSprite(pTexGirl, ref ps, ref pt, (uint)(counter / 5) % 16, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_OFFSETS | E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX)); // Girl Sprite pRender2D.DrawTextureSprite(pTexGirl, ref ps, ref pt, (uint)(counter / 5) % 16, 0f, E_EFFECT2D_FLAGS.EF_BLEND); // Lights pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); for (uint i = 0; i < 5; ++i) { ps = new TPoint2(lights[i].x, lights[i].y); pt = new TPoint2(64f, 128f); pRender2D.DrawTextureSprite(pLight, ref ps, ref pt, (uint)(counter / 2) % 14, 0f, E_EFFECT2D_FLAGS.EF_BLEND); } pRender2D.ResetCamera(); // We must calculate correct coordinates in game space because game resolution and screen resolution can be different. TPoint2 pos; pRender2D.AbsoluteToResolutionCorrect(ref stMousePos, out pos); ps = new TPoint2(pos.x - 37, pos.y - 37); pt = new TPoint2(75f, 75f); pRender2D.DrawTextureSprite(pVox, ref ps, ref pt, (uint)(counter / 2) % 16, 0f, E_EFFECT2D_FLAGS.EF_BLEND); uint tw, th; pFont.GetTextDimensions(HELP_TEXT, out tw, out th); col = TColor4.White; pFont.Draw2D((float)((GAME_VP_WIDTH - tw) / 2), (float)(GAME_VP_HEIGHT - th), HELP_TEXT, ref col); pRender2D.End2D(); }
void Render(IntPtr pParam) { if (pRender2D == null) return; pRender2D.Begin2D(); // Draw sky TPoint2 ps = new TPoint2(); TPoint2 pt = new TPoint2(GAME_VP_WIDTH, GAME_VP_HEIGHT); pRender2D.DrawTexture(pSky, ref ps, ref pt, 0, E_EFFECT2D_FLAGS.EF_NONE); // Draw background ps = new TPoint2(cameraPosition.x / 1.5f, cameraPosition.y / 1.5f); pt = new TPoint2(cameraScale, cameraScale); pRender2D.SetCamera(ref ps, cameraAngle, ref pt); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); ps = new TPoint2(-200f, 150f); pt = new TPoint2(1399f, 517f); TRectF rect = new TRectF(0f, 905f, 1399f, 517f); pRender2D.DrawTextureCropped(pBg, ref ps, ref pt, ref rect, 0.0f, E_EFFECT2D_FLAGS.EF_BLEND); // Draw moving fog on background ps = new TPoint2(cameraPosition.x / 1.2f, cameraPosition.y / 1.2f); pt = new TPoint2(cameraScale, cameraScale); pRender2D.SetCamera(ref ps, cameraAngle, ref pt); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); // Sometimes it's better to batch a lot of similar objects. pRender2D.BeginBatch(); TColor4 col = new TColor4(255, 255, 255, 64); pRender2D.SetColorMix(ref col); for (uint i = 0; i < 22; ++i) for (uint j = 0; j < 2; ++j) { ps = new TPoint2((float)(500f + Math.Sin((float)i) * 600f - Math.Cos((float)counter / 50f) * 10f * (i % 4)), (float)(475f + Math.Sin((float)j * 2.5f) * 150f - Math.Sin((float)counter / 50f) * 20f * (i % 3))); pt = new TPoint2(250f, 150f); pRender2D.DrawTexture(pFog, ref ps, ref pt, 0f, (E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX)); } pRender2D.EndBatch(); // Draw foreground scene // Setup camera and blending pt = new TPoint2(cameraScale, cameraScale); pRender2D.SetCamera(ref cameraPosition, cameraAngle, ref pt); pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); // Owl col = new TColor4(150, 150, 150, 255); pRender2D.SetColorMix(ref col); // make sprite little darker ps = new TPoint2(owlX, 425f); pt = new TPoint2(48f, 128f); E_EFFECT2D_FLAGS EEF = (E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX | (owlGoLeft ? E_EFFECT2D_FLAGS.EF_FLIP_HORIZONTALLY : E_EFFECT2D_FLAGS.EF_DEFAULT)); pRender2D.DrawTextureSprite(pOwl, ref ps, ref pt, (uint)(counter / 3) % 15, 0f, EEF); // Draw tree ps = new TPoint2(); pt = new TPoint2(1399f, 900f); rect = new TRectF(0f, 0f, 1399f, 900f); pRender2D.DrawTextureCropped(pBg, ref ps, ref pt, ref rect, 0f, E_EFFECT2D_FLAGS.EF_BLEND); // Glowing disc under moving light pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); ps = new TPoint2(-100f, 0f); pt = new TPoint2(); pRender2D.SetVerticesOffsets(ref ps, ref ps, ref pt, ref pt); col = new TColor4(65, 59, 193, 255); pRender2D.SetColorMix(ref col); ps = new TPoint2(lights[0].x - 32f, lights[0].y + 64f); pt = new TPoint2(256f, 256f); pRender2D.DrawTexture(pLightRound, ref ps, ref pt, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_OFFSETS | E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX)); // Girl Shadow pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_NORMAL); ps = new TPoint2(-150f + (float)Math.Cos((float)counter / 100f) * 100f, -55f); pt = new TPoint2(-50f + (float)Math.Cos((float)counter / 100f) * 100f, -55f); TPoint2 pp = new TPoint2(15f, 5f); pRender2D.SetVerticesOffsets(ref ps, ref pt, ref pp, ref pp); col = new TColor4(0, 0, 0, 128); pRender2D.SetColorMix(ref col); ps = new TPoint2(550f, 725f); pt = new TPoint2(60f, 120f); pRender2D.DrawTextureSprite(pTexGirl, ref ps, ref pt, (uint)(counter / 5) % 16, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_OFFSETS | E_EFFECT2D_FLAGS.EF_BLEND | E_EFFECT2D_FLAGS.EF_COLOR_MIX)); // Girl Sprite pRender2D.DrawTextureSprite(pTexGirl, ref ps, ref pt, (uint)(counter / 5) % 16, 0f, E_EFFECT2D_FLAGS.EF_BLEND); // Lights pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_ADD); for (uint i = 0; i < 5; ++i) { ps = new TPoint2(lights[i].x, lights[i].y); pt = new TPoint2(64f, 128f); pRender2D.DrawTextureSprite(pLight, ref ps, ref pt, (uint)(counter / 2) % 14, 0f, E_EFFECT2D_FLAGS.EF_BLEND); } pRender2D.ResetCamera(); // We must calculate correct coordinates in game space because game resolution and screen resolution can be different. TPoint2 pos; pRender2D.AbsoluteToResolutionCorrect(ref stMousePos, out pos); ps = new TPoint2(pos.x - 37, pos.y - 37); pt = new TPoint2(75f, 75f); pRender2D.DrawTextureSprite(pVox, ref ps, ref pt, (uint)(counter / 2) % 16, 0f, E_EFFECT2D_FLAGS.EF_BLEND); uint tw, th; pFont.GetTextDimensions(HELP_TEXT, out tw, out th); col = TColor4.White; pFont.Draw2D((float)((GAME_VP_WIDTH - tw) / 2), (float)(GAME_VP_HEIGHT - th), HELP_TEXT, ref col); pRender2D.End2D(); }
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(); }
void DrawPrimitives(TRectF screen) { TColor4 c; TRectF rect; rect = new TRectF(5f, 5f, 170f, 170f); c = TColor4.ColorBlue(); pRender2D.DrawRectangle(ref rect, ref c, E_PRIMITIVE2D_FLAGS.PF_LINE); rect = new TRectF(10f, 10f, 160f, 160f); c = TColor4.ColorGray(); pRender2D.DrawRectangle(ref rect, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL); pRender2D.DrawTriangles(null, ref triangles[0], (uint)triangles.Length, E_PRIMITIVE2D_FLAGS.PF_FILL); for (int i = 0; i <= 12; i++) { TPoint2 p = new TPoint2(screen.x, screen.y) + new TPoint2(15f + 12 * i, 15f + 12 * i); c = TColor4.ColorTeal(); pRender2D.DrawPoint(ref p, ref c, (uint)(1 + i)); } for (int i = 0; i < 15; i++) { pRender2D.SetLineWidth((uint)(1 + i / 2)); TPoint2 p = new TPoint2(screen.width - i * 20, screen.height); TPoint2 p1 = new TPoint2(screen.width, screen.height - i * 20); c = TColor4.ColorOfficialOrange((byte)(255 - i * 17)); pRender2D.DrawLine(ref p, ref p1, ref c); } pRender2D.SetLineWidth(2); TColor4 c1 = TColor4.ColorAqua(), c2 = TColor4.ColorFuchsia(), c3 = new TColor4(), c4 = new TColor4(); pRender2D.SetVerticesColors(ref c1, ref c2, ref c3, ref c4); // override per vertex color for the line c = new TColor4(); TPoint2 p2 = new TPoint2(screen.width, 75f); TPoint2 p3 = new TPoint2(200f, screen.height); pRender2D.DrawLine(ref p2, ref p3, ref c, E_PRIMITIVE2D_FLAGS.PF_VERTICES_COLORS); pRender2D.SetLineWidth(1); c1 = TColor4.ColorGray(); c2 = TColor4.ColorMagenta(); c3 = TColor4.ColorOrange(); c4 = TColor4.ColorViolet(); pRender2D.SetVerticesColors(ref c1, ref c2, ref c3, ref c4); // override per vertex color for the rectangle rect = new TRectF(250f, 25f, 125f, 125f); pRender2D.DrawRectangle(ref rect, ref c, (E_PRIMITIVE2D_FLAGS.PF_LINE | E_PRIMITIVE2D_FLAGS.PF_VERTICES_COLORS)); c1 = TColor4.ColorBlack(0); c2 = TColor4.ColorGreen(); c3 = TColor4.ColorGreen(); c4 = TColor4.ColorBlack(0); pRender2D.SetVerticesColors(ref c1, ref c2, ref c3, ref c4); rect = new TRectF(260f, 35f, 105f, 105f); pRender2D.DrawRectangle(ref rect, ref c, (E_PRIMITIVE2D_FLAGS.PF_FILL | E_PRIMITIVE2D_FLAGS.PF_VERTICES_COLORS)); p2 = new TPoint2(125f, 50f); c = TColor4.ColorOrange(); pRender2D.DrawCircle(ref p2, 40, 32, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL); c = TColor4.ColorWhite(); for (int i = 0; i < 6; i++) { pRender2D.DrawCircle(ref p2, (uint)(10 + i * 5), (uint)(4 + i * 2), ref c, E_PRIMITIVE2D_FLAGS.PF_LINE); } p2 = new TPoint2(200f, 250f); p3 = new TPoint2(110f, 34f); c = TColor4.ColorViolet(); pRender2D.DrawEllipse(ref p2, ref p3, 64, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL); pRender2D.SetLineWidth(3); p3 = new TPoint2(100f, 30f); c = TColor4.ColorWhite(); pRender2D.DrawEllipse(ref p2, ref p3, 32, ref c, E_PRIMITIVE2D_FLAGS.PF_LINE); p3 = new TPoint2(80f, 24f); c = TColor4.ColorFuchsia(); pRender2D.DrawEllipse(ref p2, ref p3, 8, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL); p3 = new TPoint2(30f, 75f); c = TColor4.ColorOrange(100); pRender2D.DrawEllipse(ref p2, ref p3, 64, ref c, E_PRIMITIVE2D_FLAGS.PF_FILL); pRender2D.DrawPolygon(null, ref star_polygon[0], (uint)triangles.Length, E_PRIMITIVE2D_FLAGS.PF_FILL); }
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(); }