Exemple #1
0
        void Init(IntPtr pParam)
        {
            IEngineSubSystem pSubSys;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_CORE_RENDERER, out pSubSys);
            pCoreRenderer = (ICoreRenderer)pSubSys;

            E_CORE_RENDERER_TYPE type;

            pCoreRenderer.GetRendererType(out type);
            if (type != E_CORE_RENDERER_TYPE.CRT_OPENGL_LEGACY)
            {
                pEngineCore.WriteToLogEx("This example will work only with Legacy OpenGL renderer!", E_LOG_TYPE.LT_FATAL, "", 0);
            }

            IResourceManager pResMan;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out pSubSys);
            pResMan = (IResourceManager)pSubSys;

            IEngineBaseObject pBaseObj = null;

            pResMan.Load(ResPath + "meshes\\torus.dmd", out pBaseObj, (int)E_MESH_MODEL_LOAD_FLAGS.MMLF_FORCE_MODEL_TO_MESH);
            pMesh = (IMesh)pBaseObj;
            pResMan.Load(ResPath + "textures\\stone.tga", out pBaseObj, (int)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D);
            pTex = (ITexture)pBaseObj;
        }
Exemple #2
0
        void Init(IntPtr pParam)
        {
            IEngineSubSystem pSubSys;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_INPUT, out pSubSys);
            pInput = (IInput)pSubSys;

            IResourceManager pResMan;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out pSubSys);
            pResMan = (IResourceManager)pSubSys;

            IEngineBaseObject pBaseObj = null;

            pResMan.Load(ResPath + "sprites\\cartoon_cloudy_night_sky.jpg", out pBaseObj, 0);
            pTex = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\cartoon_owl.png", out pBaseObj, 0);
            pTexSprite = (ITexture)pBaseObj;
            pResMan.GetDefaultResource(E_ENGINE_OBJECT_TYPE.EOT_BITMAP_FONT, out pBaseObj);
            pFont = (IBitmapFont)pBaseObj;

            pTexSprite.SetFrameSize(48, 128);
        }
Exemple #3
0
        void Init(IntPtr pParam)
        {
            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;

            IRender p_render = null;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RENDER, out p_sub_sys);
            p_render = (IRender)p_sub_sys;
            p_render.GetRender2D(out pRender2D);

            IEngineBaseObject p_obj = null;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_INPUT, out p_sub_sys);
            pInput = (IInput)p_sub_sys;
            pInput.Configure(E_INPUT_CONFIGURATION_FLAGS.ICF_HIDE_CURSOR);

            p_res_man.GetDefaultResource(E_ENGINE_OBJECT_TYPE.EOT_BITMAP_FONT, out p_obj);
            pFont = (IBitmapFont)p_obj;


            // Background clear color setup.
            TColor4 tc = new TColor4(38, 38, 55, 255);

            p_render.SetClearColor(ref tc);

            // This example adapted only for 800X600 resolution, if even resolution will be higher it won't effect it.
            pRender2D.SetResolutionCorrection(GAME_VP_WIDTH, GAME_VP_HEIGHT, true);



            p_res_man.Load(RESOURCE_PATH + "sounds\\owl.wav", out p_obj, 0);
            pSndOwl = (ISoundSample)p_obj;

            p_res_man.Load(RESOURCE_PATH + "sounds\\forest_ambient.wav", out p_obj, 0);
            pForestAmbient = (ISoundSample)p_obj;
            pForestAmbient.PlayEx(out pChannelAmbientLoop, E_SOUND_SAMPLE_PARAMS.SSP_LOOPED);

            p_res_man.Load(RESOURCE_PATH + "sprites\\cartoon_forest_background.png", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D);
            pBg = (ITexture)p_obj;
            p_res_man.Load(RESOURCE_PATH + "sprites\\cartoon_cloudy_night_sky.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D);
            pSky = (ITexture)p_obj;
            p_res_man.Load(RESOURCE_PATH + "textures\\smoke.png", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D);
            pFog = (ITexture)p_obj;
            p_res_man.Load(RESOURCE_PATH + "textures\\light.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D);
            pLightRound = (ITexture)p_obj;

            p_res_man.Load(RESOURCE_PATH + "sprites\\vox.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D);
            pVox = (ITexture)p_obj;
            pVox.SetFrameSize(149, 149);

            p_res_man.Load(RESOURCE_PATH + "sprites\\cartoon_owl.png", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D);
            pOwl = (ITexture)p_obj;
            pOwl.SetFrameSize(48, 128);

            p_res_man.Load(RESOURCE_PATH + "sprites\\cartoon_anime_girl.png", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D);
            pTexGirl = (ITexture)p_obj;
            pTexGirl.SetFrameSize(55, 117);

            p_res_man.Load(RESOURCE_PATH + "sprites\\cartoon_mistery_light.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D);
            pLight = (ITexture)p_obj;
            pLight.SetFrameSize(64, 128);
        }
Exemple #4
0
        void Init(IntPtr pParam)
        {
            IEngineSubSystem pSubSys;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RENDER, out pSubSys);
            pRender = (IRender)pSubSys;
            TColor4 c = TColor4.ColorOfficialBlack();

            pRender.SetClearColor(ref c);
            pRender.GetRender2D(out pRender2D);

            IResourceManager pResMan;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out pSubSys);
            pResMan = (IResourceManager)pSubSys;

            IEngineBaseObject pBaseObj = null;

            // for fonts part
            pResMan.Load(ResPath + "fonts\\Times_New_Roman_12_rus.dft", out pBaseObj, 0);
            pFont = (IBitmapFont)pBaseObj;
            pResMan.Load(ResPath + "fonts\\Times_New_Roman_18_Bold.dft", out pBaseObj, 0);
            pFontBold = (IBitmapFont)pBaseObj;
            pResMan.Load(ResPath + "fonts\\TheHard_18.dft", out pBaseObj, 0);
            pFontHard = (IBitmapFont)pBaseObj;

            // for sprites part
            const uint unfiltered_2d_flag = (uint)(E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_NONE /* for cool old-school pixelized image */ |
                                                   E_TEXTURE_LOAD_FLAGS.TLF_COORDS_CLAMP);

            pResMan.Load(ResPath + "textures\\cartoon_grass.tga", out pBaseObj, unfiltered_2d_flag |
                         (uint)E_TEXTURE_LOAD_FLAGS.TLF_DECREASE_QUALITY_MEDIUM /* decrease texture size to make it more pixelized */);
            pTexGrass = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\cartoon_tank_body.png", out pBaseObj, unfiltered_2d_flag);
            pTexTankBody = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\cartoon_tank_turret.png", out pBaseObj, unfiltered_2d_flag);
            pTexTankTurret = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\cartoon_anime_girl.png", out pBaseObj, unfiltered_2d_flag);
            pTexGirl = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\cartoon_mistery_light.jpg", out pBaseObj, unfiltered_2d_flag |
                         (uint)E_TEXTURE_LOAD_FLAGS.TLF_DECREASE_QUALITY_HIGH);
            pTexLight = (ITexture)pBaseObj;

            pTexGirl.SetFrameSize(55, 117);
            pTexLight.SetFrameSize(64, 128);

            // for advanced part
            pResMan.Load(ResPath + "meshes\\planets\\asteroid.jpg", out pBaseObj, (uint)(E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR |
                                                                                         E_TEXTURE_LOAD_FLAGS.TLF_COORDS_MIRROR_REPEAT));
            pTexPlanet = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\light.jpg", out pBaseObj, 0);
            pTexLightRound = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\sphere_mask.png", out pBaseObj, 0);
            pTexMask = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\cartoon_cloudy_night_sky.jpg", out pBaseObj, 0);
            pTexBg = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\jellyfish.png", out pBaseObj, 0);
            pTexJellyFish = (ITexture)pBaseObj;

            for (int i = 0; i < 11; i++)
            {
                pResMan.Load(ResPath + "textures\\water\\water_" + i + ".tga", out pBaseObj, (uint)(E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR |
                                                                                                    E_TEXTURE_LOAD_FLAGS.TLF_COORDS_MIRROR_REPEAT /* let's repeat the texture this way to make it little weird */));
                pTexAnimWater[i] = (ITexture)pBaseObj;
            }

            pResMan.CreateTexture(out pTexPlanetRenderIn, null, 256, 256, E_TEXTURE_DATA_FORMAT.TDF_RGBA8,
                                  E_TEXTURE_CREATE_FLAGS.TCF_DEFAULT, E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR |
                                  E_TEXTURE_LOAD_FLAGS.TLF_COORDS_CLAMP);
        }
Exemple #5
0
        void Init(IntPtr pParam)
        {
            // get subsystems

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

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_INPUT, out p_sub_sys);
            pInput = (IInput)p_sub_sys;
            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RENDER, out p_sub_sys);
            pRender = (IRender)p_sub_sys;
            pRender.GetRender2D(out pRender2D);

            // create arrays
            IEngineBaseObject pObj = null;

            pTextures = new ITexture[TexCount];
            pShadows  = new ITexture[ShadowCount];
            pMeshes   = new IMesh[MeshCount];

            // loading data
            pResMan.Load(RESOURCE_PATH + "sounds\\helicopter.wav", out pObj, 0);
            pSound = (ISoundSample)pObj;
            pSound.PlayEx(out pSoundChannel, E_SOUND_SAMPLE_PARAMS.SSP_LOOPED);

            for (int i = 0; i < TexCount; i++)
            {
                uint flags = TexNames[i].Contains("grass") ? (uint)(E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR | E_TEXTURE_LOAD_FLAGS.TLF_COORDS_REPEAT) : (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D;
                pResMan.Load(RESOURCE_PATH + TexNames[i], out pObj, flags);
                pTextures[i] = (ITexture)pObj;
            }

            pTextures[6].SetFrameSize(256, 256); // zombie sprite splitting

            for (int i = 0; i < MeshCount; i++)
            {
                pResMan.Load(RESOURCE_PATH + MeshNames[i], out pObj, (uint)E_MESH_MODEL_LOAD_FLAGS.MMLF_FORCE_MODEL_TO_MESH);
                pMeshes[i] = (IMesh)pObj;
            }

            // render shadows
            for (int i = 0; i < MeshCount; i++)
            {
                RenderMeshToTexture(out pShadows[i], pMeshes[i], pTextures[i]);
            }

            // render rotor shadow
            pResMan.CreateTexture(out pShadows[5], null, 256, 256, E_TEXTURE_DATA_FORMAT.TDF_RGBA8, E_TEXTURE_CREATION_FLAGS.TCF_DEFAULT, E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR);
            pRender.SetRenderTarget(pShadows[5]);
            TPoint2 coords = new TPoint2(128f, 128f);
            TColor4 col    = TColor4.ColorWhite();

            pRender2D.DrawCircle(ref coords, 100, 64, ref col, E_PRIMITIVE2D_FLAGS.PF_FILL);
            pRender.SetRenderTarget(null);


            // gather, fill and init 3d-objects data
            MyMeshes = new MyMesh[8]
            {
                new MyMesh(pMeshes[0], pTextures[0], pShadows[0], new TPoint2(900f, 500f), new TPoint3(400f, 400f, 500f), 225),
                new MyMesh(pMeshes[0], pTextures[0], pShadows[0], new TPoint2(-250f, 300f), new TPoint3(400f, 400f, 500f), 225),
                new MyMesh(pMeshes[0], pTextures[0], pShadows[0], new TPoint2(800f, 200f), new TPoint3(400f, 400f, 400f), 225),
                new MyMesh(pMeshes[1], pTextures[1], pShadows[1], new TPoint2(0f, 450f), new TPoint3(300f, 300f, 400f), 175),
                new MyMesh(pMeshes[1], pTextures[1], pShadows[1], new TPoint2(50f, 750f), new TPoint3(300f, 300f, 300f), 175),
                new MyMesh(pMeshes[2], pTextures[2], pShadows[2], new TPoint2(500f, 150f), new TPoint3(400f, 400f, 500f), 225),
                new MyMesh(pMeshes[3], pTextures[3], pShadows[3], new TPoint2(180f, 150f), new TPoint3(400f, 400f, 600f), 200),
                new MyMesh(pMeshes[3], pTextures[3], pShadows[3], new TPoint2(600f, 550f), new TPoint3(400f, 400f, 600f), 200, 90)
            };

            copter = new Copter(new MyMesh(pMeshes[4], pTextures[4], pShadows[4], new TPoint2(), new TPoint3(600, 600, 600), 200, 0, true), pTextures[5], pShadows[5]);
            zombie = new Zombie(pTextures[6]);
        }
Exemple #6
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);
        }