Exemple #1
0
        void Render(IntPtr pParam)
        {
            pRender2D.Begin2D();

            TPoint2 pc;

            pc = new TPoint2((float)(350 + Math.Cos(counter / 200.0) * 200), (float)(350 + Math.Sin(counter / 200.0) * 80));
            TPoint2 ps = new TPoint2(1, 1);

            // make floating camera
            pRender2D.SetCamera(ref pc,                               //camera center
                                (float)Math.Sin(counter / 50.0) * 15, //camera angle
                                ref ps                                //camera scale
                                );
            pRender2D.ProjectScreenToCamera(ref stMouseOnScreen, out stMouseInCamera);

            pc = new TPoint2(-750f, -750f);
            ps = new TPoint2(2000f, 2000f);
            pRender2D.DrawTexture(pTextures[7], ref pc, ref ps, 0f, E_EFFECT2D_FLAGS.EF_TILE_TEXTURE);

            //draw stone layer with per vertex blending
            TColor4 white = TColor4.ColorWhite();
            TColor4 col = TColor4.ColorWhite(0);
            TPoint2 p1 = new TPoint2(0f, 225f);
            uint    x, y;

            pTextures[8].GetDimensions(out x, out y);
            TPoint2 pdim = new TPoint2((float)x, (float)y);

            pRender2D.SetVerticesColors(ref col, ref white, ref white, ref col);
            pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND));

            pRender2D.SetVerticesColors(ref white, ref col, ref col, ref white);
            p1 = new TPoint2(0f + 256f, 225f);
            pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND));

            pRender2D.SetVerticesColors(ref white, ref col, ref col, ref col);
            p1 = new TPoint2(0f + 256f, 225f + 256f);
            pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND));

            pRender2D.SetVerticesColors(ref col, ref white, ref col, ref col);
            p1 = new TPoint2(0f, 225f + 256f);
            pRender2D.DrawTexture(pTextures[8], ref p1, ref pdim, 0f, (E_EFFECT2D_FLAGS.EF_VERTICES_COLORS | E_EFFECT2D_FLAGS.EF_BLEND));

            //// set color mix to semi-transparent black for object shadows
            col = TColor4.ColorBlack(128);
            pRender2D.SetColorMix(ref col);

            for (int i = 0; i < MyMeshes.Length; i++) // all meshes with shadows except copter
            {
                MyMeshes[i].Draw();
            }

            zombie.Render();

            copter.Render((float)counter);

            pRender2D.End2D();
        }
Exemple #2
0
        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);
        }
Exemple #3
0
            public void Render(float counter)
            {
                CopterMesh.Draw();
                pRender2D.DrawTexture(RotorTex, ref vint_pos, ref vint_dim, counter * 25f);
                // make blinky rotor shadow
                TColor4 col = TColor4.ColorBlack((byte)(counter % 3 == 2 ? 64 : 16));

                pRender2D.SetColorMix(ref col);
                TPoint2 p1 = vint_pos + new TPoint2(100f, 100f);

                pRender2D.DrawTexture(RotorShadow, ref p1, ref vint_dim, 0f, (E_EFFECT2D_FLAGS.EF_COLOR_MIX | E_EFFECT2D_FLAGS.EF_BLEND));
            }
Exemple #4
0
        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);
        }
Exemple #5
0
        void Init(IntPtr pParam)
        {
            TMatrix4x4 mat = TMatrix4x4.MatrixIdentity;

            transform = new TTransformStack(ref mat);
            rand      = new Random();

            IEngineSubSystem p_sub_sys = null;

            IResourceManager p_res_man = null;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out p_sub_sys);
            p_res_man = (IResourceManager)p_sub_sys;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RENDER, out p_sub_sys);
            p_render = (IRender)p_sub_sys;
            p_render.GetRender3D(out pRender3D);
            IEngineBaseObject p_obj = null;

            p_res_man.Load(RESOURCE_PATH + "textures\\floor.dds", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            pTexFloor = (ITexture)p_obj;
            p_res_man.Load(RESOURCE_PATH + "sprites\\light.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D);
            pTexLight = (ITexture)p_obj;

            // some global lighting

            pRender3D.ToggleLighting(true);
            TColor4 col = TColor4.ColorBlack();

            pRender3D.SetGlobalAmbientLighting(ref col); // turn off ambient lighting

            // setup lights

            // use single directional light to simulate ambient lighting
            p_res_man.CreateLight(out pLightDirect);
            pLightDirect.SetType(E_LIGHT_TYPE.LT_DIRECTIONAL);
            col = TColor4.ColorGray();
            pLightDirect.SetColor(ref col); // dim light
            TPoint3 p3 = new TPoint3(-0.5f, 0.5f, 0.75f);

            pLightDirect.SetDirection(ref p3);
            pLightDirect.SetEnabled(true);

            // Position is ignored for direction lights but is used by engine for debug drawing.
            // Use "rnd3d_draw_lights 1" console command to debug lights.
            p3 = new TPoint3(0f, 7.5f, 0f);
            pLightDirect.SetPosition(ref p3);

            // create light for the table-lamp
            p_res_man.CreateLight(out pLightSpot);
            pLightSpot.SetType(E_LIGHT_TYPE.LT_SPOT);
            col = TColor4.ColorYellow();
            pLightSpot.SetColor(ref col);
            pLightSpot.SetSpotAngle(100f);
            p3 = new TPoint3(0.15f, 0f, -1f);
            pLightSpot.SetDirection(ref p3);
            pLightSpot.SetEnabled(true);

            // create and setup materials and load models

            ITexture  p_tex;
            IMaterial p_mat;

            // desk
            p_res_man.CreateMaterial(out p_mat);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\desk\\desk_diff.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            p_tex = (ITexture)p_obj;
            p_mat.SetDiffuseTexture(p_tex);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\desk\\desk.dmd", out p_obj, 0);
            pMdlDesk = (IModel)p_obj;
            pMdlDesk.SetModelMaterial(p_mat);

            // table-lamp
            p_res_man.CreateMaterial(out p_mat);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\table_lamp\\lamp_diff.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            p_tex = (ITexture)p_obj;
            p_mat.SetDiffuseTexture(p_tex);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\table_lamp\\lamp.dmd", out p_obj, 0);
            pMdlLamp = (IModel)p_obj;
            pMdlLamp.SetModelMaterial(p_mat);

            // chair
            p_res_man.CreateMaterial(out p_mat);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\chair\\chair_diff.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            p_tex = (ITexture)p_obj;
            p_mat.SetDiffuseTexture(p_tex);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\chair\\chair.dmd", out p_obj, 0);
            pMdlChair = (IModel)p_obj;
            pMdlChair.SetModelMaterial(p_mat);

            // music box
            p_res_man.CreateMaterial(out p_mat);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\music_box\\mbox_d.dds", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            p_tex = (ITexture)p_obj;
            p_mat.SetDiffuseTexture(p_tex);
            p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\music_box\\music_box.dmd", out p_obj, 0);
            pMdlMusicBox = (IModel)p_obj;
            pMdlMusicBox.SetModelMaterial(p_mat);

            // church
            p_res_man.Load(RESOURCE_PATH + "meshes\\church\\church.dmd", out p_obj, 0);
            pModelChurch = (IModel)p_obj;
            pModelChurch.SetModelMaterial(p_mat);

            p_res_man.CreateMaterial(out p_mat);
            col = TColor4.ColorSilver();
            p_mat.SetDiffuseColor(ref col);
            col = TColor4.ColorWhite();
            p_mat.SetSpecularColor(ref col);
            p_mat.SetShininess(25f);
            pModelChurch.SetMeshMaterial(0, p_mat);

            p_res_man.CreateMaterial(out p_mat);
            p_res_man.Load(RESOURCE_PATH + "meshes\\church\\church_roof.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            p_tex = (ITexture)p_obj;
            p_mat.SetDiffuseTexture(p_tex);
            pModelChurch.SetMeshMaterial(1, p_mat);

            p_res_man.CreateMaterial(out p_mat);
            p_res_man.Load(RESOURCE_PATH + "meshes\\church\\church_main.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            p_tex = (ITexture)p_obj;
            p_mat.SetDiffuseTexture(p_tex);
            pModelChurch.SetMeshMaterial(2, p_mat);

            // snow globe
            p_res_man.Load(RESOURCE_PATH + "meshes\\snow_globe.dmd", out p_obj, 0);
            pSnowGlobe = (IModel)p_obj;
            p_res_man.CreateMaterial(out p_mat);
            col = TColor4.ColorWhite();
            p_mat.SetDiffuseColor(ref col);
            pSnowGlobe.SetMeshMaterial(0, p_mat);

            p_res_man.CreateMaterial(out p_mat);
            col = TColor4.ColorBrown();
            p_mat.SetDiffuseColor(ref col);
            col = TColor4.ColorWhite();
            p_mat.SetSpecularColor(ref col);
            p_mat.SetShininess(25f);
            pSnowGlobe.SetMeshMaterial(2, p_mat);

            p_res_man.CreateMaterial(out p_mat);
            col = TColor4.ColorWhite(100);
            p_mat.SetDiffuseColor(ref col);
            col = TColor4.ColorWhite();
            p_mat.SetSpecularColor(ref col);
            p_mat.SetShininess(50f);
            p_mat.SetBlending(true, E_BLENDING_EFFECT.BE_NORMAL);

            // When material with blending is set model will sort mesh order for meshes with blending to be the last.
            pSnowGlobe.SetMeshMaterial(1, p_mat);

            // We will use black fog to simulate darkness.
            col = TColor4.ColorBlack();
            pRender3D.SetFogColor(ref col);
            pRender3D.SetLinearFogBounds(12.5f, 20f);
            pRender3D.ToggleFog(true);
        }