Exemplo n.º 1
0
 // unfortunately getting display geometry is platform dependent, so
 // we abstract the various methods for doing this here
 public static IDisplayGeometry GetDisplayGeometry()
 {
     if (System.Environment.OSVersion.Platform == PlatformID.Win32Windows ||
         System.Environment.OSVersion.Platform == PlatformID.Win32NT)
     {
         if (instance == null)
         {
             instance = new DisplayGeometryWindows();
         }
         return(instance);
     }
     else
     {
         throw new Exception("IDisplayGeometry not yet implemented for platform " + System.Environment.OSVersion.Platform.ToString());
         // return new LinuxDisplayGeomtry();
         // etc...
     }
 }
Exemplo n.º 2
0
 // unfortunately getting display geometry is platform dependent, so
 // we abstract the various methods for doing this here
 public static IDisplayGeometry GetDisplayGeometry()
 {
     if (System.Environment.OSVersion.Platform == PlatformID.Win32Windows ||
             System.Environment.OSVersion.Platform == PlatformID.Win32NT )
         {
             if (instance == null)
             {
                 instance = new DisplayGeometryWindows();
             }
             return instance;
         }
         else
         {
             throw new Exception("IDisplayGeometry not yet implemented for platform " + System.Environment.OSVersion.Platform.ToString());
             // return new LinuxDisplayGeomtry();
             // etc...
         }
 }
Exemplo n.º 3
0
        private void Reshape(int width, int height)
        {
            Gl.glViewport(0, 0, width, height);
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluPerspective(60.0, (float)width / (float)height, _NearClip, _FarClip);
            _FieldOfView = 60.0;
            _ScreenDistanceScreenCoords = (int)((double)height / 2 / Math.Tan(60.0 / 2 * Math.PI / 180));
            LogFile.GetInstance().WriteLine("_ScreenDistanceScreenCoords: " + _ScreenDistanceScreenCoords);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();
            Glu.gluLookAt(0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
            //Gl.glShadeModel(Gl.GL_FLAT;
            //Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glPolygonMode(Gl.GL_BACK, Gl.GL_LINE);

            IDisplayGeometry dg = DisplayGeometryFactory.CreateDisplayGeometry();

            innerwindowwidth  = dg.WindowWidth;
            innerwindowheight = dg.WindowHeight;
            LogFile.GetInstance().WriteLine("inner window height: " + innerwindowheight);
        }
Exemplo n.º 4
0
        public void Init()
        {
            LogFile.WriteLine("init sdl");

            // int bpp = pixelFormat.BitsPerPixel;

            /*
             *      Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_RED_SIZE, 5 );
             *      Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_GREEN_SIZE, 5 );
             *      Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_BLUE_SIZE, 5 );
             *      Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_DEPTH_SIZE, 16 );
             *      Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_DOUBLEBUFFER, 1 );
             *
             *      Sdl.SDL_WM_SetIcon(Sdl.SDL_LoadBMP("osmpico32.bmp"), null );
             *      if( Sdl.SDL_SetVideoMode( iWindowWidth, iWindowHeight, bpp, Sdl.SDL_OPENGL | Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF ) == IntPtr.Zero )
             *      {
             *          LogFile.WriteLine(  "Video mode set failed: " + Sdl.SDL_GetError().ToString() ); // Console.WriteLine
             *          return;
             *      }
             *
             *      Sdl.SDL_WM_SetCaption( WindowName, "" );
             */
            //iWindowWidth = SdlDotNet.Video.Screen.Width;// Sdl.GetScreenWidth();
            //iWindowHeight = SdlDotNet.Video.Screen.Height; // Sdl.GetScreenHeight();

            System.Drawing.Icon icon = new System.Drawing.Icon(EnvironmentHelper.GetExeDirectory() + "/Metaverse.ico");
            SdlDotNet.Video.WindowIcon(icon);

            iWindowWidth  = Config.GetInstance().windowwidth;
            iWindowHeight = Config.GetInstance().windowheight;

            LogFile.WriteLine("requested window width/height: " + iWindowWidth.ToString() + " " + OuterWindowHeight.ToString()); // Console.WriteLine

            Video.SetVideoModeWindowOpenGL(iWindowWidth, iWindowHeight);
            //Video.SetVideoModeOpenGL(iWindowWidth, WindowHeight, FullScreenBitsPerPixel);

            LogFile.WriteLine(Video.WindowHandle.ToString());

            IDisplayGeometry displaygeometry = DisplayGeometryFactory.GetDisplayGeometry();

            innerwidth  = displaygeometry.WindowWidth;
            innerheight = displaygeometry.WindowHeight;

            string extensions = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Gl.glGetString(Gl.GL_EXTENSIONS));

            LogFile.WriteLine(extensions);

            if (extensions.IndexOf("GL_ARB_multitexture") >= 0)
            {
                GlExtensionLoader.LoadExtension("GL_ARB_multitexture");           // Is Multitexturing Supported?
                Gl.glGetIntegerv(Gl.GL_MAX_TEXTURE_UNITS_ARB, out MaxTexelUnits);
                LogFile.WriteLine("max texel units: " + MaxTexelUnits);
                Multitexturing = true;
            }

            LogFile.WriteLine(Marshal.PtrToStringAnsi(Gl.glGetString(Gl.GL_VERSION)));

            Video.WindowCaption = WindowName;

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

            Gl.glEnable(Gl.GL_DEPTH_TEST);
            //Gl.glEnable(Gl.GL_TEXTURE_2D);
            //Gl.glEnable (Gl.GL_CULL_FACE);

            Gl.glEnable(Gl.GL_LIGHTING);
            Gl.glEnable(Gl.GL_LIGHT0);

            Tao.DevIl.Ilut.ilutRenderer(Tao.DevIl.Ilut.ILUT_OPENGL);

            //Gl.glShadeModel(Gl.GL_SMOOTH);

            Reshape(iWindowWidth, iWindowHeight);

            float[] ambientLight  = new float[] { 0.4f, 0.4f, 0.4f, 1.0f };
            float[] diffuseLight  = new float[] { 0.6f, 0.6f, 0.6f, 1.0f };
            float[] specularLight = new float[] { 0.2f, 0.2f, 0.2f, 1.0f };
            float[] position      = new float[] { -1.0f, 0.2f, -0.4f, 1.0f };

            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT, ambientLight);
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, diffuseLight);
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_SPECULAR, specularLight);
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, position);

            /*
             *
             * Gl.glLoadIdentity();
             *
             * Gl.glMatrixMode( Gl.GL_PROJECTION );
             * Gl.glLoadIdentity();
             * float aspect = (float)iWindowWidth / (float)iWindowHeight;
             * Glu.gluPerspective( 45.0, aspect, 0.5, 100.0 );
             *
             * Gl.glMatrixMode( Gl.GL_MODELVIEW );
             * Gl.glViewport (0, 0, iWindowWidth, iWindowHeight);
             *
             */
            Events.Quit            += new QuitEventHandler(this.Quit);
            Events.MouseMotion     += new MouseMotionEventHandler(this._MouseMotion);
            Events.MouseButtonDown += new MouseButtonEventHandler(Events_MouseButtonDown);
            Events.MouseButtonUp   += new MouseButtonEventHandler(Events_MouseButtonUp);
            Events.KeyboardDown    += new KeyboardEventHandler(this._KeyDown);
            Events.KeyboardUp      += new KeyboardEventHandler(this._KeyUp);
        }