/// <summary> /// This function draws all of the objects in the scene (i.e. every quadric /// in the quadrics arraylist etc). /// </summary> public virtual void Draw() { // Create a performance monitor. PerformanceMonitor performance = new PerformanceMonitor(); performance.Monitor("Clearing buffers"); // Set the clear color. float[] clear = clearColour; gl.ClearColor(clear[0], clear[1], clear[2], clear[3]); // TODO: this is big overhead- one should only reproject when the camera moves. if (currentCamera != null) { currentCamera.Project(gl); } // Clear. gl.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT | OpenGL.STENCIL_BUFFER_BIT); gl.BindTexture(OpenGL.TEXTURE_2D, 0); gl.Enable(OpenGL.TEXTURE_2D); gl.Enable(OpenGL.LIGHTING); if (designMode) { performance.Monitor("Drawing Stock Scene"); gl.StockDrawing.DrawGrid(gl); } performance.Monitor("Setting and drawing Lights"); foreach (Light light in lights) { // Set the lights properties into our OpenGL. light.Set(gl); // Draw the light into OpenGL. if (designMode) { light.Draw(gl); } } performance.Monitor("Drawing Custom Objects"); // TODO: Adding this code here re-enables textures- it should work without it but it // doesn't, look into this. foreach (SceneObject ob in sceneObjects) { ob.Draw(gl); } performance.Monitor("Drawing Quadrics"); // TODO: Adding this code here re-enables textures- it should work without it but it // doesn't, look into this. foreach (Quadric quad in quadrics) { quad.Draw(gl); } performance.Monitor("Drawing Evaluators"); // TODO: Adding this code here re-enables textures- it should work without it but it // doesn't, look into this. foreach (Evaluator evaluator in evaluators) { evaluator.Draw(gl); } performance.Monitor("Drawing Cameras"); foreach (Camera cam in cameras) { if (designMode) { cam.Draw(gl); } } performance.Monitor("Drawing Polygons"); // TODO: Adding this code here re-enables textures- it should work without it but it // doesn't, look into this. gl.BindTexture(OpenGL.TEXTURE_2D, 0); gl.Enable(OpenGL.TEXTURE_2D); foreach (Polygon poly in polygons) { // Draw the polygon into OpenGL. poly.Draw(gl); if (poly.CastsShadow) { poly.CastShadow(gl, lights); } } gl.Flush(); performance.EndMonitor(); if (drawPerformance) { performance.Draw(gl.GDIGraphics); } }