/// <summary> /// This is the main function of the class, it'll create a triangulated polygon /// from and SceneObject. /// </summary> /// <param name="gl">The gl.</param> /// <param name="sourceObject">The object to convert.</param> /// <param name="guarenteedView">A camera that can see the whole object.</param> /// <returns> /// A polygon created from 'sourceObject'. /// </returns> public Polygon CreatePolygon(OpenGL gl, IRenderable sourceObject, Camera guarenteedView) { // Save the current camera data. gl.MatrixMode(OpenGL.GL_PROJECTION); gl.PushMatrix(); // Look through the camera that can see the object. guarenteedView.Project(gl); // Start triangulation. Begin(gl); // Draw the object. sourceObject.Render(gl, RenderMode.Design); // End triangulation. End(gl); Polygon newPoly = Triangle; newPoly.Name = (sourceObject is SceneElement ? ((SceneElement)sourceObject).Name : "Object") + " (Triangulated Poly)"; return newPoly; }
/// <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(Camera camera = null) { // TODO: we must decide what to do about drawing - are // cameras completely outside of the responsibility of the scene? // If no camera has been provided, use the current one. if (camera == null) camera = currentCamera; // Set the clear color. float[] clear = clearColour; gl.ClearColor(clear[0], clear[1], clear[2], clear[3]); // Reproject. if (camera != null) camera.Project(gl); // Clear. gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT); //gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0); // Render the root element, this will then render the whole // of the scene tree. RenderElement(sceneContainer, RenderMode.Design); // TODO: Adding this code here re-enables textures- it should work without it but it // doesn't, look into this. //gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0); //gl.Enable(OpenGL.GL_TEXTURE_2D); gl.Flush(); }