Beispiel #1
0
        /// <summary>
        /// Crea la ventana de <c>OSG</c>.
        /// </summary>
        protected virtual void CreateOSGWindow()
        {
            GraphicsContext.Traits traits = this.CreateTraits();

            Trace.WriteLine("Traits:");
            Trace.WriteLine(ToString(traits));

            this.gc = GraphicsContext.createGraphicsContext(traits);

            if (!this.gc.valid())
            {
                Trace.WriteLine("El GraphicsContext {0} no es valido", this.gc.ToString());
            }

            // Se establece el 'viewer'.
            Viewer viewer = new Viewer();

            viewer.asOsgViewerView().setLightingMode(osg.View.LightingMode.SKY_LIGHT);
            this.viewer = viewer;

            // Se establece la camara.
            Camera camera = this.viewer.asOsgViewerView().getCamera();

            camera.setGraphicsContext(this.gc);
            camera.setViewport(new Viewport(0, 0, traits.width, traits.height));
            camera.setProjectionMatrixAsPerspective(30.0f, (double)traits.width / (double)traits.height, 0.5, 1000.0);
            camera.setDrawBuffer((uint)OsgModule.GL_FRONT);
            camera.setReadBuffer((uint)OsgModule.GL_FRONT);
            camera.setClearColor(new Vec4f(0.2f, 0.2f, 0.2f, 1));
            //camera.asCullSettings().setComputeNearFarMode(CullSettings.ComputeNearFarMode.DO_NOT_COMPUTE_NEAR_FAR);
            camera.setClearMask((uint)(OsgModule.GL_COLOR_BUFFER_BIT
                                       | OsgModule.GL_DEPTH_BUFFER_BIT
                                       /*| OsgModule.GL_STENCIL_BUFFER_BIT*/));

            //DisplaySettings settings = this.CreateDisplaySettings();
            //camera.setDisplaySettings(settings);
            //osgViewer.Viewer.asView(this.Viewer).setDisplaySettings(settings);

            //this.Camera.attach(Camera.BufferComponent.STENCIL_BUFFER,));

            //this.Camera = camera;
            this.camera = camera;

            // Se establece el manipulador por defecto: tipo trackball.
            TrackballManipulator manipulator = new TrackballManipulator();

            manipulator.setHomePosition(new Vec3d(-50, 0, 2), new Vec3d(0, 0, 0), new Vec3d(0, 0, 1));
            manipulator.setTransformation(new Vec3d(-50, 0, 2), new Vec3d(0, 0, 0), new Vec3d(0, 0, 1));
            //manipulator.home(0);
            //manipulator.setAutoComputeHomePosition(true);
            manipulator.setAllowThrow(false);
            manipulator.setVerticalAxisFixed(true);
            manipulator.setTrackballSize(1);

            this.Manipulator = manipulator;
        }
Beispiel #2
0
        private static string ToString(GraphicsContext.Traits traits)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("x, y, width, height: {0}, {1}, {2}, {3}", traits.x, traits.y, traits.width, traits.height).AppendLine();
            builder.AppendFormat("windowName: {0}", traits.windowName).AppendLine();
            builder.AppendFormat("windowDecoration: {0}", traits.windowDecoration).AppendLine();
            builder.AppendFormat("supportsResize: {0}", traits.supportsResize).AppendLine();
            builder.AppendFormat("RGBA: {0}, {1}, {2}, {3}", traits.red, traits.green, traits.blue, traits.alpha).AppendLine();
            builder.AppendFormat("depth: {0}", traits.depth).AppendLine();
            builder.AppendFormat("stencil: {0}", traits.stencil).AppendLine();
            builder.AppendFormat("sampleBuffers: {0}", traits.sampleBuffers).AppendLine();
            builder.AppendFormat("samples: {0}", traits.samples).AppendLine();
            builder.AppendFormat("pbuffer: {0}", traits.pbuffer).AppendLine();
            builder.AppendFormat("quadBufferStereo: {0}", traits.quadBufferStereo).AppendLine();
            builder.AppendFormat("doubleBuffer: {0}", traits.doubleBuffer).AppendLine();
            builder.AppendFormat("target: {0}", traits.target).AppendLine();
            builder.AppendFormat("format: {0}", traits.format).AppendLine();
            builder.AppendFormat("level: {0}", traits.level).AppendLine();
            builder.AppendFormat("face: {0}", traits.face).AppendLine();
            builder.AppendFormat("mipMapGeneration: {0}", traits.mipMapGeneration).AppendLine();
            builder.AppendFormat("vsync: {0}", traits.vsync).AppendLine();
            builder.AppendFormat("swapGroupEnabled: {0}", traits.swapGroupEnabled).AppendLine();
            builder.AppendFormat("swapGroup: {0}", traits.swapGroup).AppendLine();
            builder.AppendFormat("swapBarrier: {0}", traits.swapBarrier).AppendLine();
            builder.AppendFormat("useMultiThreadedOpenGLEngine: {0}", traits.useMultiThreadedOpenGLEngine).AppendLine();
            builder.AppendFormat("useCursor: {0}", traits.useCursor).AppendLine();
            builder.AppendFormat("glContextVersion: {0}", traits.glContextVersion).AppendLine();
            builder.AppendFormat("glContextFlags: {0}", traits.glContextFlags).AppendLine();
            builder.AppendFormat("glContextProfileMask: {0}", traits.glContextProfileMask).AppendLine();
            //getContextVersion(SWIGTYPE_p_unsigned_int major, SWIGTYPE_p_unsigned_int minor)
            builder.AppendFormat("sharedContext: {0}", traits.sharedContext).AppendLine();
            builder.AppendFormat("inheritedWindowData: {0}", traits.inheritedWindowData).AppendLine();
            builder.AppendFormat("setInheritedWindowPixelFormat: {0}", traits.setInheritedWindowPixelFormat).AppendLine();
            builder.AppendFormat("overrideRedirect: {0}", traits.overrideRedirect).AppendLine();
            builder.AppendFormat("swapMethod: {0}", traits.swapMethod).AppendLine();

            GraphicsContext.ScreenIdentifier sidentifier = traits.asScreenIdentifier();
            builder.AppendFormat("displayName: {0}", sidentifier.displayName()).AppendLine();
            builder.AppendFormat("hostName: {0}", sidentifier.hostName).AppendLine();
            builder.AppendFormat("displayNum: {0}", sidentifier.displayNum).AppendLine();
            builder.AppendFormat("screenNum: {0}", sidentifier.screenNum).AppendLine();

            return(builder.ToString());
        }
Beispiel #3
0
        protected virtual GraphicsContext.Traits CreateTraits()
        {
            Referenced windata = GraphicsWindowWin32.WindowData.create(this.Handle);

            GraphicsContext.Traits traits = new GraphicsContext.Traits();
            traits.x                = 0;
            traits.y                = 0;
            traits.width            = this.Width;
            traits.height           = this.Height;
            traits.supportsResize   = true;
            traits.windowDecoration = false;
            traits.doubleBuffer     = true;
            //traits.sharedContext = new GraphicsContextObserver();
            traits.inheritedWindowData = new ReferencedRef(windata);

            //traits.setInheritedWindowPixelFormat = true;
            traits.setInheritedWindowPixelFormat = false;
            traits.stencil       = stencil;
            traits.depth         = depth;
            traits.red           = red;
            traits.green         = green;
            traits.blue          = blue;
            traits.alpha         = alpha;
            traits.samples       = (uint)numSamples; // to make anti-aliased
            traits.sampleBuffers = (uint)((numSamples > 0) ? 1 : 0);

            // disable vertical sync.
            traits.vsync      = this.EnableVSync;
            traits.windowName = this.Name;
            //traits.useMultiThreadedOpenGLEngine

            traits.swapMethod = swapMethod;

            //traits.glContextVersion = version;

            return(traits);
        }