public override string ToString() { var builder = new System.Text.StringBuilder(); var cols = new vec2[] { col0, col1}; for (int i = 0; i < cols.Length; i++) { builder.Append(cols[i]); builder.Append(" + "); } return builder.ToString(); }
private void InitVAO() { this.mode = DrawMode.Quads; this.vertexCount = 4; // Create a vertex buffer for the vertex data. UnmanagedArray<vec3> in_Position = new UnmanagedArray<vec3>(this.vertexCount); UnmanagedArray<vec2> in_TexCoord = new UnmanagedArray<vec2>(this.vertexCount); Bitmap bigBitmap = this.ttfTexture.BigBitmap; float factor = (float)this.ttfTexture.BigBitmap.Width / (float)this.ttfTexture.BigBitmap.Height; float x1 = -factor; float x2 = factor; float y1 = -1; float y2 = 1; in_Position[0] = new vec3(x1, y1, 0); in_Position[1] = new vec3(x2, y1, 0); in_Position[2] = new vec3(x2, y2, 0); in_Position[3] = new vec3(x1, y2, 0); in_TexCoord[0] = new vec2(0, 0); in_TexCoord[1] = new vec2(1, 0); in_TexCoord[2] = new vec2(1, 1); in_TexCoord[3] = new vec2(0, 1); if (vao[0] != 0) { GL.DeleteBuffers(1, vao); } if (vbo[0] != 0) { GL.DeleteBuffers(vbo.Length, vbo); } GL.GenVertexArrays(1, vao); GL.BindVertexArray(vao[0]); GL.GenBuffers(2, vbo); uint in_PositionLocation = shaderProgram.GetAttributeLocation(strin_Position); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo[0]); GL.BufferData(BufferTarget.ArrayBuffer, in_Position, BufferUsage.StaticDraw); GL.VertexAttribPointer(in_PositionLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero); GL.EnableVertexAttribArray(in_PositionLocation); uint in_TexCoordLocation = shaderProgram.GetAttributeLocation(strin_TexCoord); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo[1]); GL.BufferData(BufferTarget.ArrayBuffer, in_TexCoord, BufferUsage.StaticDraw); GL.VertexAttribPointer(in_TexCoordLocation, 2, GL.GL_FLOAT, false, 0, IntPtr.Zero); GL.EnableVertexAttribArray(in_TexCoordLocation); GL.BindVertexArray(0); in_Position.Dispose(); in_TexCoord.Dispose(); }
protected override void DoInitialize() { base_prog = GL.CreateProgram(); ShaderHelper.vglAttachShaderSource(base_prog, ShaderType.VertexShader, quad_shader_vs); ShaderHelper.vglAttachShaderSource(base_prog, ShaderType.FragmentShader, quad_shader_fs); GL.GenBuffers(1, quad_vbo); GL.BindBuffer(BufferTarget.ArrayBuffer, quad_vbo[0]); var quad_data = new UnmanagedArray<vec2>(8); quad_data[0] = new vec2(1.0f, -1.0f); quad_data[1] = new vec2(-1.0f, -1.0f); quad_data[2] = new vec2(-1.0f, 1.0f); quad_data[3] = new vec2(1.0f, 1.0f); quad_data[4] = new vec2(0.0f, 0.0f); quad_data[5] = new vec2(1.0f, 0.0f); quad_data[6] = new vec2(1.0f, 1.0f); quad_data[7] = new vec2(0.0f, 1.0f); GL.BufferData(BufferTarget.ArrayBuffer, quad_data, BufferUsage.StaticDraw); GL.GenVertexArrays(1, vao); GL.BindVertexArray(vao[0]); GL.VertexAttribPointer(0, 2, GL.GL_FLOAT, false, 0, IntPtr.Zero); GL.VertexAttribPointer(1, 2, GL.GL_FLOAT, false, 0, new IntPtr(8 * sizeof(float))); GL.EnableVertexAttribArray(0); GL.EnableVertexAttribArray(1); GL.LinkProgram(base_prog); StringBuilder buf = new StringBuilder(1024); GL.GetProgramInfoLog(base_prog, 1024, IntPtr.Zero, buf); vglImageData image = new vglImageData(); tex = vgl.vglLoadTexture(@"media\test.dds", 0, ref image); GL.TexParameteri(image.target, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR_MIPMAP_LINEAR); vgl.vglUnloadImage(ref image); }
public vec2(vec2 v) { this.x = v.x; this.y = v.y; }
private void InitVAO(string value) { if (value == null) { value = string.Empty; } this.mode = DrawMode.Quads; this.vertexCount = 4 * value.Length; // Create a vertex buffer for the vertex data. UnmanagedArray<vec3> in_Position = new UnmanagedArray<vec3>(this.vertexCount); UnmanagedArray<vec2> in_TexCoord = new UnmanagedArray<vec2>(this.vertexCount); Bitmap bigBitmap = this.ttfTexture.BigBitmap; // step 1: set width for each glyph vec3[] tmpPositions = new vec3[this.vertexCount]; float totalLength = 0; for (int i = 0; i < value.Length; i++) { char c = value[i]; CharacterInfo cInfo; if (this.ttfTexture.CharInfoDict.TryGetValue(c, out cInfo)) { float glyphWidth = (float)cInfo.width / (float)this.ttfTexture.FontHeight; if (i == 0) { tmpPositions[i * 4 + 0] = new vec3(0, 0, 0); tmpPositions[i * 4 + 1] = new vec3(glyphWidth, 0, 0); tmpPositions[i * 4 + 2] = new vec3(glyphWidth, 1, 0); tmpPositions[i * 4 + 3] = new vec3(0, 1, 0); } else { tmpPositions[i * 4 + 0] = tmpPositions[i * 4 + 0 - 4 + 1]; tmpPositions[i * 4 + 1] = tmpPositions[i * 4 + 0] + new vec3(glyphWidth, 0, 0); tmpPositions[i * 4 + 3] = tmpPositions[i * 4 + 3 - 4 - 1]; tmpPositions[i * 4 + 2] = tmpPositions[i * 4 + 3] + new vec3(glyphWidth, 0, 0); } totalLength += glyphWidth; } //else //{ throw new Exception(string.Format("Not support for display the char [{0}]", c)); } } for (int i = 0; i < value.Length; i++) { char c = value[i]; CharacterInfo cInfo; float x1 = 0; float x2 = 1; float y1 = 0; float y2 = 1; if (this.ttfTexture.CharInfoDict.TryGetValue(c, out cInfo)) { x1 = (float)cInfo.xoffset / (float)bigBitmap.Width; x2 = (float)(cInfo.xoffset + cInfo.width) / (float)bigBitmap.Width; y1 = (float)cInfo.yoffset / (float)bigBitmap.Height; y2 = (float)(cInfo.yoffset + this.ttfTexture.FontHeight) / (float)bigBitmap.Height; } //else //{ throw new Exception(string.Format("Not support for display the char [{0}]", c)); } in_Position[i * 4 + 0] = tmpPositions[i * 4 + 0] - new vec3(totalLength / 2, 0, 0); in_Position[i * 4 + 1] = tmpPositions[i * 4 + 1] - new vec3(totalLength / 2, 0, 0); in_Position[i * 4 + 2] = tmpPositions[i * 4 + 2] - new vec3(totalLength / 2, 0, 0); in_Position[i * 4 + 3] = tmpPositions[i * 4 + 3] - new vec3(totalLength / 2, 0, 0); //in_TexCoord[i * 4 + 0] = new vec2(x1, y1); //in_TexCoord[i * 4 + 1] = new vec2(x2, y1); //in_TexCoord[i * 4 + 2] = new vec2(x2, y2); //in_TexCoord[i * 4 + 3] = new vec2(x1, y2); in_TexCoord[i * 4 + 0] = new vec2(x1, y2); in_TexCoord[i * 4 + 1] = new vec2(x2, y2); in_TexCoord[i * 4 + 2] = new vec2(x2, y1); in_TexCoord[i * 4 + 3] = new vec2(x1, y1); } if (vao[0] != 0) { GL.DeleteBuffers(1, vao); } if (vbo[0] != 0) { GL.DeleteBuffers(vbo.Length, vbo); } GL.GenVertexArrays(1, vao); GL.BindVertexArray(vao[0]); GL.GenBuffers(2, vbo); uint in_PositionLocation = shaderProgram.GetAttributeLocation(strin_Position); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo[0]); GL.BufferData(BufferTarget.ArrayBuffer, in_Position, BufferUsage.StaticDraw); GL.VertexAttribPointer(in_PositionLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero); GL.EnableVertexAttribArray(in_PositionLocation); uint in_TexCoordLocation = shaderProgram.GetAttributeLocation(strin_TexCoord); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo[1]); GL.BufferData(BufferTarget.ArrayBuffer, in_TexCoord, BufferUsage.StaticDraw); GL.VertexAttribPointer(in_TexCoordLocation, 2, GL.GL_FLOAT, false, 0, IntPtr.Zero); GL.EnableVertexAttribArray(in_TexCoordLocation); GL.BindVertexArray(0); in_Position.Dispose(); in_TexCoord.Dispose(); }
public mat2(vec2 a, vec2 b) { this.col0 = a; this.col1 = b; }
/// <summary> /// Initializes a new instance of the <see cref="mat2"/> struct. /// The matrix is initialised with the <paramref name="cols"/>. /// </summary> /// <param name="cols">The colums of the matrix.</param> public mat2(vec2[] cols) { this.col0 = cols[0]; this.col1 = cols[1]; }
public vec3(vec2 xy, float z) { this.x = xy.x; this.y = xy.y; this.z = z; }
public static vec2 ToVec2(this float[] array, int startIndex = 0) { vec2 result = new vec2(array[startIndex], array[startIndex + 1]); return result; }
public mat2(vec2 col0, vec2 col1) { this.col0 = col0; this.col1 = col1; }
/// <summary> /// Define a picking region. /// </summary> /// <param name="center">The center.</param> /// <param name="delta">The delta.</param> /// <param name="viewport">The viewport.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException"></exception> public static mat4 pickMatrix(vec2 center, vec2 delta, vec4 viewport) { if (delta.x <= 0 || delta.y <= 0) throw new ArgumentOutOfRangeException(); var Result = new mat4(1.0f); if (!(delta.x > (0f) && delta.y > (0f))) return Result; // Error vec3 Temp = new vec3( ((viewport[2]) - (2f) * (center.x - (viewport[0]))) / delta.x, ((viewport[3]) - (2f) * (center.y - (viewport[1]))) / delta.y, (0f)); // Translate and scale the picked region to the entire window Result = translate(Result, Temp); return scale(Result, new vec3((viewport[2]) / delta.x, (viewport[3]) / delta.y, (1))); }
public float dot(vec2 rhs) { var result = this.x * rhs.x + this.y * rhs.y; return result; }
private static void LoadModels(string filename, ObjFile file) { using (var sr = new StreamReader(filename)) { var model = new ObjModel(); while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] parts = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (parts[0] == ("v")) { if (model.innerFaceList.Count > 0) { file.models.Add(model); model = new ObjModel(); } vec3 position = new vec3(float.Parse(parts[1]), float.Parse(parts[2]), float.Parse(parts[3])); model.positionList.Add(position); } else if (parts[0] == ("vt")) { vec2 uv = new vec2(float.Parse(parts[1]), float.Parse(parts[2])); model.uvList.Add(uv); } else if (parts[0] == ("vn")) { vec3 normal = new vec3(float.Parse(parts[1]), float.Parse(parts[2]), float.Parse(parts[3])); model.normalList.Add(normal); } else if (parts[0] == ("f")) { Triangle triangle = ParseFace(parts); model.innerFaceList.Add(triangle); } } file.models.Add(model); } }
public float dot(vec2 rhs) { var result = this.x * rhs.x + this.y * rhs.y; return(result); }