protected override void OnLoad(EventArgs e) { base.OnLoad(e); LoadGLTextures(); GL.Enable(All.Texture2D); GL1.ShadeModel(All1.Smooth); // Enables Smooth Shading GL.ClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background // Create a depth renderbuffer uint depthRenderBuffer = 0; GL.GenRenderbuffers(1, ref depthRenderBuffer); GL.BindRenderbuffer(All.Renderbuffer, depthRenderBuffer); // Allocate storage for the new renderbuffer GL.RenderbufferStorage(All.Renderbuffer, All.DepthComponent16, Size.Width, Size.Height); // Attach the renderbuffer to the framebuffer's depth attachment point GL.FramebufferRenderbuffer(All.Framebuffer, All.DepthAttachment, All.Renderbuffer, depthRenderBuffer); GL1.ClearDepth(1.0f); // Depth Buffer Setup GL1.Enable(All1.DepthTest); // Enables Depth Testing GL1.DepthFunc(All1.Lequal); // The Type Of Depth Test To Do GL1.Hint(All1.PerspectiveCorrectionHint, All1.Nicest); // Really Nice Perspective Calculations GL1.Light(All1.Light0, All1.Ambient, LightAmbient); // Setup The Ambient Light GL1.Light(All1.Light0, All1.Diffuse, LightDiffuse); // Setup The Diffuse Light GL1.Light(All1.Light0, All1.Position, LightPosition); // Position The Light GL1.Enable(All1.Light0); GL1.Color4(1.0f, 1.0f, 1.0f, 0.5f); // Full Brightness, 50% Alpha ( NEW ) GL1.BlendFunc(All1.SrcAlpha, All1.One); // Blending Function For Translucency Based On Source Alpha Value ( NEW ) }
private void End11() { // Disable Blending by default = BlendState.Opaque GL11.Disable(All11.Blend); // set the blend mode if (_blendState == BlendState.NonPremultiplied) { GL11.BlendFunc(All11.One, All11.OneMinusSrcAlpha); GL11.Enable(All11.Blend); } if (_blendState == BlendState.AlphaBlend) { GL11.BlendFunc(All11.SrcAlpha, All11.OneMinusSrcAlpha); GL11.Enable(All11.Blend); } if (_blendState == BlendState.Additive) { GL11.BlendFunc(All11.SrcAlpha, All11.One); GL11.Enable(All11.Blend); } // set camera GL11.MatrixMode(All11.Projection); GL11.LoadIdentity(); // Switch on the flags. switch (this.graphicsDevice.PresentationParameters.DisplayOrientation) { case DisplayOrientation.LandscapeLeft: { GL11.Rotate(-90, 0, 0, 1); GL11.Ortho(0, this.graphicsDevice.Viewport.Height, this.graphicsDevice.Viewport.Width, 0, -1, 1); break; } case DisplayOrientation.LandscapeRight: { GL11.Rotate(90, 0, 0, 1); GL11.Ortho(0, this.graphicsDevice.Viewport.Height, this.graphicsDevice.Viewport.Width, 0, -1, 1); break; } case DisplayOrientation.PortraitUpsideDown: { GL11.Rotate(180, 0, 0, 1); GL11.Ortho(0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height, 0, -1, 1); break; } default: { GL11.Ortho(0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height, 0, -1, 1); break; } } // Enable Scissor Tests if necessary if (this.graphicsDevice.RenderState.ScissorTestEnable) { GL11.Enable(All11.ScissorTest); } GL11.MatrixMode(All11.Modelview); GL11.Viewport(0, 0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height); // Enable Scissor Tests if necessary if (this.graphicsDevice.RenderState.ScissorTestEnable) { GL11.Scissor(this.graphicsDevice.ScissorRectangle.X, this.graphicsDevice.ScissorRectangle.Y, this.graphicsDevice.ScissorRectangle.Width, this.graphicsDevice.ScissorRectangle.Height); } GL11.LoadMatrix(ref _matrix.M11); // Initialize OpenGL states (ideally move this to initialize somewhere else) GL11.Disable(All11.DepthTest); GL11.TexEnv(All11.TextureEnv, All11.TextureEnvMode, (int)All11.BlendSrc); GL11.Enable(All11.Texture2D); GL11.EnableClientState(All11.VertexArray); GL11.EnableClientState(All11.ColorArray); GL11.EnableClientState(All11.TextureCoordArray); // Enable Culling for better performance GL11.Enable(All11.CullFace); GL11.FrontFace(All11.Cw); GL11.Color4(1.0f, 1.0f, 1.0f, 1.0f); _batcher.DrawBatch11(_sortMode); }
public void EndGL11() { // Disable Blending by default = BlendState.Opaque GL11.Disable(ALL11.Blend); // set the blend mode if (_blendState == BlendState.NonPremultiplied) { GL11.BlendFunc(ALL11.SrcAlpha, ALL11.OneMinusSrcAlpha); GL11.Enable(ALL11.Blend); } if (_blendState == BlendState.AlphaBlend) { GL11.BlendFunc(ALL11.One, ALL11.OneMinusSrcAlpha); GL11.Enable(ALL11.Blend); } if (_blendState == BlendState.Additive) { GL11.BlendFunc(ALL11.SrcAlpha, ALL11.One); GL11.Enable(ALL11.Blend); } if (_blendState == BlendState.Multiply) { GL11.BlendFunc(ALL11.DstColor, ALL11.Zero); GL11.Enable(ALL11.Blend); } if (_blendState == BlendState.Multiplyx2) { GL11.BlendFunc(ALL11.DstColor, ALL11.SrcColor); GL11.Enable(ALL11.Blend); } // set camera GL11.MatrixMode(ALL11.Projection); GL11.LoadIdentity(); GL11.Ortho(0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height, 0, -1, 1); // Enable Scissor Tests if necessary if (this.graphicsDevice.RasterizerState.ScissorTestEnable) { GL11.Enable(ALL11.ScissorTest); } GL11.MatrixMode(ALL11.Modelview); GL11.Viewport(0, 0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height); // Enable Scissor Tests if necessary if (this.graphicsDevice.RasterizerState.ScissorTestEnable) { GL11.Scissor(this.graphicsDevice.ScissorRectangle.X, this.graphicsDevice.ScissorRectangle.Y, this.graphicsDevice.ScissorRectangle.Width, this.graphicsDevice.ScissorRectangle.Height); } GL11.LoadMatrix(ref _matrix.M11); // Initialize OpenGL states (ideally move this to initialize somewhere else) GL11.Disable(ALL11.DepthTest); GL11.TexEnv(ALL11.TextureEnv, ALL11.TextureEnvMode, (int)ALL11.BlendSrc); GL11.Enable(ALL11.Texture2D); GL11.EnableClientState(ALL11.VertexArray); GL11.EnableClientState(ALL11.ColorArray); GL11.EnableClientState(ALL11.TextureCoordArray); // No need to cull sprites. they will all be same-facing by construction. // Plus, setting frontface to Clockwise is a troll move. GLStateManager.Cull(CullMode.None); GL11.Color4(1.0f, 1.0f, 1.0f, 1.0f); _batcher.DrawBatchGL11(_sortMode, _samplerState); if (this.graphicsDevice.RasterizerState.ScissorTestEnable) { GL11.Disable(ALL11.ScissorTest); } }