void RenderGrid(int gridSize) { GL.Disable(EnableCap.Lighting); GLUtility.DisableTexture2D(); GL.Begin(BeginMode.Lines); for (int z = -gridSize; z <= gridSize; z++) { GL.Color3(Color.White); GL.Vertex3(-gridSize, 0.0f, z); GL.Vertex3(gridSize, 0.0f, z); } for (int x = -gridSize; x <= gridSize; x++) { GL.Color3(Color.White); GL.Vertex3(x, 0.0f, -gridSize); GL.Vertex3(x, 0.0f, gridSize); } GL.End(); GLUtility.EnableTexture2D(); GL.Enable(EnableCap.Lighting); }
void RenderPart(Part part, RenderFlags renderFlags) { GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, shaders[part.ShaderIndex].Tint.ToColor4()); var batch = batches[part.BatchIndex]; if (batch.UseNBT) // Render with bump map. { int binormalAttribute = GL.GetAttribLocation(Program.EmbossProgram, "inBinormal"); int tangentAttribute = GL.GetAttribLocation(Program.EmbossProgram, "inTangent"); int diffuseMap = GL.GetUniformLocation(Program.EmbossProgram, "diffuseMap"); int bumpMap = GL.GetUniformLocation(Program.EmbossProgram, "bumpMap"); int embossFactor = GL.GetUniformLocation(Program.EmbossProgram, "embossScale"); Program.EmbossProgram.Use(); GL.ActiveTexture(TextureUnit.Texture0 + 0); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, glTextures[materials[shaders[part.ShaderIndex].MaterialIndex[0]].textureIndex]); GLUtility.SetTexture2DWrapModeS(materials[shaders[part.ShaderIndex].MaterialIndex[0]].wrapS); GLUtility.SetTexture2DWrapModeT(materials[shaders[part.ShaderIndex].MaterialIndex[0]].wrapT); GL.Uniform1(diffuseMap, 0); GL.ActiveTexture(TextureUnit.Texture0 + 1); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, glTextures[materials[shaders[part.ShaderIndex].MaterialIndex[1]].textureIndex]); GLUtility.SetTexture2DWrapModeS(materials[shaders[part.ShaderIndex].MaterialIndex[1]].wrapS); GLUtility.SetTexture2DWrapModeT(materials[shaders[part.ShaderIndex].MaterialIndex[1]].wrapT); GL.Uniform1(bumpMap, 1); GL.Uniform1(embossFactor, 2.0f); foreach (var primitive in batch) { GL.Begin(primitive.GLType); foreach (var vertex in primitive) { GL.MultiTexCoord2(TextureUnit.Texture0 + 0, ref texCoord0s[vertex.UVIndex[0].Value]); GL.MultiTexCoord2(TextureUnit.Texture0 + 1, ref texCoord1s[vertex.UVIndex[1].Value]); GL.Normal3(normals[vertex.NormalIndex.Value]); GL.VertexAttrib3(tangentAttribute, ref normals[vertex.BinormalIndex.Value + 1]); GL.VertexAttrib3(binormalAttribute, ref normals[vertex.TangentIndex.Value + 2]); GL.Vertex3(positions[vertex.PositionIndex.Value]); } GL.End(); } GL.UseProgram(0); } else // Render without bump map. { for (int texUnit = 0; texUnit < 8; texUnit++) { if (shaders[part.ShaderIndex].MaterialIndex[texUnit] < 0) { continue; } var material = materials[shaders[part.ShaderIndex].MaterialIndex[texUnit]]; GL.ActiveTexture(TextureUnit.Texture0 + texUnit); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, glTextures[material.textureIndex]); GLUtility.SetTexture2DWrapModeS(material.wrapS); GLUtility.SetTexture2DWrapModeT(material.wrapT); } foreach (var primitive in batch) { GL.Begin(primitive.GLType); foreach (var vertex in primitive) { if (vertex.UVIndex[0] != null) { GL.MultiTexCoord2(TextureUnit.Texture0, ref texCoord0s[vertex.UVIndex[0].Value]); } if (vertex.NormalIndex != null) { GL.Normal3(normals[vertex.NormalIndex.Value]); } GL.Vertex3(positions[vertex.PositionIndex.Value]); } GL.End(); } } GLUtility.DisableTexture2D(); // normals if (renderFlags.HasFlag(RenderFlags.NBT)) { const float normalLength = 0.0625f; GL.Disable(EnableCap.Lighting); GL.Begin(BeginMode.Lines); foreach (var primitive in batch) { foreach (var vertex in primitive) { if (vertex.NormalIndex != null) { GL.Color4(Color.Red.ToColor4()); GL.Vertex3(positions[vertex.PositionIndex.Value]); GL.Vertex3(positions[vertex.PositionIndex.Value] + normals[vertex.NormalIndex.Value] * normalLength); } if (vertex.TangentIndex != null) { GL.Color4(Color.Green.ToColor4()); GL.Vertex3(positions[vertex.PositionIndex.Value]); GL.Vertex3(positions[vertex.PositionIndex.Value] + normals[vertex.TangentIndex.Value + 2] * normalLength); } if (vertex.BinormalIndex != null) { GL.Color4(Color.Blue.ToColor4()); GL.Vertex3(positions[vertex.PositionIndex.Value]); GL.Vertex3(positions[vertex.PositionIndex.Value] + normals[vertex.BinormalIndex.Value + 1] * normalLength); } } } GL.End(); GL.Enable(EnableCap.Lighting); } }