/// <summary> /// Once we have a context, we are able to peform various setup routines /// that require us to connect to OpenGL. /// </summary> protected override void OnSetContext() { //fCamera1 = VideoTexture.CreateFromDeviceIndex(GI, 0, 640, 480); fCamera1 = VideoTexture.CreateFromDeviceIndex(GI, 0, true); // Turn off features that we don't need, and they // just slow down video processing GI.Features.AlphaTest.Disable(); GI.Features.Blend.Disable(); GI.Features.DepthTest.Disable(); GI.Features.Dither.Disable(); GI.Features.Fog.Disable(); GI.Features.Lighting.Disable(); // Create the FaceMesh that will receive the gray texture so we // can break it up into 8x8 squares fFaceSize = new Vector3D(fCamera1.Width, fCamera1.Height, 0); fBackgroundCreator = new RGBToGray(GI, fCamera1.Width, fCamera1.Height); fBackgroundCopier = new UnaryTextureProcessor(GI, fCamera1.Width, fCamera1.Height); fBackgroundPixellator = new Pixellate(GI, fCamera1.Width, fCamera1.Height, 8); fImageOperator = new UnaryTextureProcessor(GI, fCamera1.Width, fCamera1.Height); fGrayConverter = new RGBToGray(GI, fCamera1.Width, fCamera1.Height); fGammaCorrection = new PowerLawTransform(GI, fCamera1.Width, fCamera1.Height, 1.0f); fLuminanceThreshold = new LuminanceThreshold(GI, fCamera1.Width, fCamera1.Height, 0f); fLuminanceBinarizer = new LuminanceBinarizer(GI, fCamera1.Width, fCamera1.Height, 0.3f); fLuminanceBinarizer.OverColor = ColorRGBA.Black; fLuminanceBinarizer.UnderColor = ColorRGBA.White; fPixellate = new Pixellate(GI, fCamera1.Width, fCamera1.Height,8); fBlocker = new BlockProcessor(GI, fCamera1.Width, fCamera1.Height, 2); fAverager = new AverageProcessor(GI, fCamera1.Width, fCamera1.Height); fMorpher = new Morph(GI, fCamera1.Width, fCamera1.Height); fEdgeEnhance = new ConvolutionProcessor(GI, fCamera1.Width, fCamera1.Height, ConvolutionKernel.EdgeEnhance); fEdgeEnhance.Distance = 4; fEmboss = new ConvolutionProcessor(GI, fCamera1.Width, fCamera1.Height, ConvolutionKernel.Emboss); fSoften = new ConvolutionProcessor(GI, fCamera1.Width, fCamera1.Height, ConvolutionKernel.GaussianBlur); fSoften.Distance = 4; fSobell = new ConvolutionProcessor(GI, fCamera1.Width, fCamera1.Height, ConvolutionKernel.Sobell); fLaplacian = new ConvolutionProcessor(GI, fCamera1.Width, fCamera1.Height, ConvolutionKernel.Laplacian); fDifference = new DifferenceProcessor(GI, fCamera1.Width, fCamera1.Height); // We want replace mode because we don't care about // the values that are currently in place, we just want // to replace them. GI.TexEnv(TextureEnvModeParam.Replace); fGrayMesh = new XYAxesMesh(GI, new Vector3D(fCamera1.Width, fCamera1.Height, 0), new Resolution(2, 2), null); fPointMesh = new XYAxesPointMesh(GI, new Vector3D(fCamera1.Width, fCamera1.Height, 0), new Resolution(fCamera1.Width/4, fCamera1.Height/4), null); }
protected override void DrawBegin() { // Start with viewport covering whole window GI.Viewport(0, 0, fViewWidth, fViewHeight); // Create an orthographic view so we can draw // using 2D coordinates and not really worry about the // camera position GI.MatrixMode(MatrixMode.Projection); GI.LoadIdentity(); GI.Ortho(0, fViewWidth, 0, fViewHeight, -1.0, 1.0); // Clear the color buffer to an unlikely color so // that we can see where the drawing is NOT occuring GI.Buffers.ColorBuffer.Color = new ColorRGBA(1, 0, 0, 1); ; GI.Buffers.ColorBuffer.Clear(); // If the resolution of the mesh changed since the last time we were // drawing, recreate the mesh using the newest dimensions. if (fResolutionChanged) { Console.WriteLine("Block Size: {0}", fBlockSize); fResolutionChanged = false; fResolution = new Resolution(fVideoTexture.Width / fBlockSize, fVideoTexture.Height / fBlockSize); fFaceMesh = new XYAxesMesh(fFaceSize, fResolution, fYTexture); } }