CSharpGL.Pixel.ToStageVertexId C# (CSharp) Method

ToStageVertexId() public method

Gets stageVertexID from coded color. The stageVertexID is the last vertex that constructs the primitive. see http://www.cnblogs.com/bitzhuwei/p/modern-opengl-picking-primitive-in-VBO-2.html
public ToStageVertexId ( ) : uint
return uint
        public uint ToStageVertexId()
        {
            uint shiftedR = (uint)this.r;
            uint shiftedG = ((uint)this.g) << 8;
            uint shiftedB = ((uint)this.b) << 16;
            uint shiftedA = ((uint)this.a) << 24;
            uint stageVertexId = shiftedR + shiftedG + shiftedB + shiftedA;

            return stageVertexId;
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Read pixels in specified rect and get the VertexIds they represent.
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        private static unsafe List <Tuple <Point, uint> > ReadPixels(Rectangle target)
        {
            var result = new List <Tuple <Point, uint> >();

            // get coded color.
            using (var codedColor = new UnmanagedArray <Pixel>(target.Width * target.Height))
            {
                OpenGL.ReadPixels(target.X, target.Y, target.Width, target.Height,
                                  OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, codedColor.Header);

                var array        = (Pixel *)codedColor.Header.ToPointer();
                int index        = 0;
                var vertexIdList = new List <uint>();
                for (int yOffset = target.Height - 1; yOffset >= 0; yOffset--)
                {
                    for (int xOffset = 0; xOffset < target.Width; xOffset++)
                    {
                        Pixel pixel = array[index++];
                        // This is when (x, y) is not on background and some primitive is picked.
                        if (!pixel.IsWhite())
                        {
                            uint stageVertexId = pixel.ToStageVertexId();
                            if (!vertexIdList.Contains(stageVertexId))
                            {
                                result.Add(new Tuple <Point, uint>(
                                               new Point(target.X + xOffset, target.Y + yOffset), stageVertexId));
                                vertexIdList.Add(stageVertexId);
                            }
                        }
                    }
                }
            }

            return(result);
        }
All Usage Examples Of CSharpGL.Pixel::ToStageVertexId