public void Render(PolygonModes mode) { foreach (ThreeDSMesh4LegacyOpenGL mesh in Entities) { mesh.Render(this, mode); } }
private void openGLControl1_KeyDown(object sender, KeyEventArgs e) { var zoomSpeed = 0.5f; var horizontalMoveSpeed = 0.2f; var verticalMoveSpeed = 0.2f; if (e.KeyCode == Keys.Q) { zoom *= (1 + zoomSpeed); if (zoom < 1e-10) { MessageBox.Show("Scale too small."); zoom = 0.00001f; } } else if (e.KeyCode == Keys.E) { zoom *= (1 - 0.5f); } else if (e.KeyCode == Keys.A) { horizontal += horizontalMoveSpeed; } else if (e.KeyCode == Keys.D) { horizontal -= horizontalMoveSpeed; } else if (e.KeyCode == Keys.W) { vertical += verticalMoveSpeed; } else if (e.KeyCode == Keys.S) { vertical -= verticalMoveSpeed; } else if (e.KeyCode == Keys.M) { switch (this.polygonMode) { case PolygonModes.Points: this.polygonMode = PolygonModes.Lines; break; case PolygonModes.Lines: this.polygonMode = PolygonModes.Filled; break; case PolygonModes.Filled: this.polygonMode = PolygonModes.Points; break; default: break; } } this.UpdateInfo(); }
public void Render(ThreeDSModel4LegacyOpenGL model, PolygonModes mode) { if (TriangleIndexes == null) { return; } GL.PolygonMode(PolygonModeFaces.FrontAndBack, mode); // Draw every triangle in the entity foreach (var item in this.usingMaterialIndexesList) { var material = model.MaterialDict[item.Item1]; GL.Materialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, material.Ambient); GL.Materialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, material.Diffuse); GL.Materialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, material.Specular); GL.Materialf(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, material.Shininess); Texture2D[] textures = new Texture2D[] { material.GetTexture(), material.GetBumpTexture(), material.GetReflectionTexture(), }; bool drawn = false; foreach (var texture in textures) { if (!(drawn && texture == null)) // 如果没有贴图,就只画一次。 { if (texture != null) { GL.Enable(GL.GL_TEXTURE_2D); texture.Bind(); } DrawTriangles(item, texture); if (texture != null) { texture.Unbind(); GL.Disable(GL.GL_TEXTURE_2D); } } drawn = true; } } //Console.WriteLine ( GL.GetError () ); }
/// <summary> /// This sets the current drawing mode of polygons (points, lines, filled). /// </summary> /// <param name="face">The faces this applies to (front, back or both).</param> /// <param name="mode">The mode to set to (points, lines, or filled).</param> public static void PolygonMode(PolygonModeFaces face, PolygonModes mode) { GL.PolygonMode((uint)face, (uint)mode); }
public PolygonModeSwitch(PolygonModes mode) { this.Mode = mode; }
public void Render(ThreeDSModel4LegacyOpenGL model, PolygonModes mode) { if (TriangleIndexes == null) return; GL.PolygonMode(PolygonModeFaces.FrontAndBack, mode); // Draw every triangle in the entity foreach (var item in this.usingMaterialIndexesList) { var material = model.MaterialDict[item.Item1]; GL.Materialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, material.Ambient); GL.Materialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, material.Diffuse); GL.Materialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, material.Specular); GL.Materialf(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, material.Shininess); Texture2D[] textures = new Texture2D[] { material.GetTexture(), material.GetBumpTexture(), material.GetReflectionTexture(), }; bool drawn = false; foreach (var texture in textures) { if (!(drawn && texture == null)) // 如果没有贴图,就只画一次。 { if (texture != null) { GL.Enable(GL.GL_TEXTURE_2D); texture.Bind(); } DrawTriangles(item, texture); if (texture != null) { texture.Unbind(); GL.Disable(GL.GL_TEXTURE_2D); } } drawn = true; } } if (this.usingMaterialIndexesList.Count == 0) { GL.Begin(GL.GL_TRIANGLES); foreach (var tri in this.TriangleIndexes) { // Vertex 1 if (normalized) { var normal = this.normals[tri.vertex1]; GL.Normal3d(normal.X, normal.Y, normal.Z); } { var vertex = this.Vertexes[tri.vertex1]; GL.Vertex3d(vertex.X, vertex.Y, vertex.Z); } // Vertex 2 if (normalized) { var normal = this.normals[tri.vertex2]; GL.Normal3d(normal.X, normal.Y, normal.Z); } { var vertex = this.Vertexes[tri.vertex2]; GL.Vertex3d(vertex.X, vertex.Y, vertex.Z); } // Vertex 3 if (normalized) { var normal = this.normals[tri.vertex3]; GL.Normal3d(normal.X, normal.Y, normal.Z); } { var vertex = this.Vertexes[tri.vertex3]; GL.Vertex3d(vertex.X, vertex.Y, vertex.Z); } } GL.End(); } //Console.WriteLine ( GL.GetError () ); }