// Constructors static FrameBufferManager() { // Initialise singleton instance instance = new FrameBufferManager(); // This is where we initialise the GL FrameBuffers and RenderBuffers. instance.renderBuffer = new uint[(int)RenderBuffer.NumRenderBuffers]; GL.GenRenderbuffers((int)RenderBuffer.NumRenderBuffers, instance.renderBuffer); int[] viewport = new int[4]; GL.GetInteger(GetPName.Viewport, viewport); instance.viewportWidth = viewport[2]; instance.viewportHeight = viewport[3]; SetRenderbufferStorage(instance.viewportWidth, instance.viewportHeight); GL.GenFramebuffers(1, out instance.selectionBuffer); GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, instance.selectionBuffer); GL.FramebufferRenderbuffer(FramebufferTarget.DrawFramebuffer, FramebufferAttachment.ColorAttachment0, RenderbufferTarget.Renderbuffer, instance.renderBuffer[(int)RenderBuffer.Color]); GL.FramebufferRenderbuffer(FramebufferTarget.DrawFramebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, instance.renderBuffer[(int)RenderBuffer.Depth]); // Set back to default FrameBuffer GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0); }
// Constructors public Selection() { fbManager = new FrameBufferManager(); console = OutputWindow.Console; info.Selected = null; pollingTimer = new Timer(20); pollingTimer.AutoReset = true; pollingTimer.Elapsed += new System.Timers.ElapsedEventHandler(pollingTimerElapsed); }
// Constructors public Game() : base(640, 480, new GraphicsMode(new ColorFormat(8, 8, 8, 8), 16, 0, 8), "OpenGL 3.1 Example", 0, DisplayDevice.Default, 3, 1, GraphicsContextFlags.Debug) { // Initialise fields WindowBorder = WindowBorder.Fixed; singleSelection = new Selection(); // Setup window view. float widthToHeight = ClientSize.Width / (float)ClientSize.Height; Shader.SetProjectionMatrix(Matrix4.CreatePerspectiveFieldOfView(0.25f, widthToHeight, 60, 120)); Shader.SetLightPosition(new Vector3(3.0f, 4.0f, 5.0f)); GL.Enable(EnableCap.DepthTest); GL.ClearColor(0.2f, 0.2f, 0.2f, 1); // Register a button down event. Mouse.ButtonDown += new EventHandler <OpenTK.Input.MouseButtonEventArgs>(MouseButtonDown); Mouse.ButtonUp += new EventHandler <OpenTK.Input.MouseButtonEventArgs>(MouseButtonUp); Mouse.WheelChanged += new EventHandler <MouseWheelEventArgs>(MouseWheelChanged); Keyboard.KeyDown += new EventHandler <KeyboardKeyEventArgs>(KeyboardKeyDown); // ------- Sandbox ------- // Initialise objects to be drawn in the scene. console = OutputWindow.Console; randomNumber = new Random(); scene1 = new Scene(); //cubeArray = new Cube[25]; // Populate the Scene with Cubes at random locations and rotations. for (int i = 0; i < 25; i++) { randomVector = new Vector3(randomNumber.Next(-5, 5), randomNumber.Next(-5, 5), randomNumber.Next(-120, -10)); randomRotation = new Vector3(randomNumber.Next(0, 314) / 100, randomNumber.Next(0, 314) / 100, 0); scene1.AddActor(new Cube(randomVector, randomRotation, new Color4(0.4f, 0.5f, 0.0f, 1.0f))); } // Create references to the manager classes singletons. fbManager = FrameBufferManager.Instance; // Add introduction text console.DisplayHelp(); }
// Constructors static Cube() { sourceFile = "cube.obj"; cubeMesh = Mesh.CreateMesh(sourceFile, name); fbManager = FrameBufferManager.Instance; cubeShader = Shader.CreateShader("cube.vert", "cube.frag", name); selectionShader = Shader.CreateShader("select.vert", "select.frag", "select"); GL.EnableVertexAttribArray(0); GL.BindAttribLocation(cubeShader.ShaderID, 0, "vertex_position"); GL.BindAttribLocation(selectionShader.ShaderID, 0, "vertex_position"); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, Vertex.SizeInBytes, 0); GL.EnableVertexAttribArray(1); GL.BindAttribLocation(cubeShader.ShaderID, 1, "vertex_normal"); GL.BindAttribLocation(selectionShader.ShaderID, 1, "vertex_normal"); GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, Vertex.SizeInBytes, Vector3.SizeInBytes); surfaceColorLocation = GL.GetUniformLocation(cubeShader.ShaderID, "surfaceColor"); selectColorLocation = GL.GetUniformLocation(selectionShader.ShaderID, "surfaceColor"); modelviewMatrixLocation = GL.GetUniformLocation(cubeShader.ShaderID, "modelview_matrix"); selectModelviewMatrixLocation = GL.GetUniformLocation(selectionShader.ShaderID, "modelview_matrix"); }
// Constructors public Scene() { fbManager = FrameBufferManager.Instance; actorList = new List <ISelectable>(); }