コード例 #1
0
ファイル: SDLWindow.cs プロジェクト: hyyly/teslagame
 public SDLWindow(Configuration configuration)
 {
     InitWindow(configuration);
     InitGL(configuration);
     Tao.DevIl.Il.ilInit();
     Tao.DevIl.Ilut.ilutInit();
 }
コード例 #2
0
ファイル: AudioContext.cs プロジェクト: hyyly/teslagame
        public AudioContext(Configuration c)
        {
            Al.alGetError();
            if (!SubSystemsInitialized)
            {
                Alut.alutInit();
                SubSystemsInitialized = true;
            }

            Check();
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: hyyly/teslagame
        static void Initialize()
        {
            c  = new Configuration("config.dat");
            audioContext = new AudioContext(c);
            listener = new Listener();

            w = new SDLWindow(c);
            w.Add(buttonAction);
        }
コード例 #4
0
ファイル: SDLWindow.cs プロジェクト: hyyly/teslagame
        private void InitWindow(Configuration configuration)
        {
            width = configuration.resWidth;
            height = configuration.resHeight;
            centerX = width / 2;
            centerY = height / 2;
            bpp = configuration.bpp;
            Name = configuration.title;
            Fullscreen = configuration.fullscreen;
            buttonActionDelegate = new ButtonAction(buttonAction);
            alwaysUpdateMouse = true;
            exceptions = 0;

            if (Fullscreen)
            {
                flags = (/*Sdl.SDL_HWACCEL | Sdl.SDL_HWSURFACE |*/ Sdl.SDL_OPENGL | Sdl.SDL_FULLSCREEN);

                bpp = 32/*System.Windows.Forms.Screen.PrimaryScreen.BitsPerPixel*/;

                /*Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
                Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;*/
            }
            else
                flags = (/*Sdl.SDL_HWACCEL | Sdl.SDL_HWSURFACE |*/ Sdl.SDL_OPENGL);

            quitFlag = false;
            try
            {
                Log.Write("InitSDL: " + Width.ToString() + "x" + Height.ToString() + "@" + bpp.ToString());

                Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING);
                Sdl.SDL_WM_SetCaption(Name, "");

                IntPtr surfacePtr = Sdl.SDL_SetVideoMode(Width, Height, 32, flags);

                Sdl.SDL_Rect rect2 = new Sdl.SDL_Rect(0, 0, (short)Width, (short)Height);
                Sdl.SDL_SetClipRect(surfacePtr, ref rect2);
                Sdl.SDL_WarpMouse((short)centerX, (short)centerY);
                Log.Write("[" + (short)centerX + ", " + (short)centerY + "] <- [" + centerX + ", " + centerY + "]");
                Sdl.SDL_ShowCursor(0);
            }
            catch
            {
                Sdl.SDL_Quit(); // Vi kallar inte Quit() här för detta är Ändå första funktionen så om det inte går här så blir det så mycket null fel I Quit();
                quitFlag = true;
                Log.Write("Create OpenGL Window Failure", LogType.CriticalError);
                throw;
            }
        }
コード例 #5
0
ファイル: SDLWindow.cs プロジェクト: hyyly/teslagame
        private void InitGL(Configuration configuration)
        {
            Gl.glShadeModel(Gl.GL_SMOOTH);
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            //Gl.glDepthFunc(Gl.GL_ALWAYS);
            Gl.glDepthFunc(Gl.GL_LEQUAL);
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glEnable(Gl.GL_BLEND);

            Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

            /* Setup LIGHTING  */
            float[] LightAmbient = { 0.1f, 0.09f, 0.06f, 1.0f };
            float[] LightDiffuse = { 1.0f, 0.819607843f, 0.450980392f, 1.0f };
            float[] LightPosition = { -0.33f, 0.33f, -0.33f, 0.0f };
            Gl.glEnable(Gl.GL_LIGHTING);
            Gl.glEnable(Gl.GL_LIGHT1);
            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_AMBIENT, LightAmbient);
            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_DIFFUSE, LightDiffuse);
            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_POSITION, LightPosition);

            float[] LightSpot = {1.0f, 1.0f, 1.0f, 1.0f};

            //Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_SRC_ALPHA);
            //Gl.glBlendFunc(Gl.GL_SRC_ALPHA_SATURATE, Gl.GL_ONE);
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);  //perfekt för alla mina TexturedQuad
            Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST);

            /* Required setup stuff */
            Gl.glViewport(0, 0, Width, Height);
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluPerspective(45.0f, Width / (float)Height, 0.1f, 2000.0f);
            camera = new Camera(new Vector3f(0.0f, 0.0f, 0.0f), 45.0f, (float)Width / (float)Height, 0.1f, 2000.0f);
            frustum = new Frustum(camera);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();

            //Gl.glEnable(Gl.GL_CULL_FACE);
            //Gl.glPolygonMode(Gl.GL_FRONT, Gl.GL_FILL);
            //Gl.glFrontFace(Gl.GL_CW);

            int error = Gl.glGetError();
            if (error != Gl.GL_NO_ERROR)
                Log.Write("OpenGL: " + Gl.glGetString(error), LogType.CriticalError);
        }