Exemplo n.º 1
0
        /// <summary>
        /// Initializes DirectDraw and all the surfaces to be used.
        /// </summary>
        private void InitDirectDraw()
        {
            SurfaceDescription description  = new SurfaceDescription();                         // Describes a surface.
            Random             randomNumber = new Random();                                     // Random number for position and velocity.

            displayDevice = new Device();                                                       // Create a new DirectDrawDevice.
            displayDevice.SetCooperativeLevel(this, CooperativeLevelFlags.FullscreenExclusive); // Set the cooperative level.
            displayDevice.SetDisplayMode(screenWidth, screenHeight, 16, 0, false);              // Set the display mode width and height, and 8 bit color depth.

            description.SurfaceCaps.Flip = description.SurfaceCaps.Complex = description.SurfaceCaps.PrimarySurface = true;
            description.BackBufferCount  = 1;                // Create 1 backbuffer.
            front = new Surface(description, displayDevice); // Create the surface using the description above.

            SurfaceCaps caps = new SurfaceCaps();

            caps.BackBuffer = true;                                          // Caps of the surface.
            back            = front.GetAttachedSurface(caps);                // Get the attached surface that matches the caps, which will be the backbuffer.

            clip          = new Clipper(displayDevice);                      // Create a clipper object.
            clip.Window   = this;                                            // Set the clippers window handle to the window handle of the main window.
            front.Clipper = clip;                                            // Tell the front surface to use the clipper object.

            description.Clear();                                             // Clear out the SurfaceDescription structure.
            surfaceLogo = new Surface(nameFile, description, displayDevice); // Create the sprites bitmap surface.

            description.Clear();

            description.Width  = 400; // Set the width and height of the surface.
            description.Height = 20;
            description.SurfaceCaps.OffScreenPlain = true;

            text = new Surface(description, displayDevice); // Create the surface using the above description.
            text.ColorFill(Color.Black);
            text.ForeColor = Color.White;
            text.DrawText(0, 0, textHelp, true);

            ColorKey ck = new ColorKey();                          // Create a new colorkey.

            surfaceLogo.SetColorKey(ColorKeyFlags.SourceDraw, ck); // Set the colorkey to the bitmap surface. 0 is used for the colorkey, which is what the ColorKey struct is initialized to.

            for (int i = 0; i < numSprites; i++)
            {
                // Set the sprites's position and velocity
                sprites[i].posX = (randomNumber.Next() % screenWidth);
                sprites[i].posY = (randomNumber.Next() % screenHeight);

                sprites[i].velX = 500.0f * randomNumber.Next() / Int32.MaxValue - 250.0f;
                sprites[i].velY = 500.0f * randomNumber.Next() / Int32.MaxValue - 250.0f;
            }
        }
Exemplo n.º 2
0
        private void CreateSurfaces()
        {
            SurfaceDescription desc = new SurfaceDescription();
            SurfaceCaps        caps = new SurfaceCaps();

            localClipper        = new Clipper(localDevice);
            localClipper.Window = owner;

            desc.SurfaceCaps.PrimarySurface = true;
            if (null != surfacePrimary)
            {
                surfacePrimary.Dispose();
            }
            surfacePrimary         = new Surface(desc, localDevice);
            surfacePrimary.Clipper = localClipper;

            desc.Clear();
            desc.SurfaceCaps.OffScreenPlain = true;
            desc.Width  = surfacePrimary.SurfaceDescription.Width;
            desc.Height = surfacePrimary.SurfaceDescription.Height;

            if (null != surfaceSecondary)
            {
                surfaceSecondary.Dispose();
            }
            surfaceSecondary           = new Surface(desc, localDevice);
            surfaceSecondary.FillStyle = 0;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes DirectDraw and all the surfaces to be used.
        /// </summary>
        private void InitDirectDraw()
        {
            SurfaceDescription description = new SurfaceDescription();                                                      // Describes a surface.

            draw = new Device();                                                                                            // Create a new DirectDrawDevice.
            draw.SetCooperativeLevel(this, CooperativeLevelFlags.FullscreenExclusive);                                      // Set the cooperative level.
            draw.SetDisplayMode(widthScreen, heightScreen, 16, 0, false);                                                   // Set the display mode width and height, and 16 bit color depth.

            description.SurfaceCaps.PrimarySurface = description.SurfaceCaps.Flip = description.SurfaceCaps.Complex = true; // Capabilities of the surface.
            description.BackBufferCount            = 1;                                                                     // Create 1 backbuffer.

            front = new Surface(description, draw);                                                                         // Create the surface using the description above.

            SurfaceCaps caps = new SurfaceCaps();

            caps.BackBuffer = true;                           // Caps of the surface.
            back            = front.GetAttachedSurface(caps); // Get the attached surface that matches the caps, which will be the backbuffer.
            back.ForeColor  = Color.White;

            description.Clear();                                         // Clear out the SurfaceDescription structure.
            surfaceAnimation = new Surface(nameFile, description, draw); // Create the sprite bitmap surface.

            ColorKey ck = new ColorKey();                                // Create a new colorkey.

            surfaceAnimation.SetColorKey(ColorKeyFlags.SourceDraw, ck);  // Set the colorkey to the bitmap surface. 0 is used for the colorkey, which is what the ColorKey struct is initialized to.

            for (int i = 0; i < numSprites; i++)
            {
                // Set the sprite's position, velocity, frame, rotation direction, and rotation speed.
                sprite[i].posX          = (randomNumber.Next(0, maxRand) % widthScreen);
                sprite[i].posY          = (randomNumber.Next(0, maxRand) % heightScreen);
                sprite[i].velX          = ((500.0f * randomNumber.Next(0, maxRand)) / (float)maxRand) - 250.0f;
                sprite[i].velY          = ((500.0f * randomNumber.Next(0, maxRand)) / (float)maxRand) - 250.0f;
                sprite[i].frame         = randomNumber.Next(0, maxRand) % numFrames;
                sprite[i].tickRotation  = 0;
                sprite[i].speedRotation = (randomNumber.Next(0, maxRand) % 50 + 25) / 1000.0f;
                sprite[i].isClockwise   = (0 == randomNumber.Next(0, maxRand) % 2) ? true : false;
            }

            // Precompute the source rects for frame.  The source rects
            // are used during the blt of the dds to the backbuffer.
            for (int i = 0; i < numFrames; i++)
            {
                System.Drawing.Point p = new System.Drawing.Point((i % 5) * diameterSprite, (i / 5) * diameterSprite);
                frame[i] = new System.Drawing.Rectangle(p, new Size(diameterSprite, diameterSprite));
            }

            // Init an array of random values.  This array is used to create the
            // 'flocking' effect seen in the sample.
            randomIndex = 0;
            for (int randomNext = 0; randomNext < numRandom; randomNext++)
            {
                randomTable[randomNext] = randomNumber.Next(0, maxRand);
            }
        }
Exemplo n.º 4
0
		/// <summary>
		/// This method creates the primary and secondary surfaces
		/// </summary>
		public void CreateSurfaces()
		{
			// Every surface needs a description
			// This is where you set the parameters for the surface
			SurfaceDescription desc = new SurfaceDescription();
  
			// This is the clipper for the primary surface
			// -> connect it to the target control
			Clipper graphicsClipper = new Clipper(graphicsDevice);
			graphicsClipper.Window = target;

			// First we want to create a primary surface
			desc.SurfaceCaps.PrimarySurface = true;

#if !windowed
			// In release mode, we enable flipping, set the complex
			// flag and tell the surface that we will use one back
			// buffer
			desc.SurfaceCaps.Flip = true;
			desc.SurfaceCaps.Complex = true;
			desc.BackBufferCount = 1;
#endif

			// Create the surface
			surfacePrimary = new Surface(desc, graphicsDevice);
			srcRect = new Rectangle(0,0,target.Width,target.Height);

			// Attach clipper to the surface
			surfacePrimary.Clipper = graphicsClipper;

			// To build the secondary surface, we need 
			// a new description -> clear all values
			desc.Clear();

#if windowed
			// In debug mode, we simply copy the primary surfaces
			// dimensions and create a offscreenplain secondary
			// surface
			desc.Width = surfacePrimary.SurfaceDescription.Width;
			desc.Height = surfacePrimary.SurfaceDescription.Height;
			desc.SurfaceCaps.OffScreenPlain = true;
			surfaceSecondary = new Surface(desc, this.graphicsDevice);
#else
			// In release mode, we set the backbuffer flag to true
			// and retrieve a backbuffer surface from the primary
			// surface
			desc.SurfaceCaps.BackBuffer = true;
			surfaceSecondary = surfacePrimary.GetAttachedSurface(desc.SurfaceCaps);
#endif

			//surfaceSecondary.Clipper=graphicsClipper;
		} 
Exemplo n.º 5
0
        /// <summary>
        /// This function is where the surfaces and
        /// clipper object are created.
        /// </summary>
        private void CreateSurfaces()
        {
            SurfaceDescription description = new SurfaceDescription();                             // Create a new SurfaceDescription struct.

            description.SurfaceCaps.PrimarySurface = true;                                         // The caps for this surface is simply primary.

            primary         = new Surface(description, draw);                                      // Create the primary surface.
            clip            = new Clipper(draw);                                                   // Create a new clipper.
            clip.Window     = this;                                                                // The clipper will use the main window handle.
            primary.Clipper = clip;                                                                // Assign this clipper to the primary surface.

            description.Clear();                                                                   // Clear the SurfaceDescription struct.
            offscreen = new Surface(DXUtil.SdkMediaPath + "\\earthenvmap.bmp", description, draw); // Create the surface using the specified file.
        }
Exemplo n.º 6
0
        /// <summary>
        /// This function is where the surfaces and
        /// clipper object are created.
        /// </summary>
        private void CreateSurfaces()
        {
            SurfaceDescription description = new SurfaceDescription(); // Create a new SurfaceDescription struct.

            description.SurfaceCaps.PrimarySurface = true;

            // If any object currently exist, destroy them.
            if (null != offscreen)
            {
                offscreen.Dispose();
            }
            if (null != primary)
            {
                primary.Dispose();
            }

            primary         = new Surface(description, draw); // Create the primary surface.
            clip.Window     = this;                           // The clipper will use the main window handle.
            primary.Clipper = clip;                           // Assign this clipper to the primary surface.
            description.Clear();

            offscreen = new Surface(DXUtil.SdkMediaPath + "\\earthenvmap.bmp", description, draw); // Create the surface using the specified file.
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes DirectDraw and all the surfaces to be used.
        /// </summary>
        private void InitializeDirectDraw()
        {
            SurfaceDescription description  = new SurfaceDescription(); // Describes a surface.
            Random             randomNumber = new Random();             // Random number for position and velocity.
            ColorKeyFlags      flags        = new ColorKeyFlags();

            displayDevice = new Device();                                                       // Create a new DirectDrawDevice.
            displayDevice.SetCooperativeLevel(this, CooperativeLevelFlags.FullscreenExclusive); // Set the cooperative level.

            try
            {
                displayDevice.SetDisplayMode(screenWidth, screenHeight, 8, 0, false); // Set the display mode width and height, and 8 bit color depth.
            }
            catch (UnsupportedException)
            {
                MessageBox.Show("Device doesn't support required mode. Sample will now exit.", "UnsupportedException caught");
                Close();
                return;
            }

            description.SurfaceCaps.PrimarySurface = description.SurfaceCaps.Flip = description.SurfaceCaps.Complex = true;
            description.BackBufferCount            = 1;      // Create 1 backbuffer.

            front = new Surface(description, displayDevice); // Create the surface using the description above.

            SurfaceCaps caps = new SurfaceCaps();

            caps.BackBuffer = true;                                                // Caps of the surface.
            back            = front.GetAttachedSurface(caps);                      // Get the attached surface that matches the caps, which will be the backbuffer.

            pal           = new Palette(displayDevice, bitmapFileName);            // Create a new palette, using the bitmap file.
            pe            = pal.GetEntries(0, 256);                                // Store the palette entries.
            front.Palette = pal;                                                   // The front surface will use this palette.

            description.Clear();                                                   // Clear the data out from the SurfaceDescription class.
            surfaceLogo = new Surface(bitmapFileName, description, displayDevice); // Create the sprite bitmap surface.

            ColorKey key = new ColorKey();                                         // Create a new colorkey.

            key.ColorSpaceHighValue = key.ColorSpaceLowValue = 0;
            flags = ColorKeyFlags.SourceDraw;
            surfaceLogo.SetColorKey(flags, key); // Set the colorkey to the bitmap surface. 144 is the index used for the colorkey, which is black in this palette.

            description.Clear();
            description.SurfaceCaps.OffScreenPlain = true;
            description.Width  = 200; // Set the width and height of the surface.
            description.Height = 20;

            text           = new Surface(description, displayDevice); // Create the surface using the above description.
            text.ForeColor = Color.FromArgb(indexWhite);              // Because this is a palettized environment, the app needs to use index based colors, which
                                                                      // do not correspond to pre-defined color values. For this reason, the indexWhite variable exists
                                                                      // and contains the index where the color white is stored in the bitmap's palette. The app makes use
                                                                      // of the static FromArgb() method to convert the index to a Color value.
            text.ColorFill(indexBlack);
            text.DrawText(0, 0, textHelp, false);

            for (int i = 0; i < numSprites; i++)
            {
                // Set the sprite's position and velocity
                sprite[i].posX = (randomNumber.Next() % screenWidth);
                sprite[i].posY = (randomNumber.Next() % screenHeight);

                sprite[i].velX = 500.0f * randomNumber.Next() / Int32.MaxValue - 250.0f;
                sprite[i].velY = 500.0f * randomNumber.Next() / Int32.MaxValue - 250.0f;
            }
        }
        private void CreateSurfaces()
        {
            SurfaceDescription desc = new SurfaceDescription();
            SurfaceCaps caps = new SurfaceCaps();

            localClipper = new Clipper(localDevice);
            localClipper.Window = owner;

            desc.SurfaceCaps.PrimarySurface = true;
            if (null != surfacePrimary)
                surfacePrimary.Dispose();
            surfacePrimary = new Surface(desc, localDevice);
            surfacePrimary.Clipper = localClipper;

            desc.Clear();
            desc.SurfaceCaps.OffScreenPlain = true;
            desc.Width = surfacePrimary.SurfaceDescription.Width;
            desc.Height = surfacePrimary.SurfaceDescription.Height;

            if (null != surfaceSecondary)
                surfaceSecondary.Dispose();
            surfaceSecondary = new Surface(desc, localDevice);
            surfaceSecondary.FillStyle = 0;
        }