Example #1
0
        static unsafe void BuildCharMap()
        {
            const int Len   = 17;
            const int Width = Len * 7;

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Width, Width);

            BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, Width, Width), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            ColorValue *color = (ColorValue *)data.Scan0;

            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    int idx = i * Len * Width + j;
                    color[idx] = ColorValue.Black;
                }
            }
            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Len; j++)
                {
                    int idx = i * Width + j * Len;
                    color[idx] = ColorValue.Black;
                }
            }

            bmp.UnlockBits(data);

            bmp.Save(@"E:\Desktop\cmap17.png", ImageFormat.Png);
        }
Example #2
0
        /// <summary>
        /// This callback function will be called at the end of every frame to perform all the
        /// rendering calls for the scene, and it will also be called if the window needs to be
        /// repainted. After this function has returned, the sample framework will call
        /// Device.Present to display the contents of the next buffer in the swap chain
        /// </summary>
        public unsafe void OnFrameRender(Device device, double appTime, float elapsedTime)
        {
            bool beginSceneCalled = false;

            // Clear the render target and the zbuffer
            device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, unchecked ((int)0x8C003F3F), 1.0f, 0);
            try
            {
                device.BeginScene();
                beginSceneCalled = true;

                Vector3 *   pLightDir     = stackalloc Vector3[MaxNumberLights];
                ColorValue *pLightDiffuse = stackalloc ColorValue[MaxNumberLights];

                // Render the arrows so the user can visually see the light direction
                for (int i = 0; i < numberActiveLights; i++)
                {
                    ColorValue arrowColor = (i == activeLight) ? YellowColor : WhiteColor;
                    lightControl[i].OnRender(arrowColor, camera.ViewMatrix, camera.ProjectionMatrix, camera.EyeLocation);
                    // Get the light direction and color
                    pLightDir[i]     = lightControl[i].LightDirection;
                    pLightDiffuse[i] = ColorOperator.Scale(WhiteColor, lightScale);
                }

                Matrix worldMatrix = worldFix * camera.WorldMatrix;
                // Update the effects now
                effect.SetValue("g_LightDir", pLightDir, sizeof(Vector3) * MaxNumberLights);
                effect.SetValue("g_LightDiffuse", pLightDiffuse, sizeof(ColorValue) * MaxNumberLights);

                // Update the effect's variables.  Instead of using strings, it would
                // be more efficient to cache a handle to the parameter by calling
                // Effect.GetParameter
                effect.SetValue("worldViewProjection", worldMatrix * camera.ViewMatrix * camera.ProjectionMatrix);
                effect.SetValue("worldMatrix", worldMatrix);
                effect.SetValue("appTime", (float)appTime);

                effect.SetValue("g_MaterialDiffuseColor", WhiteColor);
                effect.SetValue("g_nNumLights", numberActiveLights);

                // Render the scene with this technique as defined in the .fx file
                switch (numberActiveLights)
                {
                case 1: effect.Technique = "RenderSceneWithTexture1Light"; break;

                case 2: effect.Technique = "RenderSceneWithTexture2Light"; break;

                case 3: effect.Technique = "RenderSceneWithTexture3Light"; break;
                }

                // Apply the technique contained in the effect
                int passes = effect.Begin(0);
                for (int pass = 0; pass < passes; pass++)
                {
                    effect.BeginPass(pass);

                    // The effect interface queues up the changes and performs them
                    // with the CommitChanges call. You do not need to call CommitChanges if
                    // you are not setting any parameters between the BeginPass and EndPass.
                    // effect.CommitChanges() );

                    // Render the mesh with the applied technique
                    mesh.DrawSubset(0);
                    effect.EndPass();
                }
                effect.End();

                // Show frame rate and help, etc
                RenderText(appTime);

                // Show UI
                hud.OnRender(elapsedTime);
                sampleUi.OnRender(elapsedTime);
            }
            finally
            {
                if (beginSceneCalled)
                {
                    device.EndScene();
                }
            }
        }