public void ApplyStdMaterial(StdMaterial mat) { OpenGL.glBindVertexArray(vertex_array); MakeCurrent(); this.mat = mat; for (int i = 0; i < elements.Count; i++) { ElementType t = (ElementType)(((int)desc.types[i] & 0xf) | ((int)desc.types[i] & 0x0f000000)); switch (t) { case ElementType.Position: elements[i].attribute = (uint)mat.PositionAttribute; break; case ElementType.Normals: elements[i].attribute = (uint)mat.NormalAttribute; break; case ElementType.TexCoord: elements[i].attribute = (uint)mat.TexCoord0Attribute; break; case ElementType.TexCoord | (ElementType)0x01000000: elements[i].attribute = (uint)mat.TexCoord1Attribute; break; case ElementType.TexCoord | (ElementType)0x02000000: elements[i].attribute = (uint)mat.TexCoord2Attribute; break; case ElementType.TexCoord | (ElementType)0x03000000: elements[i].attribute = (uint)mat.TexCoord3Attribute; break; case ElementType.Color: elements[i].attribute = (uint)mat.Color0Attribute; break; case ElementType.Color | (ElementType)0x01000000: elements[i].attribute = (uint)mat.Color1Attribute; break; case ElementType.Color | (ElementType)0x02000000: elements[i].attribute = (uint)mat.Color2Attribute; break; case ElementType.Color | (ElementType)0x03000000: elements[i].attribute = (uint)mat.Color3Attribute; break; } } AssignPointers(); }
public void InitializeGraphics() { if (vb != null) { vb.Dispose(); } if (mat == null) { Glorg2.Resource.MaterialImporter imp = new Glorg2.Resource.MaterialImporter(); using (var stream = System.IO.File.OpenRead(".\\shaders\\Grid.mxl")) { mat = imp.Import <StdMaterial>(stream, "grid", null); } } vb = new VertexBuffer <WireframeVertex>(WireframeVertex.Description); vb.Allocate(Columns * 2 + Rows * 2 + 4); float tot_w = Size * Columns; float tot_h = Size * Rows; float fi = -tot_w / 2; int i; for (i = 0; i <= Columns; i++, fi += Size) { Vector4 color; if (Major == 0 || (i % Major) == 0) { color = MajorColor; } else { color = MinorColor; } vb[i * 2] = new WireframeVertex() { Position = new Vector3(fi, 0, -tot_h / 2), Color = color }; vb[i * 2 + 1] = new WireframeVertex() { Position = new Vector3(fi, 0, tot_h / 2), Color = color }; } int start = i * 2; fi = -tot_h / 2; for (int j = 0; j <= Rows; j++, fi += Size) { Vector4 color; if (Major == 0 || (j % Major) == 0) { color = MajorColor; } else { color = MinorColor; } vb[start + j * 2] = new WireframeVertex() { Position = new Vector3(-tot_h / 2, 0, fi), Color = color }; vb[start + j * 2 + 1] = new WireframeVertex() { Position = new Vector3(tot_h / 2, 0, fi), Color = color }; } vb.BufferData(VboUsage.GL_STATIC_DRAW); vb.FreeClientData(); }