static void Draw()
        {
            Sdl.SDL_FillRect(screen, ref screenArea, 0); //Clear for next draw cycle
            screenData = (Sdl.SDL_Surface)Marshal.PtrToStructure(screen, typeof(Sdl.SDL_Surface)); //Put the screen data in its place

            switch (Adventurer.gameState)
            {
            case GameState.OpeningMenu:
                Draw_Opening();
                break;

            case GameState.NameSelect:
                Draw_Name();
                break;

            case GameState.CreatureSelect:
                Draw_CreatureSel();
                break;

            case GameState.HelpMenu:
                Draw_Help();
                break;

            case GameState.MainGame:
                Draw_Main();
                break;

            case GameState.InventoryMenu:
                Draw_Inventory();
                break;

            case GameState.HealthMenu:
                Draw_Health();
                break;

            case GameState.WaitForPosition:
                Draw_GetPos();
                break;

            case GameState.EscapeMenu:
                Draw_Escape();
                break;
            }

            Sdl.SDL_Flip(screen); //Update screen
        }
Exemple #2
0
		public override void EndScreenDeviceChange(string screenDeviceName, int clientWidth, int clientHeight)
        {
			this.screenDeviceName = screenDeviceName;
			OnScreenDeviceNameChanged();
			
			int flags = Sdl.SDL_OPENGL;
			if (willBeFullScreen)
				flags |= Sdl.SDL_FULLSCREEN;
			
			int bitsPerPixel = 0;
			SurfaceFormat format;
			if (game.GraphicsDevice == null)
			{
				// TODO This cast should be tested against MS XNA
				GraphicsDeviceManager graphicsManager = (GraphicsDeviceManager)game.Services.GetService(typeof (IGraphicsDeviceManager));
				format = graphicsManager.PreferredBackBufferFormat;
			}
			else 
				format = game.GraphicsDevice.PresentationParameters.BackBufferFormat;
			
			if (format == SurfaceFormat.Color || format == SurfaceFormat.Bgr32 || format == SurfaceFormat.Rgba32)
				bitsPerPixel = 32;
			// TODO add support for other surface formats
			
			IntPtr sdlSurfacePtr = Sdl.SDL_SetVideoMode(clientWidth, clientHeight, bitsPerPixel, flags);
			if (sdlSurfacePtr != IntPtr.Zero)
				sdlSurface = (Sdl.SDL_Surface)Marshal.PtrToStructure(sdlSurfacePtr, typeof(Sdl.SDL_Surface));
			
#warning SDL 1.2 doesn't support getting the window position, only the dimensions
			clientBounds.Width = clientWidth;
			clientBounds.Height = clientHeight;
			
			OnClientSizeChanged();
			
			inTransition = false;
        }
        public void initSDL()
        {
            int VideoFlags;
            IntPtr ptrVideoInfo = IntPtr.Zero;
            Sdl.SDL_VideoInfo SDLVideoInfo;
            Sdl.SDL_Event SDLEvent = new Sdl.SDL_Event();
            bool isActive = true;

            // SDL Code von http://www.gamedev.de/index.php?name=News&sid=117&file=article&pageid=2
            // SDL initialisieren
            if(Sdl.SDL_Init(Sdl.SDL_INIT_VIDEO) < 0)
            {
                Console.WriteLine("SDL initialization failed:\n" + Sdl.SDL_GetError());
                Sdl.SDL_Quit();
                return;
            }

            // Video Info einlesen
            ptrVideoInfo = Sdl.SDL_GetVideoInfo();

            if(ptrVideoInfo == IntPtr.Zero)
            {
                Console.WriteLine("Video Query failed:\n" + Sdl.SDL_GetError());
                Sdl.SDL_Quit();
                return;
            }
            else
            {
                SDLVideoInfo = (Sdl.SDL_VideoInfo)Marshal.PtrToStructure(ptrVideoInfo, typeof(Sdl.SDL_VideoInfo));
            }

            // Video Flags festlegen
            //VideoFlags  = Sdl.SDL_OPENGL;
            VideoFlags = Sdl.SDL_GL_DOUBLEBUFFER;
            VideoFlags |= Sdl.SDL_HWPALETTE;
            //VideoFlags |= Sdl.SDL_RESIZABLE;

            // überprüfen ob wir Hardware Surfaces haben
            if(SDLVideoInfo.hw_available == 1)
                VideoFlags |= Sdl.SDL_HWSURFACE;
            else
                VideoFlags |= Sdl.SDL_SWSURFACE;

            // Überprüfen ob wir Hardwareunterstützung für bliting haben
            if(SDLVideoInfo.blit_hw == 1)
                VideoFlags |= Sdl.SDL_HWACCEL;

            // OpenGL Double Buffering einschalten
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DOUBLEBUFFER, 1);

            // Surface Pointer holen
            ptrSurface = Sdl.SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, COLOR_DEPTH, VideoFlags);
            Sdl.SDL_WM_SetCaption("Arena of Glory", "");

            // Surface pointer überprüfen
            if(ptrSurface == IntPtr.Zero)
            {
                Console.WriteLine("Video Mode set failed:\n" + Sdl.SDL_GetError());
                Sdl.SDL_Quit();
                return;
            }
            else
            {
                SDLSurface = (Sdl.SDL_Surface)Marshal.PtrToStructure(ptrSurface, typeof(Sdl.SDL_Surface));
            }

            Console.WriteLine("Video Driver: " + Sdl.SDL_VideoDriverName("", 128));

            while(!done)
            {
                // Events aus dem Eventqueue auselesen
                while(Sdl.SDL_PollEvent(out SDLEvent) == 1)
                {
                    switch(SDLEvent.type)
                    {
                        case Sdl.SDL_ACTIVEEVENT:
                            // Überprüfen ob wir den Focus verloren haben
                            if(SDLEvent.active.gain == 0)
                                isActive = false;
                            else
                                isActive = true;
                            break;
                        case Sdl.SDL_KEYDOWN:
                             // Tastatureingaben behandeln
                            if(this.KeyDown != null)
                                this.KeyDown(SDLEvent.key.keysym);
                            break;
                        case Sdl.SDL_KEYUP:
                            if(this.KeyUp != null)
                                this.KeyUp(SDLEvent.key.keysym);
                            break;
                        case Sdl.SDL_QUIT:
                             // Wenn das SDL Fenster geschlossen wird.
                            done = true;
                            break;
                    }
                }
                // Scene Zeichnen wenn wir den Fokus haben
                //if(isActive)
                //{
                DrawGlScene();
                Sdl.SDL_GL_SwapBuffers();  // Buffer flip
                //}
                Sdl.SDL_Delay(25);
            }

            Sdl.SDL_Quit ();
        }
Exemple #4
0
        static void Main()
        {
            Sdl.SDL_Init(Sdl.SDL_INIT_VIDEO);

            g_pDisplaySurface = Sdl.SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, Sdl.SDL_DOUBLEBUF);
            g_DisplaySurface = (Sdl.SDL_Surface)Marshal.PtrToStructure(g_pDisplaySurface, typeof(Sdl.SDL_Surface));

            Init();

            Sdl.SDL_ShowCursor(0);

            for (; ; )
            {
                if (Sdl.SDL_PollEvent(out g_Event) == 0)
                {
                    DoFrame();
                    Sdl.SDL_Flip(g_pDisplaySurface);

                    int forward = 0;
                    int strafe = 0;

                    int numkeys;
                    byte[] keys = Sdl.SDL_GetKeyState(out numkeys);
                    if (keys[Sdl.SDLK_w] != 0) { forward = 10; }
                    if (keys[Sdl.SDLK_a] != 0) { strafe = -10; }
                    if (keys[Sdl.SDLK_s] != 0) { forward = -10; }
                    if (keys[Sdl.SDLK_d] != 0) { strafe = 10; }

                    int x, y;
                    byte state = Sdl.SDL_GetMouseState(out x, out y);

                    Voxlap.dpoint3d vec = new Voxlap.dpoint3d()
                    {
                        x = forward * or.ifo.x + strafe * or.ist.x,
                        y = forward * or.ifo.y + strafe * or.ist.y,
                        z = 0
                    };

                    or.ipo = Voxlap.ClipMove(or.ipo, vec, 8.0);

                    //or.ipo.x += forward * or.ifo.x;
                    //or.ipo.y += forward * or.ifo.y;

                    //or.ipo.x += strafe * or.ist.x;
                    //or.ipo.y += strafe * or.ist.y;

                }
                else
                {
                    if (g_Event.type == Sdl.SDL_MOUSEMOTION)
                    {
                        or.ifo = TodPoint3d(Voxlap.Rotate(
                            ToPoint3d(or.ifo),
                            new Voxlap.point3d() { z = 1 },
                            (float)g_Event.motion.xrel / 100f));

                        or.ihe = TodPoint3d(Voxlap.Rotate(
                            ToPoint3d(or.ihe),
                            new Voxlap.point3d() { z = 1 },
                            (float)g_Event.motion.xrel / 100f));

                        or.ist = TodPoint3d(Voxlap.Rotate(
                            ToPoint3d(or.ist),
                            new Voxlap.point3d() { z = 1 },
                            (float)g_Event.motion.xrel / 100f));

                        float newangle = vertAngle + (float)-g_Event.motion.yrel / 100f;

                        if (newangle < Math.PI / 2 && newangle > -Math.PI / 2)
                        {
                            or.ifo = TodPoint3d(Voxlap.Rotate(
                                ToPoint3d(or.ifo),
                                ToPoint3d(or.ist),
                                (float)-g_Event.motion.yrel / 100f));

                            or.ihe = TodPoint3d(Voxlap.Rotate(
                                ToPoint3d(or.ihe),
                                ToPoint3d(or.ist),
                                (float)-g_Event.motion.yrel / 100f));

                            or.ist = TodPoint3d(Voxlap.Rotate(
                                ToPoint3d(or.ist),
                                ToPoint3d(or.ist),
                                (float)-g_Event.motion.yrel / 100f));

                            vertAngle = newangle;
                        }

                        Sdl.SDL_EventState(Sdl.SDL_MOUSEMOTION, Sdl.SDL_IGNORE);
                        Sdl.SDL_WarpMouse(SCREEN_WIDTH >> 1, SCREEN_HEIGHT >> 1);
                        Sdl.SDL_EventState(Sdl.SDL_MOUSEMOTION, Sdl.SDL_ENABLE);

                    }

                    if (g_Event.type == Sdl.SDL_MOUSEBUTTONDOWN)
                    {
                        if (g_Event.button.button == Sdl.SDL_BUTTON_WHEELUP)
                        {
                            or.ipo.z -= 10;
                        }

                        if (g_Event.button.button == Sdl.SDL_BUTTON_WHEELDOWN)
                        {
                            or.ipo.z += 10;
                        }
                    }

                    if (g_Event.type == Sdl.SDL_KEYDOWN)
                    {
                        if (g_Event.key.keysym.sym == Sdl.SDLK_ESCAPE)
                        {
                            break;
                        }
                    }

                    if (g_Event.type == Sdl.SDL_QUIT) break;

                }
            }

            Sdl.SDL_Quit();
        }