Beispiel #1
0
        public static void SetDesignResolutionSize(float width, float height, CCResolutionPolicy resolutionPolicy)
        {
            Debug.Assert(resolutionPolicy != CCResolutionPolicy.UnKnown, "should set resolutionPolicy");

            if (width == 0.0f || height == 0.0f)
            {
                return;
            }

            m_obDesignResolutionSize.Width  = width;
            m_obDesignResolutionSize.Height = height;

            m_fScaleX = m_obScreenSize.Width / m_obDesignResolutionSize.Width;
            m_fScaleY = m_obScreenSize.Height / m_obDesignResolutionSize.Height;

            if (resolutionPolicy == CCResolutionPolicy.NoBorder)
            {
                m_fScaleX = m_fScaleY = Math.Max(m_fScaleX, m_fScaleY);
            }

            if (resolutionPolicy == CCResolutionPolicy.ShowAll)
            {
                m_fScaleX = m_fScaleY = Math.Min(m_fScaleX, m_fScaleY);
            }

            // calculate the rect of viewport
            float viewPortW = m_obDesignResolutionSize.Width * m_fScaleX;
            float viewPortH = m_obDesignResolutionSize.Height * m_fScaleY;

            m_obViewPortRect = new CCRect((m_obScreenSize.Width - viewPortW) / 2, (m_obScreenSize.Height - viewPortH) / 2, viewPortW, viewPortH);

            m_eResolutionPolicy = resolutionPolicy;

            // reset director's member variables to fit visible rect
            CCDirector.SharedDirector.m_obWinSizeInPoints = Size;
            CCDirector.SharedDirector.m_obWinSizeInPixels = new CCSize(m_obDesignResolutionSize.Width * CCMacros.CCContentScaleFactor(),
                                                                       m_obDesignResolutionSize.Height * CCMacros.CCContentScaleFactor());
            CCDirector.SharedDirector.CreateStatsLabel();
            CCDirector.SharedDirector.SetGlDefaultValues();
        }
Beispiel #2
0
        public static void Init(GraphicsDevice graphicsDevice)
        {
            CCDrawManager.graphicsDevice = graphicsDevice;

            spriteBatch = new SpriteBatch(graphicsDevice);

            m_defaultEffect = new BasicEffect(graphicsDevice);

            PrimitiveEffect = new BasicEffect(graphicsDevice)
            {
                TextureEnabled     = false,
                VertexColorEnabled = true
            };

            m_DepthEnableStencilState = new DepthStencilState
            {
                DepthBufferEnable      = true,
                DepthBufferWriteEnable = true,
                TwoSidedStencilMode    = true
            };

            m_DepthDisableStencilState = new DepthStencilState
            {
                DepthBufferEnable = false
            };
#if !WINDOWS_PHONE && !XBOX && !WINDOWS && !NETFX_CORE && !PSM
            List <string> extensions = CCUtils.GetGLExtensions();
            foreach (string s in extensions)
            {
                switch (s)
                {
                case "GL_OES_depth24":
                    m_PlatformDepthFormat = DepthFormat.Depth24;
                    break;

                case "GL_IMG_texture_npot":
                    m_AllowNonPower2Textures = true;
                    break;

                case "GL_NV_depth_nonlinear":     // nVidia Depth 16 non-linear
                    m_PlatformDepthFormat = DepthFormat.Depth16;
                    break;

                case "GL_NV_texture_npot_2D_mipmap":     // nVidia - nPot textures and mipmaps
                    m_AllowNonPower2Textures = true;
                    break;
                }
            }
#endif
            PresentationParameters pp = graphicsDevice.PresentationParameters;
            //pp.RenderTargetUsage = RenderTargetUsage.PreserveContents;
            //_renderTarget = new RenderTarget2D(graphicsDevice, pp.BackBufferWidth, (int)pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.PreserveContents);

            m_fScaleY           = 1.0f;
            m_fScaleX           = 1.0f;
            m_eResolutionPolicy = CCResolutionPolicy.UnKnown;

            m_obViewPortRect = new CCRect(0, 0, pp.BackBufferWidth, pp.BackBufferHeight);
            m_obScreenSize   = m_obDesignResolutionSize = m_obViewPortRect.Size;

            CCDrawingPrimitives.Init(graphicsDevice);
        }