/// <summary> /// /// </summary> /// <param name="ctx"></param> public ViewportState(GraphicsContext ctx) { int[] viewportCoords = new int[4]; // Get current viewport Gl.Get(Gl.VIEWPORT, viewportCoords); ViewportSize = new Vertex2f(viewportCoords[2] - viewportCoords[0], viewportCoords[3] - viewportCoords[1]); }
public void Uniform2f() { if (!HasVersion(Gl.Version_200) && !HasVersion(Gl.Version_200_ES) && !HasExtension("GL_ARB_shader_objects")) { Assert.Inconclusive("required features not implemented"); } using (Device device = new Device()) using (new GLContext(device)) { uint program = CreateProgramUniform2f(); try { Vertex2f uniformStruct; float[] uniformValue; int uniformLoc = Gl.GetUniformLocation(program, "uVec"); if (uniformLoc < 0) { throw new InvalidOperationException("no uniform variable"); } // glGetUniformfv uniformValue = Array2(1.0f); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array2(0.0f), uniformValue); // glGetUniformfv uniformStruct = new Vertex2f(1.0f); Gl.GetUniformf(program, uniformLoc, out uniformStruct); Assert.AreEqual(Vertex2f.Zero, uniformStruct); // glUniform2f uniformValue = Array2(0.0f); Gl.Uniform2(uniformLoc, Array2(1.0f)); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array2(1.0f), uniformValue); // glUniform2fv uniformValue = Array2(0.0f); Gl.Uniform2(uniformLoc, Array2(9.0f)); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array2(9.0f), uniformValue); // glUniform2fv uniformValue = Array2(0.0f); uniformStruct = new Vertex2f(5.0f); Gl.Uniform2f(uniformLoc, 1, uniformStruct); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array2(5.0f), uniformValue); } finally { Gl.DeleteProgram(program); } } }
/// <summary> /// Apply this depth test render state. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> which has defined the shader program <paramref name="shaderProgram"/>. /// </param> /// <param name="shaderProgram"> /// The <see cref="ShaderProgram"/> which has the state set. /// </param> public override void ApplyState(GraphicsContext ctx, ShaderProgram shaderProgram) { int[] viewportCoords = new int[4]; // Get current viewport Gl.Get(GetPName.Viewport, viewportCoords); ViewportSize = new Vertex2f(viewportCoords[2] - viewportCoords[0], viewportCoords[3] - viewportCoords[1]); // Base implementation base.ApplyState(ctx, shaderProgram); }
private void GenerateTangentsTriangle4f(IVertexArray positionArray, IVertexArray normalArray, IVertexArray texArray, IVertexArray tanArray, IVertexArray bitanArray) { uint count = (ElementCount != 0 ? ElementCount : _VertexArrayObject.ArrayLength) / 3; for (uint i = 0, v = ElementOffset; i < count; i++, v += 3) { Vertex3f v0 = (Vertex3f)positionArray.GetElement <Vertex4f>(v); Vertex3f v1 = (Vertex3f)positionArray.GetElement <Vertex4f>(v + 1); Vertex3f v2 = (Vertex3f)positionArray.GetElement <Vertex4f>(v + 2); Vertex2f t0 = texArray.GetElement <Vertex2f>(v); Vertex2f t1 = texArray.GetElement <Vertex2f>(v + 1); Vertex2f t2 = texArray.GetElement <Vertex2f>(v + 2); Vertex3f dv1 = v1 - v0, dv2 = v2 - v0; Vertex2f dt1 = t1 - t0, dt2 = t2 - t0; float w = 1.0f / (dt1.x * dt2.y - dt1.y * dt2.x); Vertex3f tgVector, btVector; if (Single.IsInfinity(w) == false) { tgVector = (dv1 * dt2.y - dv2 * dt1.y) * w; tgVector.Normalize(); btVector = (dv2 * dt1.x - dv1 * dt2.x) * w; btVector.Normalize(); Vertex3f n = normalArray.GetElement <Vertex3f>(v).Normalized; n.Normalize(); if (((n ^ tgVector) * btVector) < 0.0f) { tgVector = tgVector * -1.0f; } } else { // Degenerate triangles does not contribute tgVector = btVector = Vertex3f.Zero; } tanArray.SetElement <Vertex3f>(tgVector, v); tanArray.SetElement <Vertex3f>(tgVector, v + 1); tanArray.SetElement <Vertex3f>(tgVector, v + 2); bitanArray.SetElement <Vertex3f>(btVector, v); bitanArray.SetElement <Vertex3f>(btVector, v + 1); bitanArray.SetElement <Vertex3f>(btVector, v + 2); } }
/// <summary> /// Set uniform state variable (vec2 variable). /// </summary> /// <param name="uniformName"> /// A <see cref="String"/> that specify the variable name in the shader source. /// </param> /// <param name="v"> /// A <see cref="Vertex2f"/> holding the uniform variabile data. /// </param> public void SetUniform(string uniformName, Vertex2f v) { UniformSegment uniform = GetUniform(uniformName); if (uniform == null) { return; } uniform.CheckType(Gl.FLOAT_VEC2, Gl.BOOL_VEC2); Set(v, (ulong)uniform.Offset); }
/// <summary> /// Convert a <see cref="Single[]"/> to <see cref="Vertex2f[]"/>. /// </summary> /// <param name="array"> /// The <see cref="Single[]"/> to be converted. /// </param> /// <returns> /// It returns the <see cref="Vertex2f[]"/> equivalent to <paramref name="array"/>. /// </returns> public static Vertex2f[] ToVertex2f(this float[] array) { int structArrayLength = array.Length / 2; Vertex2f[] structArray = new Vertex2f[structArrayLength]; for (int i = 0, j = 0; i < structArrayLength; i++, j += 2) { structArray[i] = new Vertex2f(array[j + 0], array[j + 1]); } return(structArray); }
public void TestUniform2f() { if (!HasVersion(2, 0) && !HasEsVersion(2, 0) && !IsGlExtensionSupported("GL_ARB_shader_objects")) { Assert.Inconclusive("required features not implemented"); } uint program = CreateProgramUniform2f(); try { Vertex2f uniformStruct; float[] uniformValue; int uniformLoc = Gl.GetUniformLocation(program, "uVec"); if (uniformLoc < 0) { throw new InvalidOperationException("no uniform variable"); } // glGetUniformfv uniformValue = Array2(1.0f); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array2(0.0f), uniformValue); // glGetUniformfv (ref) uniformStruct = new Vertex2f(1.0f); Gl.GetUniformf(program, uniformLoc, ref uniformStruct); Assert.AreEqual(Vertex2f.Zero, uniformStruct); // glUniform2f uniformValue = Array2(0.0f); Gl.Uniform2(uniformLoc, Array2(1.0f)); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array2(1.0f), uniformValue); // glUniform2fv uniformValue = Array2(0.0f); Gl.Uniform2(uniformLoc, Array2(9.0f)); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array2(9.0f), uniformValue); // glUniform2fv (ref) uniformValue = Array2(0.0f); uniformStruct = new Vertex2f(5.0f); Gl.Uniform2f(uniformLoc, 1, ref uniformStruct); Gl.GetUniform(program, uniformLoc, uniformValue); CollectionAssert.AreEqual(Array2(5.0f), uniformValue); } finally { Gl.DeleteProgram(program); } }
private static void processVertex(ref string[] vertexData, ref List <uint> indices, ref List <Vertex2f> textures, ref List <Vertex3f> normals, ref float[] textureArray, ref float[] normalsArray) { uint currentVertexPointer = uint.Parse(vertexData[0]) - 1; indices.Add(currentVertexPointer); Vertex2f currentTex = textures[int.Parse(vertexData[1]) - 1]; textureArray[currentVertexPointer * 2] = currentTex.x; textureArray[currentVertexPointer * 2 + 1] = 1 - currentTex.y; Vertex3f currentNorm = normals[int.Parse(vertexData[2]) - 1]; normalsArray[currentVertexPointer * 3] = currentNorm.x; normalsArray[currentVertexPointer * 3 + 1] = currentNorm.y; normalsArray[currentVertexPointer * 3 + 2] = currentNorm.z; }
/// <summary> /// Merge this state with another one. /// </summary> /// <param name="state"> /// A <see cref="IGraphicsState"/> having the same <see cref="GraphicsState.StateIdentifier"/> of this state. /// </param> /// <remarks> /// <para> /// After a call to this routine, this IGraphicsState store the union of the previous information /// and of the information of <paramref name="state"/>. /// </para> /// <para> /// The semantic of the merge result is dependent on the actual implementation of this IGraphicsState. Normally /// the merge method will copy <paramref name="state"/> into this IGraphicsState, but other state could do /// different operations. /// </para> /// </remarks> public override void Merge(IGraphicsState state) { if (state == null) { throw new ArgumentNullException("state"); } if (state.StateIdentifier != StateId) { throw new ArgumentException("state id mismatch", "state"); } ViewportState previousState = (ViewportState)state; ViewportSize = previousState.ViewportSize; }
/// <summary> /// Get a list of <see cref="GlyphModelType"/> for a specific string and model-view-projection matrix. /// </summary> /// <param name="modelview"></param> /// <param name="s"></param> /// <returns></returns> private List <GlyphModelType> GetGlyphsInstances(Matrix4x4 modelview, string s) { ModelMatrix charModel = new ModelMatrix(modelview); List <GlyphModelType> glyphsInstances = new List <GlyphModelType>(); char[] fontChars = s.ToCharArray(); for (int i = 0; i < fontChars.Length; i++) { Glyph glyph; if (_GlyphMetadata.TryGetValue(fontChars[i], out glyph) == false) { continue; } // Set instance information Matrix4x4f modelViewProjection = new Matrix4x4f( new Vertex4f(charModel.GetColumn(0)), new Vertex4f(charModel.GetColumn(1)), new Vertex4f(charModel.GetColumn(2)), new Vertex4f(charModel.GetColumn(3)) ); Vertex3f glyphVertexParams = new Vertex3f( glyph.GlyphSize.Width, glyph.GlyphSize.Height, glyph.Layer ); Vertex2f glyphTexParams = new Vertex2f( glyph.TexScale.Width, glyph.TexScale.Height ); GlyphModelType glyphModel = new GlyphModelType(); glyphModel.ModelViewProjection = modelViewProjection; glyphModel.VertexParams = glyphVertexParams; glyphModel.TexParams = glyphTexParams; glyphsInstances.Add(glyphModel); // Move next charModel.Translate(glyph.GlyphSize.Width, 0.0f); } return(glyphsInstances); }
private void Loop() { //if (FrameTracker.frameCount % 1000 == 0 && FrameTracker.frameCount != 0) //{ // StaticLogger.Logger.Debug("Regenerating."); // RegenerateGlControl(); //} if (this.configuration.WorkflowMode == UrielWorkflowMode.EditorMode) { CreateNewShaderAndSelect(); this.CurrentShader = LoadNewShaderFromSelection(this.CurrentShader); } this.FrameTracker.StartFrame(); double time = (DateTime.UtcNow - StartTime).TotalSeconds; if (this.CurrentShader.CreationArguments.Type.Uniforms.Contains(KnownFragmentShaderUniform.CursorPosition) || this.CurrentShader.CreationArguments.Type.Uniforms.Contains(KnownFragmentShaderUniform.CursorMovement)) { UpdateKeys(); } Vertex2f resolution = new Vertex2f(this.Size.Width, this.Size.Height); UniformValues uniforms = new UniformValues() { Resolution = resolution, Time = time, CursorMovement = this.tks.Movement, CursorPosition = this.tks.Position }; renderLoop.Render(this.CurrentShader, uniforms, this.RenderControl.Size); this.FrameTracker.EndFrame(); if (this.configuration.WorkflowMode == UrielWorkflowMode.EditorMode) { StatusStrip_Update(time); } }
/* * v: vertex * vt: UV texture Coordinates * vn: Normal vector * f: 연관이 있는 v, vt, vn에 대한 index 조합 * (f position/texture-coordinates/normal position/texture-coordinates/normal position/texture-coordinates/normal) */ static void ProcessVertex(string[] vertexData , List <int> indexList , List <Vertex2f> uvList , List <Vertex3f> normalList , float[] uvArray , float[] normalArray) { int i = int.Parse(vertexData[0]) - 1; //position indexList.Add(i); Vertex2f uv = uvList[int.Parse(vertexData[1]) - 1]; //texture-coordinates uvArray[i * 2] = uv.x; uvArray[i * 2 + 1] = 1 - uv.y; Vertex3f normal = normalList[int.Parse(vertexData[2]) - 1]; //normal normalArray[i * 3] = normal.x; normalArray[i * 3 + 1] = normal.y; normalArray[i * 3 + 2] = normal.z; }
void IShaderUniformContainer.SetUniform(GraphicsContext ctx, string uniformName, Vertex2f v) { SetUniform(uniformName, v); }
public void LoadAtlasInfo(int numberOfRows, Vertex2f offset) { base.LoadInt(this.location_numberOfRows, numberOfRows); base.LoadVector2(this.location_offset, offset); }
private void DrawLines2f_GL_1_0(Vertex2f[] vertices) { if ((vertices.Length % 2) != 0) throw new ArgumentException("length not a multiple of 2", "vertices"); Gl.Begin(PrimitiveType.Lines); for (int i = 0; i < vertices.Length; i += 2) { Vertex2f v1 = vertices[i], v2 = vertices[i + 1]; Gl.Vertex2(v1.x, v1.y); Gl.Vertex2(v2.x, v2.y); } Gl.End(); }
protected TexGenBase(float xRepeat, float yRepeat) { Repeat = new Vertex2f(xRepeat, yRepeat); }
/// <summary> /// Construct a FontFxShadow specifying the shadow color and offset. /// </summary> /// <param name="color"> /// The <see cref="ColorRGBAF"/> that specifies the shadow color. /// </param> /// <param name="offset"> /// The <see cref="Vertex2f"/> that specifies the shadow offset. /// </param> public FontFxShadow(ColorRGBAF color, Vertex2f offset) { Color = color; Offset = offset; }
/// <summary> /// Accumulate a scaling to this model matrix. /// </summary> /// <param name="s"> /// A <see cref="Vertex2f"/> holding the scaling factors on three dimensions. /// </param> public void Scale(Vertex2f s) { ModelMatrix scaleModel = new ModelMatrix(); scaleModel.SetScale(s.x, s.y); Set(this * scaleModel); }
protected void LoadVector2(int location, Vertex2f value) { Gl.Uniform2f(location, 1, value); }
private void DrawLines2f_GL_1_1(Vertex2f[] vertices) { if ((vertices.Length % 2) != 0) throw new ArgumentException("length not a multiple of 2", "vertices"); using (MemoryLock memoryLock = new MemoryLock(vertices)) { // Setup arrays Gl.VertexPointer(2, VertexPointerType.Float, 0, memoryLock.Address); Gl.EnableClientState(EnableCap.VertexArray); // Draw arrays Gl.DrawArrays(PrimitiveType.Lines, 0, vertices.Length); } }
public static RawModel loadObjModel(String filename, Loader loader) { StreamReader fr = null; try { fr = new StreamReader(File.OpenRead("..\\..\\res/" + filename + ".obj")); }catch (FileNotFoundException e) { Console.WriteLine("Couldn't load file!"); } string line; List <Vertex3f> vertices = new List <Vertex3f>(); List <Vertex2f> textures = new List <Vertex2f>(); List <Vertex3f> normals = new List <Vertex3f>(); List <uint> indices = new List <uint>(); float[] verticesArray = null; float[] normalsArray = null; float[] textureArray = null; uint[] indicesArray = null; try { while (true) { line = fr.ReadLine(); string[] currentLine = line.Split(' '); if (line.StartsWith("v ")) { Vertex3f vertex = new Vertex3f(float.Parse(currentLine[1]), float.Parse(currentLine[2]), float.Parse(currentLine[3])); vertices.Add(vertex); } else if (line.StartsWith("vt ")) { Vertex2f texture = new Vertex2f(float.Parse(currentLine[1]), float.Parse(currentLine[2])); textures.Add(texture); } else if (line.StartsWith("vn ")) { Vertex3f normal = new Vertex3f(float.Parse(currentLine[1]), float.Parse(currentLine[2]), float.Parse(currentLine[3])); normals.Add(normal); } else if (line.StartsWith("f ")) { textureArray = new float[vertices.Count * 2]; normalsArray = new float[vertices.Count * 3]; break; } } while (line != null) { if (!line.StartsWith("f ")) { line = fr.ReadLine(); continue; } string[] currentLine = line.Split(' '); string[] vertex1 = currentLine[1].Split('/'); string[] vertex2 = currentLine[2].Split('/'); string[] vertex3 = currentLine[3].Split('/'); processVertex(ref vertex1, ref indices, ref textures, ref normals, ref textureArray, ref normalsArray); processVertex(ref vertex2, ref indices, ref textures, ref normals, ref textureArray, ref normalsArray); processVertex(ref vertex3, ref indices, ref textures, ref normals, ref textureArray, ref normalsArray); line = fr.ReadLine(); } fr.Close(); }catch (Exception e) { Console.WriteLine(e.ToString()); } verticesArray = new float[vertices.Count * 3]; indicesArray = new uint[indices.Count]; int vertexPointer = 0; foreach (Vertex3f vertex in vertices) { verticesArray[vertexPointer++] = vertex.x; verticesArray[vertexPointer++] = vertex.y; verticesArray[vertexPointer++] = vertex.z; } for (int i = 0; i < indices.Count; i++) { indicesArray[i] = indices[i]; } return(loader.LoadToVao(verticesArray, textureArray, normalsArray, indicesArray)); }
/// <summary> /// /// </summary> /// <param name="width"></param> /// <param name="height"></param> public ViewportState(float width, float height) { ViewportSize = new Vertex2f(width, height); }
/// <summary> /// Merge this state with another one. /// </summary> /// <param name="state"> /// A <see cref="IGraphicsState"/> having the same <see cref="GraphicsState.StateIdentifier"/> of this state. /// </param> /// <remarks> /// <para> /// After a call to this routine, this IGraphicsState store the union of the previous information /// and of the information of <paramref name="state"/>. /// </para> /// <para> /// The semantic of the merge result is dependent on the actual implementation of this IGraphicsState. Normally /// the merge method will copy <paramref name="state"/> into this IGraphicsState, but other state could do /// different operations. /// </para> /// </remarks> public override void Merge(IGraphicsState state) { if (state == null) throw new ArgumentNullException("state"); if (state.StateIdentifier != StateId) throw new ArgumentException("state id mismatch", "state"); ViewportState previousState = (ViewportState)state; ViewportSize = previousState.ViewportSize; }
private void VisionControl_Render(object sender, OpenGL.GlControlEventArgs e) { #region Draw Basic Picture // Update image input _Framebuffer.BindDraw(_GraphicsContext); Gl.Viewport(0, 0, (int)_Framebuffer.Width, (int)_Framebuffer.Height); _Framebuffer.Clear(_GraphicsContext, ClearBufferMask.ColorBufferBit); { // Draw a quad Matrix4x4f quadProj = Matrix4x4f.Ortho2D(-1.0f, +1.0f, -1.0f, +1.0f); Matrix4x4f quadModel = new Matrix4x4f(); _Angle += 1.0f; quadModel.RotateZ(10.0f * (float)Math.Cos(Angle.ToRadians(_Angle))); _GraphicsContext.Bind(_ProgramStd); _ProgramStd.SetUniform(_GraphicsContext, "glo_ModelViewProjection", quadProj * quadModel); _ProgramStd.SetUniform(_GraphicsContext, "glo_UniformColor", Vertex4f.One); _ArraysQuad.Draw(_GraphicsContext, _ProgramStd); } _Framebuffer.UnbindDraw(_GraphicsContext); #endregion #region Track Corners // Read back image input pixels using (OpenGL.Objects.Image imageInput = _FramebufferTexture.Get(_GraphicsContext, PixelLayout.RGB24, 0)) { // Copy the input RGB frame from OpenGL to OpenVX Rectangle cv_rgb_image_region = new Rectangle(); cv_rgb_image_region.StartX = 0; cv_rgb_image_region.StartY = 0; cv_rgb_image_region.EndX = imageInput.Width; cv_rgb_image_region.EndY = imageInput.Height; ImagePatchAddressing cv_rgb_image_layout = new ImagePatchAddressing(); cv_rgb_image_layout.StrideX = 3; cv_rgb_image_layout.StrideY = (int)imageInput.Stride; VX.CopyImagePatch(_ImageInput, ref cv_rgb_image_region, 0, ref cv_rgb_image_layout, imageInput.ImageBuffer, Accessor.WriteOnly, MemoryType.Host); } // Now that input RGB image is ready, just run a graph. // Run Harris at the beginning to initialize the previous keypoints, // on other frames run the tracking graph. VX.ProcessGraph(_DetectCorners ? _GraphHarris : _GraphTrack); _DetectCorners = false; #endregion #region Store Markers on GPU // To mark the keypoints in display, you need to access the output // keypoint array and draw each item on the output window using gui.DrawArrow(). UIntPtr num_corners = UIntPtr.Zero; uint num_tracking = 0; _KeypointsPrevious = VX.GetReferenceFromDelay(_KeypointsDelay, -1); _KeypointsCurrent = VX.GetReferenceFromDelay(_KeypointsDelay, 0); VX.Query(_KeypointsPrevious, ArrayAttribute.Numitems, out num_corners); if (num_corners.ToUInt64() > 0) { UIntPtr kp_old_stride = UIntPtr.Zero, kp_new_stride = UIntPtr.Zero; MapId kp_old_map = new MapId(), kp_new_map = new MapId(); IntPtr kp_old_buf, kp_new_buf; VX.MapArrayRange(_KeypointsPrevious, (UIntPtr)0, num_corners, ref kp_old_map, ref kp_old_stride, out kp_old_buf, Accessor.ReadOnly, MemoryType.Host, 0); VX.MapArrayRange(_KeypointsCurrent, (UIntPtr)0, num_corners, ref kp_new_map, ref kp_new_stride, out kp_new_buf, Accessor.ReadOnly, MemoryType.Host, 0); _BufferOpticalMarkers.Map(_GraphicsContext, BufferAccess.WriteOnly); for (uint i = 0; i < num_corners.ToUInt64(); i++) { KeyPoint kp_old = VX.ArrayItem <KeyPoint>(kp_old_buf, i, kp_old_stride); KeyPoint kp_new = VX.ArrayItem <KeyPoint>(kp_new_buf, i, kp_new_stride); if (kp_new.TrackingStatus != 0) { Vertex2f vOld = new Vertex2f(kp_old.X / 1024.0f, kp_old.Y / 1024.0f); Vertex2f vNew = new Vertex2f(kp_new.X / 1024.0f, kp_new.Y / 1024.0f); _BufferOpticalMarkers.SetElement(vOld, (num_tracking * 2) + 0, 0); _BufferOpticalMarkers.SetElement(vNew, (num_tracking * 2) + 1, 0); num_tracking++; } } _BufferOpticalMarkers.Unmap(_GraphicsContext); VX.UnmapArrayRange(_KeypointsPrevious, kp_old_map); VX.UnmapArrayRange(_KeypointsCurrent, kp_new_map); } #endregion Gl.Viewport(0, 0, VisionControl.Width, VisionControl.Height); Gl.ClearColor(1.0f, 0.0f, 0.0f, 0.0f); Gl.Clear(ClearBufferMask.ColorBufferBit); #region Draw Input Image _GraphicsContext.Bind(_ProgramStdTex); _ProgramStdTex.SetUniform(_GraphicsContext, "glo_ModelViewProjection", Matrix4x4f.Ortho2D(0.0f, 1.0f, 0.0f, 1.0f)); _ProgramStdTex.SetUniform(_GraphicsContext, "glo_Texture", _FramebufferTexture); _ArraysPostQuad.Draw(_GraphicsContext, _ProgramStdTex); #endregion #region Draw Markers if (num_tracking > 0) { _GraphicsContext.Bind(_ProgramStd); _ProgramStd.SetUniform(_GraphicsContext, "glo_ModelViewProjection", Matrix4x4f.Ortho2D(0.0f, 1.0f, 0.0f, 1.0f)); _ProgramStd.SetUniform(_GraphicsContext, "glo_UniformColor", new Vertex4f(1.0f, 0.0f, 0.0f, 1.0f)); _ArraysOpticalMarkers.Draw(_GraphicsContext, _ProgramStd, 0, 0, num_tracking * 2); } #endregion // Increase the age of the delay objects to make the current entry become previous entry VX.AgeDelay(_PyramidDelay); VX.AgeDelay(_KeypointsDelay); }
public void Draw() { Vertex2f[] vertices = new Vertex2f[] { new Vertex2f(0.0f, 0.0f), new Vertex2f(1.0f, 0.0f), new Vertex2f(1.0f, 1.0f), new Vertex2f(0.0f, 1.0f), }; using (VertexArrayObject vao = new VertexArrayObject()) { // Setup ABO (Position) ArrayBufferObject abo = new ArrayBufferObject(VertexBaseType.Float, 2, BufferObjectHint.StaticCpuDraw); abo.Create(vertices); // Setup VAO vao.SetArray(abo, VertexArraySemantic.Position); vao.SetElementArray(PrimitiveType.TriangleStrip); vao.Create(_Context); using (State.GraphicsStateSet currentState = State.GraphicsStateSet.GetDefaultSet()) { // Set transform state State.TransformStateBase stateTransform = (State.TransformStateBase)currentState[State.TransformStateBase.StateId]; // Set normalized orthogonal projection stateTransform.LocalProjection = new OrthoProjectionMatrix(0.0f, 1.0f, 0.0f, 1.0f); // Apply state currentState.Apply(_Context); // Draw Assert.DoesNotThrow(delegate () { vao.Draw(_Context); }); } } }
/// <summary> /// Set uniform state variable (variant type variable). /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for operations. /// </param> /// <param name="uniformName"> /// A <see cref="String"/> that specify the variable name in the shader source. /// </param> /// <param name="v"> /// A <see cref="Vertex2f"/> holding the uniform variabile data. /// </param> public void SetVariantUniform(GraphicsContext ctx, string uniformName, Vertex2f v) { SetVariantUniform(ctx, uniformName, v.x, v.y); }
/// <summary> /// Accumulate a translation on this ModelMatrix. /// </summary> /// <param name="p"> /// A <see cref="Vertex2f"/> that specifies the translation. /// </param> public void Translate(Vertex2f p) { ModelMatrix translationMatrix = new ModelMatrix(); translationMatrix[3, 0] = p.x; translationMatrix[3, 1] = p.y; Set(this * translationMatrix); }
/// <summary> /// Scale this ModelMatrix. /// </summary> /// <param name="s"> /// A <see cref="Vertex2f"/> holding the scaling factors on two dimensions. /// </param> public void SetScale(Vertex2f s) { SetScale(s.x, s.y, 1.0f); }
/// <summary> /// Construct a FontFxShadow specifying the shadow offset. /// </summary> /// <param name="offset"> /// The <see cref="Vertex2f"/> that specifies the shadow offset. /// </param> public FontFxShadow(Vertex2f offset) { Offset = offset; }
public GUITexture(uint textureId, Vertex2f position, Vertex2f scale) { textureID = textureId; this.position = position; this.scale = scale; }
private void DrawLines2f_GL_3_2(Vertex2f[] vertices) { // Define geometry buffer _DrawArrayBuffer.Create(this, vertices); // Define geometry arrays _VertexArray.SetArray(_DrawArrayBuffer, VertexArraySemantic.Position); // Draw arrays _VertexArray.Draw(this, null); }
private void GenerateTangentsTriangleStrip3f(IVertexArray positionArray, IVertexArray normalArray, IVertexArray texArray, IVertexArray tanArray, IVertexArray bitanArray) { uint count = ElementCount != 0 ? ElementCount : ArrayIndices.ItemCount; uint i0, i1, i2; Vertex3f v0, v1, v2; Vertex2f t0, t1, t2; i0 = ArrayIndices.GetIndex(ElementOffset); i1 = ArrayIndices.GetIndex(ElementOffset + 1); v0 = positionArray.GetElement <Vertex3f>(i0); v1 = positionArray.GetElement <Vertex3f>(i1); t0 = texArray.GetElement <Vertex2f>(i0); t1 = texArray.GetElement <Vertex2f>(i1); for (uint i = 0, v = ElementOffset + 2; i < count - 2; i++, v++) { // Next triangle i2 = ArrayIndices.GetIndex(v); v2 = positionArray.GetElement <Vertex3f>(i2); t2 = texArray.GetElement <Vertex2f>(i2); // Compute tangent & bitangent Vertex3f dv1 = v1 - v0, dv2 = v2 - v0; Vertex2f dt1 = t1 - t0, dt2 = t2 - t0; float w = 1.0f / (dt1.x * dt2.y - dt1.y * dt2.x); Vertex3f tgVector, btVector; if (Single.IsInfinity(w) == false) { tgVector = (dv1 * dt2.y - dv2 * dt1.y) * w; tgVector.Normalize(); btVector = (dv2 * dt1.x - dv1 * dt2.x) * w; btVector.Normalize(); //Vertex3f n = normalArray.GetElement<Vertex3f>(i2); //n.Normalize(); //if (((n ^ tgVector) * btVector) < 0.0f) // tgVector = tgVector * -1.0f; } else { // Degenerate triangles does not contribute tgVector = btVector = Vertex3f.Zero; } // Store (accumulate adjacent triangles) Vertex3f tg0 = tanArray.GetElement <Vertex3f>(i0) + tgVector; Vertex3f tg1 = tanArray.GetElement <Vertex3f>(i1) + tgVector; Vertex3f tg2 = tanArray.GetElement <Vertex3f>(i2) + tgVector; tanArray.SetElement <Vertex3f>(tg0, i0); tanArray.SetElement <Vertex3f>(tg1, i1); tanArray.SetElement <Vertex3f>(tg2, i2); Vertex3f bt0 = bitanArray.GetElement <Vertex3f>(i0) + btVector; Vertex3f bt1 = bitanArray.GetElement <Vertex3f>(i1) + btVector; Vertex3f bt2 = bitanArray.GetElement <Vertex3f>(i2) + btVector; bitanArray.SetElement <Vertex3f>(bt0, i0); bitanArray.SetElement <Vertex3f>(bt1, i1); bitanArray.SetElement <Vertex3f>(bt2, i2); // Prepare for next triangle i0 = i1; i1 = i2; } }
/// <summary> /// /// </summary> /// <param name="graphicsSurface"></param> public ViewportState(GraphicsSurface graphicsSurface) { if (graphicsSurface == null) throw new ArgumentNullException("graphicsSurface"); ViewportSize = new Vertex2f(graphicsSurface.Width, graphicsSurface.Height); }
public VertexArrays CreateArrays(ObjContext objContext) { if (objContext == null) { throw new ArgumentNullException("objContext"); } VertexArrays vertexArray = new VertexArrays(); List <ObjFaceCoord> coords = new List <ObjFaceCoord>(); bool hasTexCoord = Material.DiffuseTexture != null; bool hasNormals = false; bool hasTanCoord = hasTexCoord && Material.NormalTexture != null; foreach (ObjFace f in Faces) { hasTexCoord |= f.HasTexCoord; hasNormals |= f.HasNormal; coords.AddRange(f.Triangulate()); } uint vertexCount = (uint)coords.Count; Vertex4f[] position = new Vertex4f[vertexCount]; Vertex3f[] normal = hasNormals ? new Vertex3f[vertexCount] : null; Vertex2f[] texcoord = new Vertex2f[vertexCount]; for (int i = 0; i < position.Length; i++) { Debug.Assert(coords[i].VertexIndex < objContext.Vertices.Count); position[i] = objContext.Vertices[coords[i].VertexIndex]; if (hasTexCoord) { Debug.Assert(coords[i].TexCoordIndex < objContext.TextureCoords.Count); texcoord[i] = objContext.TextureCoords[coords[i].TexCoordIndex]; } if (hasNormals) { Debug.Assert(coords[i].NormalIndex < objContext.Normals.Count); normal[i] = objContext.Normals[coords[i].NormalIndex]; } } // Position (mandatory) ArrayBuffer <Vertex4f> positionBuffer = new ArrayBuffer <Vertex4f>(); positionBuffer.Create(position); vertexArray.SetArray(positionBuffer, VertexArraySemantic.Position); // Layout (triangles) vertexArray.SetElementArray(PrimitiveType.Triangles); // Texture if (hasTexCoord) { ArrayBuffer <Vertex2f> texCoordBuffer = new ArrayBuffer <Vertex2f>(); texCoordBuffer.Create(texcoord); vertexArray.SetArray(texCoordBuffer, VertexArraySemantic.TexCoord); } // Normals if (hasNormals) { ArrayBuffer <Vertex3f> normalBuffer = new ArrayBuffer <Vertex3f>(); normalBuffer.Create(normal); vertexArray.SetArray(normalBuffer, VertexArraySemantic.Normal); } else { ArrayBuffer <Vertex3f> normalBuffer = new ArrayBuffer <Vertex3f>(); normalBuffer.Create(vertexCount); vertexArray.SetArray(normalBuffer, VertexArraySemantic.Normal); // XXX vertexArray.GenerateNormals(); } // Tangents if (hasTanCoord) { ArrayBuffer <Vertex3f> tanCoordBuffer = new ArrayBuffer <Vertex3f>(); tanCoordBuffer.Create(vertexCount); vertexArray.SetArray(tanCoordBuffer, VertexArraySemantic.Tangent); ArrayBuffer <Vertex3f> bitanCoordBuffer = new ArrayBuffer <Vertex3f>(); bitanCoordBuffer.Create(vertexCount); vertexArray.SetArray(bitanCoordBuffer, VertexArraySemantic.Bitangent); // XXX vertexArray.GenerateTangents(); } return(vertexArray); }
/// <summary> /// Draw a character sequence (base method). /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> used for drawing. /// </param> /// <param name="modelview"> /// The <see cref="Matrix4x4"/> the model-view-projection matrix for the first character of <paramref name="s"/>. /// </param> /// <param name="color"> /// The <see cref="ColorRGBAF"/> that specifies the glyph color. /// </param> /// <param name="s"> /// A <see cref="String"/> that specifies the characters for be drawn. /// </param> private void DrawStringCore(GraphicsContext ctx, Matrix4x4 modelview, TextureArray2d texture, ColorRGBAF color, string s) { ModelMatrix charModel = new ModelMatrix(modelview); ctx.Bind(_FontProgram); // Set uniforms _FontProgram.SetUniform(ctx, "glo_UniformColor", color); _FontProgram.SetUniform(ctx, "glo_FontGlyph", texture); // Set instances char[] fontChars = s.ToCharArray(); uint instances = 0; _GlyphInstances.Map(ctx, BufferAccessARB.WriteOnly); try { for (int i = 0; i < fontChars.Length; i++) { Glyph glyph; if (_GlyphMetadata.TryGetValue(fontChars[i], out glyph) == false) { continue; } // Set instance information Matrix4x4f modelViewProjection = new Matrix4x4f( new Vertex4f(charModel.GetColumn(0)), new Vertex4f(charModel.GetColumn(1)), new Vertex4f(charModel.GetColumn(2)), new Vertex4f(charModel.GetColumn(3)) ); Vertex3f glyphVertexParams = new Vertex3f( glyph.GlyphSize.Width, glyph.GlyphSize.Height, glyph.Layer ); Vertex2f glyphTexParams = new Vertex2f( glyph.TexScale.Width, glyph.TexScale.Height ); _GlyphInstances.SetElement(modelViewProjection, instances, 0); _GlyphInstances.SetElement(glyphVertexParams, instances, 1); _GlyphInstances.SetElement(glyphTexParams, instances, 2); // Count the instance instances++; // Move next charModel.Translate(glyph.GlyphSize.Width, 0.0f); } } finally { _GlyphInstances.Unmap(ctx); } // Rasterize it using (State.BlendState stateBlend = State.BlendState.AlphaBlending) { stateBlend.ApplyState(ctx, _FontProgram); _VertexArrays.DrawInstanced(ctx, _FontProgram, instances); } }