Example #1
0
        unsafe private bool CheckARGB8888_()
        {
            if (surface == IntPtr.Zero)
            {
                return(false);
            }
            SDL.SDL_Surface *    surface_ = (SDL.SDL_Surface *)surface;
            SDL.SDL_PixelFormat *format   = (SDL.SDL_PixelFormat *)surface_->format;
            if (format == null)
            {
                return(false);
            }

            if (SDL.SDL_BYTEORDER.Equals(SDL.SDL_BIG_ENDIAN))
            {
                return(format->BitsPerPixel == 32 &&
                       format->Rmask == 0xff000000 &&
                       format->Gmask == 0x00ff0000 &&
                       format->Bmask == 0x0000ff00 &&
                       format->Amask == 0x000000ff
                       );
            }
            else
            {
                return(format->BitsPerPixel == 32 &&
                       format->Rmask == 0x000000ff &&
                       format->Gmask == 0x0000ff00 &&
                       format->Bmask == 0x00ff0000 &&
                       format->Amask == 0xff000000
                       );
            }
        }
Example #2
0
        unsafe private Color4ub GetPixel_(int x, int y)
        {
            SDL.SDL_Surface *    surface_ = (SDL.SDL_Surface *)surface;
            SDL.SDL_PixelFormat *format   = (SDL.SDL_PixelFormat *)surface_->format;
            uint u = 0;

            switch (format->BitsPerPixel)
            {
            case 16:
                u = *(ushort *)((byte *)GetPixels_() + y * surface_->pitch + x * 2);
                break;

            case 24:
                byte *p = ((byte *)GetPixels_()) + (y * surface_->pitch + x * 3);
                u = (uint)(p[2] << 16 | p[1] << 8 | p[0]);
                break;

            case 32:
                u = *(uint *)((byte *)GetPixels_() + y * surface_->pitch + x * 4);
                break;
            }

            return(new Color4ub((byte)((u & format->Rmask) >> format->Rshift),
                                (byte)((u & format->Gmask) >> format->Gshift),
                                (byte)((u & format->Bmask) >> format->Bshift),
                                (byte)((u & format->Amask) >> format->Ashift)));
        }
        //initialize the Three Card Poker sprites and variables
        public unsafe ThreeCardPokerGame(IntPtr interfaceWindow)
        {
            window        = interfaceWindow;
            windowSurface = SDL.SDL_GetWindowSurface(window);

            SDL.SDL_Surface *windowSDLSurface = (SDL.SDL_Surface *)windowSurface;
            clearColor  = SDL.SDL_MapRGB(windowSDLSurface->format, 0, 100, 0);
            textColor.r = 255; textColor.b = 255; textColor.g = 255; textColor.a = 255;

            screenRect.x = 0; screenRect.y = 0;
            screenRect.w = 600; screenRect.h = 480;

            cardSprite     = SDL.SDL_LoadBMP("cards.bmp");
            cardBackSprite = SDL.SDL_LoadBMP("card back blue.bmp");
            playButton     = SDL.SDL_LoadBMP("play button.bmp");
            foldButton     = SDL.SDL_LoadBMP("fold button.bmp");
            dealButton     = SDL.SDL_LoadBMP("deal button.bmp");
            quitButton     = SDL.SDL_LoadBMP("quit button.bmp");

            font                = SDL_ttf.TTF_OpenFont("times.ttf", 20);
            betTextSprite       = SDL_ttf.TTF_RenderText_Solid(font, "Ante: $50", textColor);
            playerWinTextSprite = SDL_ttf.TTF_RenderText_Solid(font, "You won!", textColor);
            dealerWinTextSprite = SDL_ttf.TTF_RenderText_Solid(font, "The dealer won.", textColor);
            drawTextSprite      = SDL_ttf.TTF_RenderText_Solid(font, "Draw...", textColor);
        }
Example #4
0
 unsafe private IntPtr GetPixels_()
 {
     if (surface == IntPtr.Zero)
     {
         return(IntPtr.Zero);
     }
     SDL.SDL_Surface *surface_ = (SDL.SDL_Surface *)surface;
     return(surface_->pixels);
 }
Example #5
0
        /// <summary>
        /// パレットから色を取得
        /// </summary>
        /// <param name="i">パレットのインデックス</param>
        private unsafe Color4ub GetPaletteColor(int i)
        {
            SDL.SDL_Surface *    surface_ = (SDL.SDL_Surface *)surface;
            SDL.SDL_PixelFormat *format   = (SDL.SDL_PixelFormat *)surface_->format;
            SDL.SDL_Palette *    palette  = (SDL.SDL_Palette *)format->palette;
            SDL.SDL_Color *      colors   = (SDL.SDL_Color *)palette->colors;
            global::System.Diagnostics.Debug.Assert(i < palette->ncolors);

            return(new Color4ub(colors[i].r, colors[i].g, colors[i].b, 0xff));
        }
Example #6
0
 unsafe private void getSize_(ref int x, ref int y)
 {
     if (surface != IntPtr.Zero)
     {
         SDL.SDL_Surface *surface_ = (SDL.SDL_Surface *)surface;
         x = surface_->h; y = surface_->h;
     }
     else
     {
         x = y = 0;
     }
 }
Example #7
0
 unsafe private int getHeight_()
 {
     if (surface != IntPtr.Zero)
     {
         SDL.SDL_Surface *surface_ = (SDL.SDL_Surface *)surface;
         return(surface_->h);
     }
     else
     {
         return(0);
     }
 }
            bool FillOutInfo()
            {
                unsafe
                {
                    // Get the SDL_Surface*
                    _sdlSurfacePtr = (SDL.SDL_Surface *)(_sdlSurface.ToPointer());

                    // Fetch the SDL_Surface pixel format
                    var fmtPtr = (uint *)(_sdlSurfacePtr->format.ToPointer());
                    _PixelFormat = *fmtPtr;

                    // Get the size of the SDL_Surface
                    _Width  = _sdlSurfacePtr->w;
                    _Height = _sdlSurfacePtr->h;
                    _pitch  = _sdlSurfacePtr->pitch;
                    _pixels = _sdlSurfacePtr->pixels.ToPointer();
                }

                // And now it's bits per pixel and channel masks
                if (SDL.SDL_PixelFormatEnumToMasks(
                        _PixelFormat,
                        out _bpp,
                        out _Rmask,
                        out _Gmask,
                        out _Bmask,
                        out _Amask) == SDL.SDL_bool.SDL_FALSE)
                {
                    return(false);
                }

                if (SDL.SDL_GetSurfaceBlendMode(_sdlSurface, out _blendMode) != 0)
                {
                    return(false);
                }

                if (SDL.SDL_GetSurfaceAlphaMod(_sdlSurface, out _alphaMod) != 0)
                {
                    return(false);
                }

                byte r, g, b;

                if (SDL.SDL_GetSurfaceColorMod(_sdlSurface, out r, out g, out b) != 0)
                {
                    return(false);
                }
                _colorMod = Color.FromArgb(r, g, b);

                _mustLock = SDL.SDL_MUSTLOCK(_sdlSurface);

                return(true);
            }
Example #9
0
        unsafe private bool getAlpha()
        {
            if (surface == IntPtr.Zero)
            {
                return(false);
            }

            SDL.SDL_Surface *    surface_ = (SDL.SDL_Surface *)surface;
            SDL.SDL_PixelFormat *format   = (SDL.SDL_PixelFormat *)surface_->format;

            return(format != null && format->Amask != 0);
            // alpha maskを持つならば、alpha channelがあるのだろう。
        }
Example #10
0
        /// <summary>
        /// SDL_Surfaceに設定されているカラーキーを返すためのヘルパ
        /// </summary>
        /// <returns></returns>
        unsafe private long?getColorKey()
        {
            SDL.SDL_Surface *    surface_ = (SDL.SDL_Surface *)surface;
            SDL.SDL_PixelFormat *format   = (SDL.SDL_PixelFormat *)surface_->format;

            // 転送元カラーキーが設定されていないのでnullを返す
            if ((surface_->flags & SDL.SDL_SRCCOLORKEY) == 0)
            {
                return(null);
            }

            uint ckey = format->colorkey;

            return(ckey);
        }
Example #11
0
        unsafe private Color4ub GetPixel_(int x, int y)
        {
            SDL.SDL_Surface *    surface_ = (SDL.SDL_Surface *)surface;
            SDL.SDL_PixelFormat *format   = (SDL.SDL_PixelFormat *)surface_->format;
            uint u = 0;
            int  i;

            switch (format->BitsPerPixel)
            {
            /*
             * case 1:
             *      i = *((byte*)GetPixels_() + y * surface_->pitch + x / 8);
             *      return GetPaletteColor((i >> (x % 8)) & 0x01);
             * case 2:
             *      i = *((byte*)GetPixels_() + y * surface_->pitch + x / 4);
             *      return GetPaletteColor((i >> (x % 4) * 2) & 0x03);
             * case 4:
             *      i = *((byte*)GetPixels_() + y * surface_->pitch + x / 2);
             *      return GetPaletteColor((i >> (x % 2) * 4) & 0x0f);
             */
            // ↑SDLがそもそもサポートしてないようなので要らない。
            case 8:
                i = *((byte *)GetPixels_() + y * surface_->pitch + x);
                return(GetPaletteColor(i));

            case 16:
                u = *(ushort *)((byte *)GetPixels_() + y * surface_->pitch + x * 2);
                break;

            case 24:
                byte *p = ((byte *)GetPixels_()) + (y * surface_->pitch + x * 3);
                u = (uint)(p[2] << 16 | p[1] << 8 | p[0]);
                break;

            case 32:
                u = *(uint *)((byte *)GetPixels_() + y * surface_->pitch + x * 4);
                break;
            }

            return(new Color4ub((byte)((u & format->Rmask) >> format->Rshift),
                                (byte)((u & format->Gmask) >> format->Gshift),
                                (byte)((u & format->Bmask) >> format->Bshift),
                                (byte)((u & format->Amask) >> format->Ashift)));
        }
Example #12
0
        unsafe private YanesdkResult Blt_(Surface src, int x, int y)
        {
            if (surface == IntPtr.Zero)
            {
                return(YanesdkResult.PreconditionError);                                        // 転送先が構築されていない
            }
            if (src.surface == IntPtr.Zero)
            {
                return(YanesdkResult.InvalidParameter);                                        // 転送元が構築されていない
            }
            SDL.SDL_Surface *surface_ = (SDL.SDL_Surface *)src.surface;
            SDL.SDL_Rect     dest     = new SDL.SDL_Rect();
            dest.x = (short)x;
            dest.y = (short)y;
            dest.w = (ushort)surface_->w;
            dest.h = (ushort)surface_->h;

            return(SDL.SDL_BlitSurface(src.surface, IntPtr.Zero, surface, (IntPtr)(&dest)) == 0 ?
                   YanesdkResult.NoError : YanesdkResult.SdlError);
        }
            protected virtual void Dispose(bool disposing)
            {
                if (_disposed)
                {
                    return;
                }

                DeleteTexture();

                if (_sdlSurface != IntPtr.Zero)
                {
                    SDL.SDL_FreeSurface(_sdlSurface);
                }
                _sdlSurface = IntPtr.Zero;
                unsafe
                {
                    _sdlSurfacePtr = null;
                }
                _sdlRenderer = null;

                _disposed = true;
            }
Example #14
0
        private static unsafe void RenderSprites(bool mini, IntPtr windowPtr, SDL.SDL_Surface *screenSurface)
        {
            int size = 10;

            SDL.SDL_Surface *[] surfaces   = StateSurfaces;
            SDL.SDL_Surface *[] bgSurfaces = RuleBackgroundSurfaces;
            if (mini)
            {
                size       = 3;
                surfaces   = StateSurfacesMini;
                bgSurfaces = RuleBackgroundSurfacesMini;
            }
            SDL.SDL_Rect rect = new SDL.SDL_Rect();
            rect.h = size;
            rect.w = size;
            var pieceGrid = new PieceGrid(100);
            int index     = 0;

            foreach (var kvp in pieceGrid.PointPieces)
            {
                rect.x = kvp.Key.X * size;
                rect.y = kvp.Key.Y * size;
                if (index < surfaces.Length)
                {
                    SDL.SDL_BlitSurface((IntPtr)surfaces[index++], IntPtr.Zero, (IntPtr)screenSurface, ref rect);
                }
                else if (index - surfaces.Length < bgSurfaces.Length)
                {
                    int convertedIndex = index - surfaces.Length;
                    index++;
                    SDL.SDL_BlitSurface((IntPtr)bgSurfaces[convertedIndex], IntPtr.Zero, (IntPtr)screenSurface, ref rect);
                }
                else
                {
                    index = 0;
                }
            }
            SDL.SDL_UpdateWindowSurface(windowPtr);
        }
        public unsafe void init()
        {
            SDL.SDL_Init(SDL.SDL_INIT_VIDEO);
            SDL_ttf.TTF_Init();

            window        = SDL.SDL_CreateWindow("Card Games", SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED, 600, 480, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN);
            windowSurface = SDL.SDL_GetWindowSurface(window);
            arrowSprite   = SDL.SDL_LoadBMP("arrow.bmp");
            titleSprite   = SDL.SDL_LoadBMP("title.bmp");

            SDL.SDL_Surface *windowSDLSurface = (SDL.SDL_Surface *)windowSurface;
            clearColor = SDL.SDL_MapRGB(windowSDLSurface->format, 0, 100, 0);

            textColor.r      = 255; textColor.b = 255; textColor.g = 255; textColor.a = 255;
            favoritesColor.r = 255; favoritesColor.b = 0; favoritesColor.g = 255; favoritesColor.a = 255;

            font = SDL_ttf.TTF_OpenFont("times.ttf", 20);

            string instructionText;

            instructionText        = "ENTER to select game, F to favorite, SPACE to toggle showing favorites";
            instructionTextSurface = SDL_ttf.TTF_RenderText_Solid(font, instructionText, textColor);


            screenRect.x = 0; screenRect.y = 0;
            screenRect.w = 600; screenRect.h = 480;


            //initialize the card games
            gameList.Add(new CardGame("Three Card Poker", 1));
            gameList[0].generateNameSurface(font, textColor);
            gameList.Add(new CardGame("Omaha High Poker", 2));
            gameList[1].generateNameSurface(font, textColor);
            gameList.Add(new CardGame("Three Card Draw", 3));
            gameList[2].generateNameSurface(font, textColor);
            gameList.Add(new CardGame("Pai Gow Poker", 4));
            gameList[3].generateNameSurface(font, textColor);
        }
Example #16
0
        private static unsafe void Render(PieceGrid pieceGrid, bool mini, Dictionary <Point, ICARule> tweakPoints1, IntPtr windowPtr, SDL.SDL_Surface *screenSurface)
        {
            int size = 10;

            SDL.SDL_Surface *[] surfaces   = StateSurfaces;
            SDL.SDL_Surface *[] bgSurfaces = RuleBackgroundSurfaces;
            if (mini)
            {
                size       = 3;
                surfaces   = StateSurfacesMini;
                bgSurfaces = RuleBackgroundSurfacesMini;
            }
            SDL.SDL_Rect rect = new SDL.SDL_Rect();
            rect.h = size;
            rect.w = size;
            foreach (var kvp in pieceGrid.PointPieces)
            {
                rect.x = kvp.Key.X * size;
                rect.y = kvp.Key.Y * size;
                if (kvp.Value.StateValue >= 1)
                {
                    if (!rulesOnlyDisplay)
                    {
                        SDL.SDL_BlitSurface((IntPtr)surfaces[kvp.Value.StateValue], IntPtr.Zero, (IntPtr)screenSurface, ref rect);
                    }
                }
                else
                {
                    if (tweakPoints1.TryGetValue(kvp.Key, out ICARule rule))
                    {
                        SDL.SDL_BlitSurface((IntPtr)bgSurfaces[RuleBackgroundIndexes[rule]], IntPtr.Zero, (IntPtr)screenSurface, ref rect);
                    }
                    else
                    {
                        SDL.SDL_BlitSurface((IntPtr)surfaces[0], IntPtr.Zero, (IntPtr)screenSurface, ref rect);
                    }
                }
            }
            SDL.SDL_UpdateWindowSurface(windowPtr);
        }
Example #17
0
File: Font.cs Project: sinshu/dtf
        unsafe private void RateCheck(ref IntPtr image)
        {
            //	rateが1でなければ、サーフェースを縮小しなければならない。
            if (rate == 1)
            {
                return;
            }                                     // ok
            if (image == IntPtr.Zero)
            {
                return;
            }                                                  // surfaceの作成に失敗しちょる

            SDL.SDL_Surface *image_ = (SDL.SDL_Surface *)image;

            // 1/rateのサイズのサーフェースを作ることからはじめよう
            int ix, iy;

            ix  = image_->w; iy = image_->h;
            ix /= rate; iy /= rate;

            //	これが rateで割り切れない時のことは知らネ
            if (ix == 0 || iy == 0)
            {
                return;
            }

            SDL.SDL_PixelFormat *format = (SDL.SDL_PixelFormat *)image_->format;
            bool bAlpha = (format->BitsPerPixel == 32);

            /*
             *      SDL_ttfの返すサーフェースは、αつきなら32bpp,αなしなら8bppと
             *      決まっちょる
             */

            //	SDLには縮小する関数が無いので、
            //	DIBを作って、それを縮小することにする
            //	SDL_gfxを持ってきてもいいのだが、そこまで大がかりでもないので..

            IntPtr image2;

            if (Surface.CreateDIBstatic(out image2, image_->w, image_->h, bAlpha) != 0)
            {
                return;                  //	作成失敗
            }
            if (bAlpha)
            {
                //	αを無効化しておかないとARGB→ARGBのbltで
                //	αを考慮して転送しやがる
                SDL.SDL_SetAlpha(image, 0, 0);
            }

            if (SDL.SDL_BlitSurface(image, IntPtr.Zero, image2, IntPtr.Zero) != 0)
            {
                SDL.SDL_FreeSurface(image2);
                return;                  // 転送失敗
            }

            IntPtr image2s;

            // ix,iyが2^nの場合、フォントが表示されないのでiy+1していた。
            // 原因が分かったら戻すこと→わかったので戻した。
            if (Surface.CreateDIBstatic(out image2s, ix, iy, bAlpha) != 0)
            {
                SDL.SDL_FreeSurface(image2);
                SDL.SDL_FreeSurface(image2s);
                return;                  //	作成失敗
            }

            //	縮小するためにlockする
            if (SDL.SDL_LockSurface(image2) != 0)
            {
                SDL.SDL_FreeSurface(image2);
                SDL.SDL_FreeSurface(image2s);
                return;                  // lock失敗
            }
            if (SDL.SDL_LockSurface(image2s) != 0)
            {
                SDL.SDL_UnlockSurface(image2s);
                SDL.SDL_FreeSurface(image2);
                SDL.SDL_FreeSurface(image2s);
                return;                  // lock失敗
            }

            SDL.SDL_Surface *image2_, image2s_;
            image2_  = (SDL.SDL_Surface *)image2;
            image2s_ = (SDL.SDL_Surface *)image2s;

            //	縮小ルーチン
            if (bAlpha)
            {
                uint  rt, gt, bt, at;
                uint  rr      = (uint)(rate * rate);
                uint *pixels1 = (uint *)image2_->pixels;
                uint *pixels2 = (uint *)image2s_->pixels;
                for (int y = 0; y < iy /*image2s_->h*/; ++y)
                {
                    uint xx = 0;
                    for (int x = 0; x < ix /*image2s_->w*/; ++x)
                    {
                        //	ピクセルの平均を求める
                        uint  r, g, b, a;
                        uint *pixels1t = pixels1;
                        r = g = b = a = 0;
                        for (int j = 0; j < rate; ++j)
                        {
                            for (int i = 0; i < rate; ++i)
                            {
                                uint p = pixels1t[xx + i];
                                format = (SDL.SDL_PixelFormat *)image2_->format;
                                rt     = p & format->Rmask;
                                rt   >>= format->Rshift;
                                r     += rt;
                                gt     = p & format->Gmask;
                                gt   >>= format->Gshift;
                                g     += gt;
                                bt     = p & format->Bmask;
                                bt   >>= format->Bshift;
                                b     += bt;
                                at     = p & format->Amask;
                                at   >>= format->Ashift;
                                a     += at;
                            }
                            pixels1t = (uint *)(((byte *)pixels1) + image2_->pitch);
                        }
                        r /= rr; g /= rr; b /= rr; a /= rr;
                        //	↑これだと切り捨てすぎかも..
                        // format = (SDL.SDL_PixelFormat*)image2_->format;
                        format     = (SDL.SDL_PixelFormat *)image2s_->format;
                        pixels2[x] = (r << format->Rshift)
                                     + (g << format->Gshift)
                                     + (b << format->Bshift)
                                     + (a << format->Ashift);
                        xx += (uint)rate;
                    }
                    pixels1 = (uint *)(((byte *)pixels1) + image2_->pitch * rate);
                    pixels2 = (uint *)(((byte *)pixels2) + image2s_->pitch);
                }
            }
            else
            {
                //	24bppのはず
                uint  rr      = (uint)(rate * rate);
                byte *pixels1 = (byte *)image2_->pixels;
                byte *pixels2 = (byte *)image2s_->pixels;
                for (int y = 0; y < image2s_->h; ++y)
                {
                    uint xx, x2;
                    xx = x2 = 0;
                    for (int x = 0; x < image2s_->w; ++x)
                    {
                        //	ピクセルの平均を求める
                        uint  r, g, b;
                        byte *pixels1t = pixels1;
                        r = g = b = 0;
                        for (int j = 0; j < rate; ++j)
                        {
                            uint xxx = xx;
                            for (int i = 0; i < rate; ++i)
                            {
                                r   += pixels1t[xxx + i + 0];
                                g   += pixels1t[xxx + i + 1];
                                b   += pixels1t[xxx + i + 2];
                                xxx += 3;
                            }
                            pixels1t = pixels1 + image2_->pitch;
                        }
                        r /= rr; g /= rr; b /= rr;

                        pixels2[x2 + 0] = (byte)r;
                        pixels2[x2 + 1] = (byte)g;
                        pixels2[x2 + 2] = (byte)b;

                        x2 += 3;
                        xx += (uint)(3 * rate);
                    }
                    pixels1 = pixels1 + image2_->pitch * rate;
                    pixels2 = pixels2 + image2s_->pitch;
                }
            }

            //	さすがにunlockは失敗しないでそ..
            SDL.SDL_UnlockSurface(image2);
            SDL.SDL_UnlockSurface(image2s);

            SDL.SDL_FreeSurface(image);
            SDL.SDL_FreeSurface(image2);
            image = image2s;             // 書き換えて返す
        }
Example #18
0
        private static unsafe void CreateSpriteSurfaces(SDL.SDL_Surface *screenSurface)
        {
            IntPtr aliveBmp          = SDL.SDL_ConvertSurface(SDL.SDL_LoadBMP("Alive.bmp"), screenSurface->format, 0);
            IntPtr deadBmp           = SDL.SDL_ConvertSurface(SDL.SDL_LoadBMP("Dead.bmp"), screenSurface->format, 0);
            IntPtr deadTweak1Bmp     = SDL.SDL_ConvertSurface(SDL.SDL_LoadBMP("DeadTweak1.bmp"), screenSurface->format, 0);
            IntPtr aliveMiniBmp      = SDL.SDL_ConvertSurface(SDL.SDL_LoadBMP("AliveMini.bmp"), screenSurface->format, 0);
            IntPtr deadMiniBmp       = SDL.SDL_ConvertSurface(SDL.SDL_LoadBMP("DeadMini.bmp"), screenSurface->format, 0);
            IntPtr deadMiniTweak1Bmp = SDL.SDL_ConvertSurface(SDL.SDL_LoadBMP("DeadMiniTweak1.bmp"), screenSurface->format, 0);

            var rgbValues = new List <List <byte> >()
            {
                new List <byte>()
                {
                    0, 0, 255
                },
                new List <byte>()
                {
                    0, 255, 255
                },
                new List <byte>()
                {
                    255, 255, 0
                },
                new List <byte>()
                {
                    255, 0, 255
                },
                new List <byte>()
                {
                    255, 0, 0
                },
                new List <byte>()
                {
                    0, 255, 0
                },
                new List <byte>()
                {
                    64, 255, 64
                },
                new List <byte>()
                {
                    255, 64, 64
                },
                new List <byte>()
                {
                    64, 64, 255
                },
            };

            int stateValue     = 0;
            int stateValueMini = 0;

            StateSurfaces[stateValue++]         = (SDL.SDL_Surface *)deadBmp;
            StateSurfaces[stateValue++]         = (SDL.SDL_Surface *)aliveBmp;
            StateSurfacesMini[stateValueMini++] = (SDL.SDL_Surface *)deadMiniBmp;
            StateSurfacesMini[stateValueMini++] = (SDL.SDL_Surface *)aliveMiniBmp;

            foreach (List <byte> rgbList in rgbValues)
            {
                SDL.SDL_Surface *newStateSurface = (SDL.SDL_Surface *)SDL.SDL_ConvertSurface(aliveBmp, screenSurface->format, 0);
                ColorMod(newStateSurface, rgbList[0], rgbList[1], rgbList[2]);
                StateSurfaces[stateValue++] = newStateSurface;

                SDL.SDL_Surface *newStateSurfaceMini = (SDL.SDL_Surface *)SDL.SDL_ConvertSurface(aliveMiniBmp, screenSurface->format, 0);
                ColorMod(newStateSurfaceMini, rgbList[0], rgbList[1], rgbList[2]);
                StateSurfacesMini[stateValueMini++] = newStateSurfaceMini;
            }

            int ruleIndex     = 0;
            int ruleIndexMini = 0;

            foreach (List <byte> rgbList in rgbValues)
            {
                SDL.SDL_Surface *newBgSurface = (SDL.SDL_Surface *)SDL.SDL_ConvertSurface(deadTweak1Bmp, screenSurface->format, 0);
                ColorMod(newBgSurface, rgbList[0], rgbList[1], rgbList[2]);
                RuleBackgroundSurfaces[ruleIndex++] = newBgSurface;

                SDL.SDL_Surface *newBgSurfaceMini = (SDL.SDL_Surface *)SDL.SDL_ConvertSurface(deadMiniTweak1Bmp, screenSurface->format, 0);
                ColorMod(newBgSurfaceMini, rgbList[0], rgbList[1], rgbList[2]);
                RuleBackgroundSurfacesMini[ruleIndexMini++] = newBgSurfaceMini;
            }
        }
Example #19
0
        private static unsafe void InitSDL(PieceGrid grid, bool mini, out IntPtr windowPtr, out SDL.SDL_Surface *screenSurface)
        {
            int x;
            int y;
            int factor = 10;

            if (mini)
            {
                factor = 3;
            }
            x = grid.Size * factor;
            y = grid.Size * factor;
            if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) < 0)
            {
                throw new Exception("Could not init SDL");
            }
            windowPtr = SDL2.SDL.SDL_CreateWindow("SDL Test", SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED, x, y, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN);
            if (windowPtr == null)
            {
                throw new Exception("Could not create SDL window");
            }
            screenSurface = (SDL.SDL_Surface *)SDL.SDL_GetWindowSurface(windowPtr);
        }
Example #20
0
 private static unsafe void ColorMod(SDL.SDL_Surface *surface, byte r1, byte g1, byte b1)
 {
     int result = SDL.SDL_SetSurfaceColorMod((IntPtr)surface, r1, g1, b1);
 }
Example #21
0
        static unsafe void Main(string[] args)
        {
            Chip8 core = new Chip8();

            if (args.Length != 1)
            {
                Console.WriteLine("Usage: c8emu <ROM file name>");
                return;
            }

            core.LoadROM(LoadFile(args[0]));

            if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) != 0)
            {
                Console.WriteLine("Failed to initialize SDL.");
                return;
            }

            emulatorWindow = SDL.SDL_CreateWindow("c8emu", SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED, 256, 128, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN);

            if (emulatorWindow == null)
            {
                Console.WriteLine("Failed to create the window.");
                SDL.SDL_Quit();
                return;
            }

            windowSurface = (SDL.SDL_Surface *)SDL.SDL_GetWindowSurface(emulatorWindow);

            screenSurface = (SDL.SDL_Surface *)SDL.SDL_CreateRGBSurface(SDL.SDL_SWSURFACE, 64, 32, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);

            if (screenSurface == null)
            {
                Console.WriteLine("Failed to create the screen surface.");
                SDL.SDL_DestroyWindow(emulatorWindow);
                SDL.SDL_Quit();
                return;
            }

            core.DisplayUpdate += DisplayUpdate;

            //Console.Clear();

            while (true)
            {
                core.FrameAdvance();

                SDL.SDL_Event e;
                while (SDL.SDL_PollEvent(out e) != 0)
                {
                    switch (e.type)
                    {
                    case SDL.SDL_EventType.SDL_WINDOWEVENT:
                        if (e.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE)
                        {
                            SDL.SDL_FreeSurface((IntPtr)screenSurface);
                            SDL.SDL_DestroyWindow(emulatorWindow);
                            SDL.SDL_Quit();
                            return;
                        }

                        break;

                    case SDL.SDL_EventType.SDL_KEYDOWN:
                        HandleKeyEvent(e.key.keysym.sym, core, true);
                        break;

                    case SDL.SDL_EventType.SDL_KEYUP:
                        HandleKeyEvent(e.key.keysym.sym, core, false);
                        break;
                    }
                }

                SDL.SDL_Delay(16);
            }
        }