private static OneIndexLineSearcher GetLineSearcher(DrawMode mode)
        {
            if (lineSearcherDict == null)
            {
                var triangle = new OneIndexLineInTriangleSearcher();
                var quad = new OneIndexLineInQuadSearcher();
                var polygon = new OneIndexLineInPolygonSearcher();
                var dict = new Dictionary<DrawMode, OneIndexLineSearcher>();
                dict.Add(DrawMode.Triangles, triangle);
                dict.Add(DrawMode.TrianglesAdjacency, triangle);
                dict.Add(DrawMode.TriangleStrip, triangle);
                dict.Add(DrawMode.TriangleStripAdjacency, triangle);
                dict.Add(DrawMode.TriangleFan, triangle);
                dict.Add(DrawMode.Quads, quad);
                dict.Add(DrawMode.QuadStrip, quad);
                dict.Add(DrawMode.Polygon, polygon);

                lineSearcherDict = dict;
            }

            OneIndexLineSearcher result = null;
            if (lineSearcherDict.TryGetValue(mode, out result))
            { return result; }
            else
            { return null; }
        }
예제 #2
0
 /// <summary>
 /// Wraps glDrawArrays(uint mode, int first, int count).
 /// </summary>
 /// <param name="mode">用哪种方式渲染各个顶点?(OpenGL.GL_TRIANGLES etc.)</param>
 /// <param name="firstVertex">要渲染的第一个顶点的位置。<para>Index of first vertex to be rendered.</para></param>
 /// <param name="vertexCount">要渲染多少个元素?<para>How many vertexes to be rendered?</para></param>
 /// <param name="primCount">primCount in instanced rendering.</param>
 internal ZeroIndexBuffer(DrawMode mode, int firstVertex, int vertexCount, int primCount = 1)
     : base(mode, 0, vertexCount, vertexCount * sizeof(uint), primCount)
 {
     this.FirstVertex = firstVertex;
     this.RenderingVertexCount = vertexCount;
     //this.OriginalVertexCount = vertexCount;
 }
        /// <summary>
        /// 设置要高亮显示的图元。
        /// </summary>
        /// <param name="mode">要高亮显示的图元类型</param>
        /// <param name="indexes">要高亮显示的图元的索引。</param>
        public void SetHighlightIndexes(DrawMode mode, params uint[] indexes)
        {
            int indexesLength = indexes.Length;
            if (indexesLength > this.maxElementCount)
            {
                IndexBuffer original = this.indexBuffer;
                this.indexBuffer = Buffer.Create(IndexBufferElementType.UInt, indexesLength, mode, BufferUsage.StaticDraw);
                this.maxElementCount = indexesLength;
                original.Dispose();
            }

            var indexBuffer = this.indexBuffer as OneIndexBuffer;
            IntPtr pointer = indexBuffer.MapBuffer(MapBufferAccess.WriteOnly);
            unsafe
            {
                var array = (uint*)pointer.ToPointer();
                for (int i = 0; i < indexesLength; i++)
                {
                    array[i] = indexes[i];
                }
            }
            indexBuffer.UnmapBuffer();

            indexBuffer.Mode = mode;
            indexBuffer.ElementCount = indexesLength;
        }
예제 #4
0
        float viewOffset; // view offset moves sprite in direction of camera

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Create a new animated sprite
        /// </summary>
        public AnimSprite(
                AnimSpriteType type,
                Vector3 position, float radius, float viewOffset,
                Texture2D texture, int frameSizeX, int frameSizeY,
                float frameRate, DrawMode mode, int player)
        {
            if (texture == null)
            {
                throw new ArgumentNullException("texture");
            }

            spriteType = type;
            this.position = position;
            this.radius = radius;
            this.viewOffset = viewOffset;
            this.texture = texture;
            this.player = player;
            this.frameRate = frameRate;
            this.drawMode = mode;

            // frame size
            float sizeX = (float)frameSizeX / (float)texture.Width;
            float sizeY = (float)frameSizeY / (float)texture.Height;
            frameSize = new Vector2(sizeX, sizeY);

            // number of frames
            numberFramesX = texture.Width / frameSizeX;
            numberFramesY = texture.Height / frameSizeY;
            numberFrames = numberFramesX * numberFramesY;

            // total animation time
            totalTime = (float)numberFrames / frameRate;
            elapsedTime = 0;
        }
        public BackgroundComponent(Game game, Texture2D image, DrawMode drawMode)
        {
            Visible = true;
            this.image = image;
            this.drawMode = drawMode;
            screenRectangle = new Rectangle(
            0,
            0,
            game.Window.ClientBounds.Width,
            game.Window.ClientBounds.Height);

            //Nastaveni Rectanglu pro vykresleni bud na cely obraz nebo jen podle velikosti textury
            switch (drawMode)
            {
                case DrawMode.Center:
                    destination = new Rectangle(
                    (screenRectangle.Width - image.Width) / 2,
                    (screenRectangle.Height - image.Height) / 2,
                    image.Width,
                    image.Height);
                    break;
                case DrawMode.Fill:
                    destination = new Rectangle(
                    screenRectangle.X,
                    screenRectangle.Y,
                    screenRectangle.Width,
                    screenRectangle.Height);
                    break;
            }
        }
예제 #6
0
        protected int timerPerion; // частота отрисовки графиков в активном режиме

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Инициализирует новый экземпляр класса
        /// </summary>
        /// <param name="GPanel">Панель которую будет обслуживать манеджер</param>
        public GraphicManager(Panel GPanel)
        {
            mutex = new Mutex();
            slim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);

            mode = DrawMode.Default;

            if (GPanel != null)
            {
                panel = GPanel;
                //panel.StartTime = DateTime.Now;

                panel.OnResize += new EventHandler(Sheet_Resize);

                panel.Sheet.onOrientationChange += new EventHandler(Sheet_onOrientationChange);
                panel.Sheet.onIntervalInCellChange += new EventHandler(Sheet_onIntervalInCellChange);

                timerPerion = 500;
                timer = new Timer(TimerCallback, null, Timeout.Infinite, timerPerion);
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
예제 #7
0
 /// <summary>
 /// Bufferable model with zero vertex attribute.
 /// </summary>
 /// <param name="mode">渲染模式。</param>
 /// <param name="firstVertex">要渲染的第一个顶点的位置。<para>Index of first vertex to be rendered.</para></param>
 /// <param name="vertexCount">要渲染多少个元素?<para>How many vertexes to be rendered?</para></param>
 /// <param name="primCount">primCount in instanced rendering.</param>
 public ZeroAttributeModel(DrawMode mode, int firstVertex, int vertexCount, int primCount = 1)
 {
     this.Mode = mode;
     this.FirstVertex = firstVertex;
     this.VertexCount = vertexCount;
     this.PrimCount = primCount;
 }
예제 #8
0
        public PictureBox3D(DeviceManager initDM, SceneManager initSM)
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            // initialize members
            nameVisible = true;				// show the name of this viewport on-screen?
            _drawMode = DrawMode.wireFrame;	// default to wireframe view
            arcBall = new ArcBall(this);
            arcBall.Radius = 1.0f;

            BuildCameraMenu();

            // new events
            Midget.Events.EventFactory.DeselectObjects +=new Midget.Events.Object.Selection.DeselectObjectEventHandler(EventFactory_DeselectObjects);
            Midget.Events.EventFactory.SelectAdditionalObject +=new Midget.Events.Object.Selection.SelectAdditionalObjectEventHandler(EventFactory_SelectAdditionalObject);
            Midget.Events.EventFactory.AdjustCameraEvent +=new Midget.Events.User.AdjustCameraEventHandler(EventFactory_AdjustCameraEvent);
            Midget.Events.EventFactory.SwitchEditModeEvent +=new Midget.Events.User.SwitchEditModeEventHandler(EventFactory_SwitchEditModeEvent);
            selectedObjects = new ArrayList();

            this.dm = initDM;

            // attach listener for render event
            dm.Render += new System.EventHandler(this.Viewport_Render);
            this.renderView += new RenderSingleViewHandler(dm.OnRenderSingleView);

            this.sm = initSM;

            this.ConfigureRenderTarget();
        }
예제 #9
0
        public void Draw(DrawMode Mode,VertexBuffer VB)
        {
            if(VB == null)
                throw new Exception("Must have Vertex Buffer");

            if(VB.Normal != null)
            {
                gl.EnableClientState(NORMAL_ARRAY);

                gl.BindBuffer((uint)VB.Normal.BType,VB.Normal.B);
                gl.NormalPointer((uint)VB.Normal.T,0,null);
            }
            else gl.DisableClientState(NORMAL_ARRAY);

            if(VB.TexCoord != null)
            {
                gl.EnableClientState(TEXTURE_COORD_ARRAY);

                gl.BindBuffer((uint)VB.TexCoord.BType,VB.TexCoord.B);
                gl.TexCoordPointer(VB.TexCoord.Size,(uint)VB.TexCoord.T,0,null);
            }
            else gl.DisableClientState(TEXTURE_COORD_ARRAY);

            gl.EnableClientState(VERTEX_ARRAY);

            gl.BindBuffer((uint)VB.BType,VB.B);
            gl.VertexPointer(VB.Size,(uint)VB.T,0,null);

            gl.DrawArrays((uint)Mode,0,VB.Count);

            gl.DisableClientState(VERTEX_ARRAY);
            gl.DisableClientState(NORMAL_ARRAY);
            gl.DisableClientState(TEXTURE_COORD_ARRAY);
        }
        /// <summary>
        /// 将共享点前移,构成2个图元组成的新的小小的索引。
        /// </summary>
        /// <param name="recognizedPrimitiveIndex0"></param>
        /// <param name="recognizedPrimitiveIndex1"></param>
        /// <param name="drawMode"></param>
        /// <param name="lastIndex0"></param>
        /// <param name="lastIndex1"></param>
        /// <returns></returns>
        private List<uint> ArrangeIndexes(
            RecognizedPrimitiveInfo recognizedPrimitiveIndex0,
            RecognizedPrimitiveInfo recognizedPrimitiveIndex1,
            DrawMode drawMode,
            out uint lastIndex0, out uint lastIndex1)
        {
            var sameIndexList = new List<uint>();
            var array0 = new List<uint>(recognizedPrimitiveIndex0.VertexIds);
            var array1 = new List<uint>(recognizedPrimitiveIndex1.VertexIds);
            array0.Sort(); array1.Sort();
            int p0 = 0, p1 = 0;
            while (p0 < array0.Count && p1 < array1.Count)
            {
                if (array0[p0] < array1[p1])
                { p0++; }
                else if (array0[p0] > array1[p1])
                { p1++; }
                else
                {
                    sameIndexList.Add(array0[p0]);
                    array0.RemoveAt(p0);
                    array1.RemoveAt(p1);
                }
            }

            if (array0.Count == 0 && array1.Count == 0)
            { throw new Exception("Two primitives are totally the same!"); }

            if (array0.Count > 0)
            { lastIndex0 = array0.Last(); }
            else
            {
                if (sameIndexList.Count == 0)
                { throw new Exception("array0 is totally empty!"); }

                lastIndex0 = sameIndexList.Last();
            }

            if (array1.Count > 0)
            { lastIndex1 = array1.Last(); }
            else
            {
                if (sameIndexList.Count == 0)
                { throw new Exception("array1 is totally empty!"); }

                lastIndex1 = sameIndexList.Last();
            }

            if (lastIndex0 == lastIndex1) { throw new Exception(); }

            var result = new List<uint>();
            result.AddRange(sameIndexList);
            result.AddRange(array0);
            result.Add(uint.MaxValue);// primitive restart index
            result.AddRange(sameIndexList);
            result.AddRange(array1);

            return result;
        }
예제 #11
0
		/// <summary>
		/// Initializes a new instance of <see cref="DrawArgs"/>.
		/// </summary>
		public DrawArgs(
			IRenderingSurface surface, 
			Screen screen,
			DrawMode drawMode)
		{
			_renderingSurface = surface;
			_screen = screen;
			_drawMode = drawMode;
		}
        public static PrimitiveRecognizer Create(DrawMode mode)
        {
            PrimitiveRecognizer recognizer = null;

            switch (mode)
            {
                case DrawMode.Points:
                    recognizer = new PointsRecognizer();
                    break;
                case DrawMode.LineStrip:
                    recognizer = new LineStripRecognizer();
                    break;
                case DrawMode.LineLoop:
                    recognizer = new LineLoopRecognizer();
                    break;
                case DrawMode.Lines:
                    recognizer = new LinesRecognizer();
                    break;
                case DrawMode.LineStripAdjacency:
                    break;
                case DrawMode.LinesAdjacency:
                    break;
                case DrawMode.TriangleStrip:
                    recognizer = new TriangleStripRecognizer();
                    break;
                case DrawMode.TriangleFan:
                    recognizer = new TriangleFanRecognizer();
                    break;
                case DrawMode.Triangles:
                    recognizer = new TrianglesRecognizer();
                    break;
                case DrawMode.TriangleStripAdjacency:
                    break;
                case DrawMode.TrianglesAdjacency:
                    break;
                case DrawMode.Patches:
                    break;
                case DrawMode.QuadStrip:
                    recognizer = new QuadStripRecognizer();
                    break;
                case DrawMode.Quads:
                    recognizer = new QuadsRecognizer();
                    break;
                case DrawMode.Polygon:
                    break;
                default:
                    break;
            }

            if (recognizer == null)
            {
                throw new NotImplementedException(string.Format(
                    "尚未实现[{0}]的recognizer!", mode));
            }

            return recognizer;
        }
예제 #13
0
 public GenericMaterial(Texture tex, Texture normalMap = null, Texture bumpMap = null)
 {
     CompileShaders();
     Tex = tex;
     NormalMap = normalMap;
     bumpMap = bumpMap;
     Color = Vector4.One;
     Mode = GenericMaterial.DrawMode.TextureOnly;
 }
예제 #14
0
파일: Mesh.cs 프로젝트: konlil/pipe
 /// <summary>
 /// 创建一个mesh对象,不使用索引缓冲
 /// </summary>
 /// <param name="pt"></param>
 /// <param name="vb"></param>
 /// <param name="vd"></param>
 public Mesh(PrimitiveType pt, VertexBuffer vb, VertexDeclaration vd)
 {
     this.is_visible = true;
     this.vertices_count = vb.SizeInBytes / vd.GetVertexStrideSize(0);
     this.draw_mode = DrawMode.Primitive;
     this.primitive_type = pt;
     this.vb = vb;
     this.vd = vd;
     this.primitive_count = CalcPrimitiveCount();
 }
예제 #15
0
        public Context(int width, int height)
        {
            Width = width;
            Height = height;

            _Context = new GraphicsContext(width,height, PixelFormat.Rgba, PixelFormat.Depth24,MultiSampleMode.Msaa4x);
            AspectRatio = _Context.Screen.AspectRatio;

            drawMode = DrawMode.Triangles;
        }
예제 #16
0
 public MeshData( DrawMode mode, int vertexCount, int indexCount )
 {
     drawMode = mode;
     positions = new float[ vertexCount * 3 ];
     normals = new float[ vertexCount * 3 ];
     tangents = new float[ vertexCount * 3 ];
     colors = new float[ vertexCount * 4 ];
     texcoords = new float[ vertexCount * 2 ];
     indices = new ushort[ indexCount ];
 }
예제 #17
0
        private void InitVAO()
        {
            this.axisPrimitiveMode = DrawMode.LineLoop;
            this.axisVertexCount = 4;
            this.vao = new uint[1];

            GL.GenVertexArrays(1, vao);

            GL.BindVertexArray(vao[0]);

            //  Create a vertex buffer for the vertex data.
            {
                UnmanagedArray<vec3> positionArray = new UnmanagedArray<vec3>(4);
                positionArray[0] = new vec3(-0.5f, -0.5f, 0);
                positionArray[1] = new vec3(0.5f, -0.5f, 0);
                positionArray[2] = new vec3(0.5f, 0.5f, 0);
                positionArray[3] = new vec3(-0.5f, 0.5f, 0);

                uint positionLocation = shaderProgram.GetAttributeLocation(strin_Position);

                uint[] ids = new uint[1];
                GL.GenBuffers(1, ids);
                GL.BindBuffer(BufferTarget.ArrayBuffer, ids[0]);
                GL.BufferData(BufferTarget.ArrayBuffer, positionArray, BufferUsage.StaticDraw);
                GL.VertexAttribPointer(positionLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero);
                GL.EnableVertexAttribArray(positionLocation);

                positionArray.Dispose();
            }

            //  Now do the same for the colour data.
            {
                UnmanagedArray<vec3> colorArray = new UnmanagedArray<vec3>(4);
                vec3 color = this.rectColor;
                for (int i = 0; i < colorArray.Length; i++)
                {
                    colorArray[i] = color;
                }

                uint colorLocation = shaderProgram.GetAttributeLocation(strin_Color);

                uint[] ids = new uint[1];
                GL.GenBuffers(1, ids);
                GL.BindBuffer(BufferTarget.ArrayBuffer, ids[0]);
                GL.BufferData(BufferTarget.ArrayBuffer, colorArray, BufferUsage.StaticDraw);
                GL.VertexAttribPointer(colorLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero);
                GL.EnableVertexAttribArray(colorLocation);

                colorArray.Dispose();
            }

            //  Unbind the vertex array, we've finished specifying data for it.
            GL.BindVertexArray(0);
        }
예제 #18
0
        public GraphicsDevice(SDLWindow window)
        {
            this.window = window;
            screen = window.Screen;

            BeginDraw();
            FillScreen(0, 0, 0, 255);
            EndDraw();

            LoadTextures();
            currentDrawMode = DrawMode.Unknown;
        }
예제 #19
0
        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();
        }
예제 #20
0
        void Draw( Player player, Command command, DrawMode mode ) {
            if( !player.Can( Permissions.Draw ) ) {
                world.NoAccessMessage( player );
                return;
            }
            if( player.drawingInProgress ) {
                player.Message( "Another draw command is already in progress. Please wait." );
                return;
            }
            string blockName = command.Next();
            Block block;
            if( blockName == null || blockName == "" ) {
                if( mode == DrawMode.Cuboid ) {
                    player.Message( "Usage: " + Color.Help + "/cuboid blockName" + Color.Sys + " or " + Color.Help + "/cub blockName" );
                } else {
                    player.Message( "Usage: " + Color.Help + "/ellipsoid blockName" + Color.Sys + " or " + Color.Help + "/ell blockName" );
                }
                return;
            }
            try {
                block = Map.GetBlockByName( blockName );
            } catch( Exception ) {
                player.Message( "Unknown block name: " + blockName );
                return;
            }
            player.tag = block;

            Permissions permission = Permissions.Build;
            switch( block ) {
                case Block.Admincrete: permission = Permissions.PlaceAdmincrete; break;
                case Block.Air: permission = Permissions.Delete; break;
                case Block.Water:
                case Block.StillWater: permission = Permissions.PlaceWater; break;
                case Block.Lava:
                case Block.StillLava: permission = Permissions.PlaceLava; break;
            }
            if( !player.Can( permission ) ) {
                player.Message( "You are not allowed to draw with this block." );
                return;
            }

            player.marksExpected = 2;
            player.markCount = 0;
            player.marks.Clear();
            player.Message( mode.ToString() + ": Place a block or type /mark to use your location." );

            if( mode == DrawMode.Cuboid ) {
                player.selectionCallback = DrawCuboid;
            } else {
                player.selectionCallback = DrawEllipsoid;
            }
        }
예제 #21
0
        public void Draw(DrawMode Mode,IndexBuffer IB)
        {
            if(IB.Vertex == null || IB == null)
                throw new Exception("Must have Vertex and Index Buffer");

            VertexBuffer VB	= IB.Vertex;

            if(VB.Normal != null)
            {
                gl.EnableClientState(NORMAL_ARRAY);

                gl.BindBuffer((uint)VB.Normal.BType,VB.Normal.B);
                gl.NormalPointer((uint)VB.Normal.T,0,null);
            }
            else gl.DisableClientState(NORMAL_ARRAY);

            if(VB.TexCoord != null)
            {
                gl.EnableClientState(TEXTURE_COORD_ARRAY);

                gl.BindBuffer((uint)VB.TexCoord.BType,VB.TexCoord.B);
                gl.TexCoordPointer(VB.TexCoord.Size,(uint)VB.TexCoord.T,0,null);
            }
            else gl.DisableClientState(TEXTURE_COORD_ARRAY);

            if(VB != null)
            {
                gl.EnableClientState(VERTEX_ARRAY);

                gl.BindBuffer((uint)VB.BType,VB.B);
                gl.VertexPointer(VB.Size,(uint)VB.T,0,null);
            }
            else gl.DisableClientState(VERTEX_ARRAY);

            gl.EnableClientState(INDEX_ARRAY);

            gl.BindBuffer((uint)IB.BType,IB.B);
            gl.IndexPointer((uint)IB.T,0,null);
            gl.DrawElements((uint)Mode,IB.Count,(uint)IB.T,null);

            gl.DisableClientState(INDEX_ARRAY);
            gl.DisableClientState(VERTEX_ARRAY);
            gl.DisableClientState(NORMAL_ARRAY);
            gl.DisableClientState(TEXTURE_COORD_ARRAY);
        }
예제 #22
0
 public ImageComponent(Game game, Texture2D texture, DrawMode drawMode)
     : base(game)
 {
     this.m_texture2D = texture;
     this.m_drawMode = drawMode;
     this.m_spriteBatch = game.Services.GetService(typeof(SpriteBatch)) as SpriteBatch;
     switch (this.m_drawMode)
     {
         case DrawMode.Center:
             this.m_imgRect = new Rectangle((game.Window.ClientBounds.Width - this.m_texture2D.Width) / 2, (game.Window.ClientBounds.Height - this.m_texture2D.Height) / 2, this.m_texture2D.Width, this.m_texture2D.Height);
             break;
         case DrawMode.Stretch:
             this.m_imgRect = new Rectangle(0, 0, game.Window.ClientBounds.Width, game.Window.ClientBounds.Height);
             break;
         default:
             break;
     }
 }
예제 #23
0
        /// <summary>
        /// Create a WPFDanmakuEngine instance
        /// </summary>
        /// <param name="TargetCanvas">Danmaku container</param>
        /// <param name="DefaultStyle">Default danmaku style</param>
        public WPFDanmakuEngine(Canvas TargetCanvas, BaseDanmaku DefaultStyle, DrawMode Mode)
        {
            mRandomObj = new Random();
            if (Mode == DrawMode.Performance) {
                throw new NotImplementedException("Still working on this");
            } else {
                CurrentDrawMode = DrawMode.Compatibility;

                if (TargetCanvas.IsLoaded) {
                    this.mBindingCanvas = TargetCanvas;
                } else {
                    throw new InvalidOperationException("Canvas is not ready.");
                }

                this.mDefaultStyle = DefaultStyle;
                GenerateWPFCache();
            }
        }
예제 #24
0
        /// <summary>
        /// Creates a <see cref="OneIndexBuffer"/> object directly in server side(GPU) without initializing its value.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="length">How many indexes are there?(How many uint/ushort/bytes?)</param>
        /// <param name="mode"></param>
        /// <param name="usage"></param>
        /// <returns></returns>
        public static OneIndexBuffer Create(IndexBufferElementType type, int length, DrawMode mode, BufferUsage usage)
        {
            if (glGenBuffers == null) { glGenBuffers = OpenGL.GetDelegateFor<OpenGL.glGenBuffers>(); }
            if (glBindBuffer == null) { glBindBuffer = OpenGL.GetDelegateFor<OpenGL.glBindBuffer>(); }
            if (glBufferData == null) { glBufferData = OpenGL.GetDelegateFor<OpenGL.glBufferData>(); }

            int byteLength = GetSize(type) * length;
            uint[] buffers = new uint[1];
            glGenBuffers(1, buffers);
            const uint target = OpenGL.GL_ELEMENT_ARRAY_BUFFER;
            glBindBuffer(target, buffers[0]);
            glBufferData(target, byteLength, IntPtr.Zero, (uint)usage);
            glBindBuffer(target, 0);

            var buffer = new OneIndexBuffer(
                 buffers[0], mode, type, length, byteLength);

            return buffer;
        }
예제 #25
0
		/// <summary>
		/// Initializes a <see cref="RenderingException"/>.
		/// </summary>
		/// <param name="innerException">The actual exception that was thrown in the rendering pipeline.</param>
		/// <param name="drawArgs">The <see cref="DrawArgs"/> of the failed rendering operation.</param>
		/// <exception cref="ArgumentNullException">Thrown if <paramref name="innerException"/> is null.</exception>
		public RenderingException(Exception innerException, DrawArgs drawArgs)
			: base("An exception was thrown in the rendering pipeline.", innerException)
		{
			if (innerException == null)
				throw new ArgumentNullException("innerException", "An inner exception must be provided.");

			// record as much information as possible about the rendering operation for debugging purposes
			if (drawArgs != null)
			{
				DrawMode = drawArgs.DrawMode;
				if (drawArgs.RenderingSurface != null)
				{
					WindowId = drawArgs.RenderingSurface.WindowID;
					ContextId = drawArgs.RenderingSurface.ContextID;
					ClientRectangle = drawArgs.RenderingSurface.ClientRectangle;
					ClipRectangle = drawArgs.RenderingSurface.ClipRectangle;
				}
			}
		}
예제 #26
0
        public DrawState(VideoSystem videosystem)
        {
            if (videosystem == null) throw new ArgumentNullException("videosystem");

            m_videosystem = videosystem;
            m_mode = DrawMode.Normal;
            m_pixels = null;
            m_palette = null;
            m_scissorrect = Rectangle.Empty;
            m_blending = new Blending();
            m_drawdata = new List<DrawData>();
            m_scale = Vector2.One;
            m_axis = Vector2.Zero;
            m_flip = SpriteEffects.None;
            m_rotation = 0;
            m_offset = Vector2.Zero;
            m_stretch = Vector2.One;
            m_parameters = new ShaderParameters();
        }
        protected void InitializeVAO()
        {
            this.primitiveMode = DrawMode.Points;
            const int axisCount = 3;
            const int count = axisCount * axisCount * axisCount;
            this.vertexCount = count;

            this.vao = new uint[1];

            GL.GenVertexArrays(4, vao);

            GL.BindVertexArray(vao[0]);

            //  Create a vertex buffer for the vertex data.
            {
                UnmanagedArray<vec3> positionArray = new UnmanagedArray<vec3>(count);
                for (int i = 0, index = 0; i < axisCount; i++)
                {
                    for (int j = 0; j < axisCount; j++)
                    {
                        for (int k = 0; k < axisCount; k++)
                        {
                            //positionArray[index++] = 10 * new vec3(i - axisCount / 2, j - axisCount / 2, k - axisCount / 2);
                            positionArray[index++] = 10 * new vec3((float)random.NextDouble() - 0.5f, (float)random.NextDouble() - 0.5f, (float)random.NextDouble() - 0.5f);
                        }
                    }
                }

                uint positionLocation = shaderProgram.GetAttributeLocation(strin_Position);

                uint[] ids = new uint[1];
                GL.GenBuffers(1, ids);
                GL.BindBuffer(BufferTarget.ArrayBuffer, ids[0]);
                GL.BufferData(BufferTarget.ArrayBuffer, positionArray, BufferUsage.StaticDraw);
                GL.VertexAttribPointer(positionLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero);
                GL.EnableVertexAttribArray(positionLocation);

                positionArray.Dispose();
            }

            //  Unbind the vertex array, we've finished specifying data for it.
            GL.BindVertexArray(0);
        }
예제 #28
0
        public ImageComponent(Game game, Texture2D texture, DrawMode drawMode)
            : base(game)
        {
            this.texture = texture;
            this.drawMode = drawMode;

            spriteBatch = (SpriteBatch) Game.Services.GetService(typeof (SpriteBatch));

            switch (drawMode)
            {
                case DrawMode.Center:
                    imageRect = new Rectangle((Game.Window.ClientBounds.Width - texture.Width)/2,
                                              (Game.Window.ClientBounds.Height - texture.Height)/2, texture.Width,
                                              texture.Height);
                    break;
                case DrawMode.Stretch:
                    imageRect = new Rectangle(0, 0, Game.Window.ClientBounds.Width, game.Window.ClientBounds.Height);
                    break;
            }
        }
예제 #29
0
        /// <summary>
        /// Creates a color plate with wrapper, placeholder and other default prefs set
        /// </summary>
        /// <param name="graphicsDevice"></param>
        /// <param name="metrics"></param>
        /// <param name="color"></param>
        /// <param name="font"></param>
        /// <param name="palette"></param>
        /// <param name="drawMode"></param>
        public ColorPlate( GraphicsDevice graphicsDevice, Rectangle metrics, Color color, SpriteFont font, List<Color> palette, DrawMode drawMode, int velocity )
        {
            // assign provided vars to instance refs
            this.font = font;
            this.ColorPalette = palette;
            this.drawMode = drawMode;
            this.rotation = 0f;
            this.Velocity = velocity;

            // create placeholder and wrapper based on metrics
            placeholderMetrics = new Rectangle( metrics.X + placeholderOffset / 2, metrics.Y + placeholderOffset / 2, metrics.Width - placeholderOffset, metrics.Height - placeholderOffset );
            wrapperMetrics = new Rectangle( metrics.X - placeholderOffset / 2, metrics.Y - placeholderOffset / 2, metrics.Width + placeholderOffset, metrics.Height + placeholderOffset );

            // assign the textures and colors
            this.placeholder = new Texture2D( graphicsDevice, placeholderMetrics.Width, placeholderMetrics.Height );
            this.wrapper = new Texture2D( graphicsDevice, wrapperMetrics.Width, wrapperMetrics.Height );
            this.Metrics = metrics;
            this.Color = color;
            this.texture = new Texture2D( graphicsDevice, metrics.Width, metrics.Height );

            // create the texture colors for the main texture
            // fill the main texture
            this.texture.SetData<Color>( ShapeFill(graphicsDevice, metrics.Width, metrics.Height, color ) );

            // create the texture colors for the placeholder texture
            Color[] bg1 = new Color[ placeholderMetrics.Width * placeholderMetrics.Height ];
            for( int c = 0; c < bg1.Length; c++ )
                bg1[ c ] = InnerColor;

            // fill the placeholder texture
            this.placeholder.SetData<Color>( bg1 );

            // create the texture colors for the wrapper texture
            Color[] bg2 = new Color[ wrapperMetrics.Width * wrapperMetrics.Height ];
            for( int c = 0; c < bg2.Length; c++ )
                bg2[ c ] = Color.White;

            // fill the wrapper texture
            this.wrapper.SetData<Color>( bg2 );
        }
예제 #30
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="game">The game object</param>
        /// <param name="texture">Texture to draw</param>
        /// <param name="drawMode">Draw mode</param>
        public ImageComponent(Game game, Texture2D texture, DrawMode drawMode)
            : base(game)
        {
            this.texture = texture;
            this.drawMode = drawMode;
            // get the current sprite batch
            spriteBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));

            // create a rectangle with the size and position of the image
            switch (drawMode)
            {
                case DrawMode.Center:
                    imageRect = new Rectangle((Game.Window.ClientBounds.Width -
                                texture.Width) / 2, (Game.Window.ClientBounds.Height -
                                texture.Height) / 2, texture.Width, texture.Height);
                    break;
                case DrawMode.Stretch:
                    imageRect = new Rectangle(0, 0, Game.Window.ClientBounds.Width,
                                Game.Window.ClientBounds.Height);
                    break;
            }
        }
예제 #31
0
        /// <summary>
        /// 文字列を描画したテクスチャを返す(メイン処理)
        /// </summary>
        /// <param name="rectDrawn">描画された領域</param>
        /// <param name="ptOrigin">描画文字列</param>
        /// <param name="drawstr">描画文字列</param>
        /// <param name="drawmode">描画モード</param>
        /// <param name="fontColor">描画色</param>
        /// <param name="edgeColor">縁取色</param>
        /// <param name="gradationTopColor">グラデーション 上側の色</param>
        /// <param name="gradationBottomColor">グラデーション 下側の色</param>
        /// <returns>描画済テクスチャ</returns>
        protected SixLabors.ImageSharp.Image <SixLabors.ImageSharp.PixelFormats.Rgba32> DrawPrivateFont(string drawstr, DrawMode drawmode, Color fontColor, Color edgeColor, Color gradationTopColor, Color gradationBottomColor, int edge_Ratio)
        {
            if (this._fontfamily == null || drawstr == null || drawstr == "" || drawstr == " " || drawstr == " ")
            {
                // nullを返すと、その後bmp→texture処理や、textureのサイズを見て__の処理で全部例外が発生することになる。
                // それは非常に面倒なので、最小限のbitmapを返してしまう。
                // まずはこの仕様で進めますが、問題有れば(上位側からエラー検出が必要であれば)例外を出したりエラー状態であるプロパティを定義するなり検討します。
                if (drawstr != "")
                {
                    Trace.TraceWarning("DrawPrivateFont()の入力不正。最小値のbitmapを返します。");
                }
                _rectStrings = new Rectangle(0, 0, 0, 0);
                _ptOrigin    = new Point(0, 0);
                return(new SixLabors.ImageSharp.Image <SixLabors.ImageSharp.PixelFormats.Rgba32>(1, 1));
            }

            // 描画サイズを測定する
            Size stringSize;

            using (Bitmap bmptmp = new Bitmap(1, 1))
            {
                using (Graphics gtmp = Graphics.FromImage(bmptmp))
                {
                    gtmp.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    using (StringFormat sf = new StringFormat()
                    {
                        LineAlignment = StringAlignment.Far,                    // 画面下部(垂直方向位置)
                        Alignment = StringAlignment.Center,                     // 画面中央(水平方向位置)
                        FormatFlags = StringFormatFlags.NoWrap,                 // どんなに長くて単語の区切りが良くても改行しない (AioiLight)
                        Trimming = StringTrimming.None,                         // どんなに長くてもトリミングしない (AioiLight)
                    })
                    {
                        //float to int
                        SizeF fstringSize = gtmp.MeasureString(drawstr, this._font, new PointF(0, 0), sf);
                        stringSize        = new Size((int)fstringSize.Width, this._font.Height);
                        stringSize.Width += 10;                         //2015.04.01 kairera0467 ROTTERDAM NATIONの描画サイズがうまくいかんので。
                    }
                }
            }

            bool bEdge      = ((drawmode & DrawMode.Edge) == DrawMode.Edge);
            bool bGradation = ((drawmode & DrawMode.Gradation) == DrawMode.Gradation);

            // 縁取りの縁のサイズは、とりあえずフォントの大きさの(1/SkinConfig)とする
            int nEdgePt = (bEdge) ? (10 * _pt / edge_Ratio) : 0;             //SkinConfigにて設定可能に(rhimm)

            //取得した描画サイズを基に、描画先のbitmapを作成する
            Bitmap bmp = new Bitmap(stringSize.Width + nEdgePt * 2, stringSize.Height + nEdgePt * 2);

            bmp.MakeTransparent();

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.SmoothingMode     = SmoothingMode.HighQuality;
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                // レイアウト枠
                Rectangle r = new Rectangle(0, 0, stringSize.Width + nEdgePt * 2 + (Text_Correction_X * stringSize.Width / 100), stringSize.Height + nEdgePt * 2 + (Text_Correction_Y * stringSize.Height / 100));

                if (bEdge)                    // 縁取り有りの描画
                {
                    using (StringFormat sf = new StringFormat()
                    {
                        LineAlignment = StringAlignment.Far,                    // 画面下部(垂直方向位置)
                        Alignment = StringAlignment.Center,                     // 画面中央(水平方向位置)
                        FormatFlags = StringFormatFlags.NoWrap,                 // どんなに長くて単語の区切りが良くても改行しない (AioiLight)
                        Trimming = StringTrimming.None,                         // どんなに長くてもトリミングしない (AioiLight)
                    })
                    {
                        // DrawPathで、ポイントサイズを使って描画するために、DPIを使って単位変換する
                        // (これをしないと、単位が違うために、小さめに描画されてしまう)
                        float sizeInPixels = _font.SizeInPoints * g.DpiY / 72;                          // 1 inch = 72 points

                        GraphicsPath gp = new GraphicsPath();
                        gp.AddString(drawstr, this._fontfamily, (int)this._font.Style, sizeInPixels, r, sf);

                        // 縁取りを描画する
                        Pen p = new Pen(edgeColor, nEdgePt);
                        p.LineJoin = LineJoin.Round;
                        g.DrawPath(p, gp);

                        // 塗りつぶす
                        Brush br;
                        if (bGradation)
                        {
                            br = new LinearGradientBrush(r, gradationTopColor, gradationBottomColor, LinearGradientMode.Vertical);
                        }
                        else
                        {
                            br = new SolidBrush(fontColor);
                        }
                        g.FillPath(br, gp);

                        if (br != null)
                        {
                            br.Dispose();
                        }
                        br = null;
                        if (p != null)
                        {
                            p.Dispose();
                        }
                        p = null;
                        if (gp != null)
                        {
                            gp.Dispose();
                        }
                        gp = null;
                    }
                }
                else
                {
                    // 縁取りなしの描画
                    g.DrawString(drawstr, _font, new SolidBrush(fontColor), new PointF(0, 0));
                }
                _rectStrings = new Rectangle(0, 0, stringSize.Width, stringSize.Height);
                _ptOrigin    = new Point(nEdgePt * 2, nEdgePt * 2);
            }

            return(C変換.ToImageSharpImage(bmp));
        }
예제 #32
0
        /// <summary>
        /// 将共享点前移,构成2个图元组成的新的小小的索引。
        /// </summary>
        /// <param name="recognizedPrimitiveIndex0"></param>
        /// <param name="recognizedPrimitiveIndex1"></param>
        /// <param name="drawMode"></param>
        /// <param name="lastIndex0"></param>
        /// <param name="lastIndex1"></param>
        /// <returns></returns>
        private List <uint> ArrangeIndexes(
            RecognizedPrimitiveInfo recognizedPrimitiveIndex0,
            RecognizedPrimitiveInfo recognizedPrimitiveIndex1,
            DrawMode drawMode,
            out uint lastIndex0, out uint lastIndex1)
        {
            var sameIndexList = new List <uint>();
            var array0        = new List <uint>(recognizedPrimitiveIndex0.VertexIds);
            var array1        = new List <uint>(recognizedPrimitiveIndex1.VertexIds);

            array0.Sort(); array1.Sort();
            int p0 = 0, p1 = 0;

            while (p0 < array0.Count && p1 < array1.Count)
            {
                if (array0[p0] < array1[p1])
                {
                    p0++;
                }
                else if (array0[p0] > array1[p1])
                {
                    p1++;
                }
                else
                {
                    sameIndexList.Add(array0[p0]);
                    array0.RemoveAt(p0);
                    array1.RemoveAt(p1);
                }
            }

            if (array0.Count == 0 && array1.Count == 0)
            {
                throw new Exception("Two primitives are totally the same!");
            }

            if (array0.Count > 0)
            {
                lastIndex0 = array0.Last();
            }
            else
            {
                if (sameIndexList.Count == 0)
                {
                    throw new Exception("array0 is totally empty!");
                }

                lastIndex0 = sameIndexList.Last();
            }

            if (array1.Count > 0)
            {
                lastIndex1 = array1.Last();
            }
            else
            {
                if (sameIndexList.Count == 0)
                {
                    throw new Exception("array1 is totally empty!");
                }

                lastIndex1 = sameIndexList.Last();
            }

            if (lastIndex0 == lastIndex1)
            {
                throw new Exception();
            }

            var result = new List <uint>();

            result.AddRange(sameIndexList);
            result.AddRange(array0);
            result.Add(uint.MaxValue);// primitive restart index
            result.AddRange(sameIndexList);
            result.AddRange(array1);

            return(result);
        }
예제 #33
0
        public override double GetValue(double x, double y)
        {
            double frequency = Frequency.GetValue(x, y);

            x *= frequency;
            y *= frequency;

            int xInt = (x > 0.0 ? (int)x : (int)x - 1);
            int yInt = (y > 0.0 ? (int)y : (int)y - 1);

            // Get mode/method:
            VoronoiMethod   method   = (VoronoiMethod)((int)Method.GetValue(x, y));
            VoronoiDistance distance = (VoronoiDistance)((int)Distance.GetValue(x, y));
            VoronoiDraw     drawMode = (VoronoiDraw)((int)DrawMode.GetValue(x, y));

            // Get the buffer:
            double[] buffer       = DistanceBuffer;
            int      bufferLength = buffer.Length;

            // Reset mins:
            for (int i = 0; i < bufferLength; i += 2)
            {
                // Up to max:
                buffer[i] = double.MaxValue;
            }

            // Inside each unit cube, there is a seed point at a random position.  Go
            // through each of the nearby cubes until we find a cube with a seed point
            // that is closest to the specified position.
            for (int yCur = yInt - 2; yCur <= yInt + 2; yCur++)
            {
                for (int xCur = xInt - 2; xCur <= xInt + 2; xCur++)
                {
                    // Calculate the position and distance to the seed point inside of
                    // this unit cube.
                    double xPos  = xCur + ValueNoiseBasis.ValueNoise(xCur, yCur, Seed);
                    double yPos  = yCur + ValueNoiseBasis.ValueNoise(xCur, yCur, Seed + 1);
                    double xDist = xPos - x;
                    double yDist = yPos - y;
                    double dist;

                    // Sample and return at the successful point:
                    int x0 = (xPos > 0.0 ? (int)xPos : (int)xPos - 1);
                    int y0 = (yPos > 0.0 ? (int)yPos : (int)yPos - 1);

                    // Min is..
                    double min = ((double)ValueNoiseBasis.ValueNoise(x0, y0) + 1.0) * 0.5;

                    switch (distance)
                    {
                    default:
                    case VoronoiDistance.Euclidean:

                        dist = xDist * xDist + yDist * yDist;

                        if (drawMode == VoronoiDraw.Normal)
                        {
                            dist += 1.0 - min;
                        }

                        break;

                    case VoronoiDistance.Manhattan:

                        if (yDist < 0)
                        {
                            yDist = -yDist;
                        }

                        if (xDist < 0)
                        {
                            xDist = -xDist;
                        }

                        dist = xDist + yDist;

                        if (drawMode == VoronoiDraw.Normal)
                        {
                            dist += 1.0 - min;
                        }

                        dist /= 2.0;

                        break;

                    case VoronoiDistance.Chebyshev:

                        if (yDist < 0)
                        {
                            yDist = -yDist;
                        }

                        if (xDist < 0)
                        {
                            xDist = -xDist;
                        }

                        if (yDist > xDist)
                        {
                            dist = yDist;
                        }
                        else
                        {
                            dist = xDist;
                        }

                        if (drawMode == VoronoiDraw.Normal)
                        {
                            if (dist < min)
                            {
                                dist = min;
                            }
                        }

                        break;

                    case VoronoiDistance.Minkowski:

                        if (yDist < 0)
                        {
                            yDist = -yDist;
                        }

                        if (xDist < 0)
                        {
                            xDist = -xDist;
                        }

                        double minkowskiNumber = MinkowskiNumber.GetValue(x, y);

                        dist = System.Math.Pow((System.Math.Pow(xDist, minkowskiNumber) + System.Math.Pow(yDist, minkowskiNumber)), 1.0 / minkowskiNumber);

                        if (drawMode == VoronoiDraw.Normal)
                        {
                            if (dist < min)
                            {
                                dist = min;
                            }
                        }

                        break;
                    }



                    // Note: The nearest is at [0].
                    for (int i = 0; i < bufferLength; i += 2)
                    {
                        // Up to max:
                        if (dist < buffer[i])
                        {
                            // This seed point is closer than the one at buffer[i/2].
                            // Push i onwards over by 2 places as the entry here
                            // and all after it are now further away.
                            int offset = i + 2;

                            if (bufferLength != offset)
                            {
                                Array.Copy(buffer, i, buffer, offset, bufferLength - offset);
                            }

                            // Write this:
                            buffer[i]     = dist;
                            buffer[i + 1] = min;

                            // Stop there.
                            break;
                        }
                    }
                }
            }

            // Buffer now contains n nodes. The nearest one is at the start of the buffer.


            double value;

            // Special case for euclidean - we used basic lengths for speed:

            if (distance == VoronoiDistance.Euclidean)
            {
                // Must compute the full distance. So, for each one..
                for (int i = 0; i < bufferLength; i += 2)
                {
                    // Get complete value:
                    buffer[i] = (System.Math.Sqrt(buffer[i])) * Math.Sqrt3 - 1.0;
                }
            }

            // Next, compute the point and offset values.

            if (drawMode == VoronoiDraw.Solid)
            {
                switch (method)
                {
                default:
                case VoronoiMethod.F1:

                    // Best distance was..

                    value = buffer[1];

                    break;

                case VoronoiMethod.F2:

                    // 2nd best distance was..

                    value = buffer[3];

                    break;

                case VoronoiMethod.F3:

                    // 3rd best distance was..

                    value = buffer[5];

                    break;

                case VoronoiMethod.F4:

                    // 4th best distance was..

                    value = buffer[7];

                    break;

                case VoronoiMethod.F2minusF1:
                case VoronoiMethod.F3minusF2:
                case VoronoiMethod.F4minusF3:

                    // fN - fNm1 (but inverted):
                    value = buffer[bufferLength - 3] - buffer[bufferLength - 1] + 1.0;

                    break;

                case VoronoiMethod.Average2:
                case VoronoiMethod.Average3:
                case VoronoiMethod.Average4:

                    // Sum all of them together:
                    value = 0.0;

                    for (int i = 1; i < bufferLength; i += 2)
                    {
                        value += buffer[i];
                    }

                    // Average is then..
                    value /= (double)bufferLength;

                    break;

                case VoronoiMethod.TwoF3minusF2minusF1:

                    // 2 * f3 - f2 - f1:
                    value = 1.0 - ((2.0 * buffer[5]) - buffer[3] - buffer[1]);

                    break;
                }
            }
            else
            {
                switch (method)
                {
                default:
                case VoronoiMethod.F1:

                    // Best distance was..

                    value = buffer[0];

                    break;

                case VoronoiMethod.F2:

                    // 2nd best distance was..

                    value = buffer[2];

                    break;

                case VoronoiMethod.F3:

                    // 3rd best distance was..

                    value = buffer[4];

                    break;

                case VoronoiMethod.F4:

                    // 4th best distance was..

                    value = buffer[6];

                    break;

                case VoronoiMethod.F2minusF1:
                case VoronoiMethod.F3minusF2:
                case VoronoiMethod.F4minusF3:

                    // fN - fNm1 (but inverted):
                    value = buffer[bufferLength - 4] - buffer[bufferLength - 2] + 1.0;

                    break;

                case VoronoiMethod.Average2:
                case VoronoiMethod.Average3:
                case VoronoiMethod.Average4:

                    // Sum all of them together:
                    value = 0.0;

                    for (int i = 0; i < bufferLength; i += 2)
                    {
                        value += buffer[i];
                    }

                    // Average is then..
                    value /= (double)bufferLength;

                    break;

                case VoronoiMethod.TwoF3minusF2minusF1:

                    // 2 * f3 - f2 - f1:
                    value = 1.0 - ((2.0 * buffer[4]) - buffer[2] - buffer[0]);

                    break;
                }
            }

            // Return the calculated distance.

            if (distance == VoronoiDistance.Euclidean)
            {
                return((1.0 - value) / 2.0);
            }

            return(1.0 - value);
        }
예제 #34
0
 private void TlmRectangle_Click(object sender, EventArgs e)
 {
     this.mode       = DrawMode.RECTANGLE;
     StsCurrent.Text = "Rectangle Mode";
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <param name="x">mouse position(Left Down is (0, 0)).</param>
        /// <param name="y">mouse position(Left Down is (0, 0)).</param>
        /// <returns></returns>
        public override PickedGeometry GetPickedGeometry(RenderEventArgs arg, uint stageVertexId,
                                                         int x, int y)
        {
            uint lastVertexId;

            if (!this.GetLastVertexIdOfPickedGeometry(stageVertexId, out lastVertexId))
            {
                return(null);
            }

            PickingGeometryType geometryType = arg.PickingGeometryType;

            if (geometryType == PickingGeometryType.Point)
            {
                DrawMode            mode       = this.indexBuffer.Mode;
                PickingGeometryType typeOfMode = mode.ToGeometryType();
                if (typeOfMode == PickingGeometryType.Point)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastVertexId, mode, typeOfMode));
                }
                else if (typeOfMode == PickingGeometryType.Line)
                {
                    if (this.OnPrimitiveTest(lastVertexId, mode))
                    {
                        return(PickPoint(arg, stageVertexId, lastVertexId));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    ZeroIndexPointSearcher searcher = GetPointSearcher(mode);
                    if (searcher != null)// point is from triangle, quad or polygon
                    {
                        return(SearchPoint(arg, stageVertexId, x, y, lastVertexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else if (geometryType == PickingGeometryType.Line)
            {
                DrawMode            mode       = this.indexBuffer.Mode;
                PickingGeometryType typeOfMode = mode.ToGeometryType();
                if (geometryType == typeOfMode)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastVertexId, mode, typeOfMode));
                }
                else
                {
                    ZeroIndexLineSearcher searcher = GetLineSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchLine(arg, stageVertexId, x, y, lastVertexId, searcher));
                    }
                    else if (mode == DrawMode.Points)// want a line when rendering GL_POINTS
                    {
                        return(null);
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else
            {
                DrawMode            mode       = this.indexBuffer.Mode;
                PickingGeometryType typeOfMode = mode.ToGeometryType();
                if (typeOfMode == geometryType)// I want what it is
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastVertexId, mode, typeOfMode));
                }
                else
                {
                    return(null);
                }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }
예제 #36
0
        public override PickedGeometry Pick(RenderEventArgs arg, uint stageVertexId,
                                            int x, int y)
        {
            uint lastVertexId;

            if (!this.GetLastVertexIdOfPickedGeometry(stageVertexId, out lastVertexId))
            {
                return(null);
            }

            // 找到 lastIndexId
            RecognizedPrimitiveIndex lastIndexId = this.GetLastIndexIdOfPickedGeometry(
                arg, lastVertexId, x, y);

            if (lastIndexId == null)
            {
                Debug.WriteLine(
                    "Got lastVertexId[{0}] but no lastIndexId! Params are [{1}] [{2}] [{3}] [{4}]",
                    lastVertexId, arg, stageVertexId, x, y);
                { return(null); }
            }

            GeometryType geometryType = arg.PickingGeometryType;
            DrawMode     mode         = this.indexBufferPtr.Mode;
            GeometryType typeOfMode   = mode.ToGeometryType();

            if (geometryType == GeometryType.Point)
            {
                // 获取pickedGeometry
                if (typeOfMode == GeometryType.Point)
                {
                    return(PickWhateverItIs(stageVertexId, lastIndexId, typeOfMode));
                }
                else if (typeOfMode == GeometryType.Line)
                {
                    if (this.OnPrimitiveTest(lastVertexId, mode))
                    {
                        return(PickPoint(stageVertexId, lastVertexId));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    OneIndexPointSearcher searcher = GetPointSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchPoint(arg, stageVertexId, x, y, lastVertexId, lastIndexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else if (geometryType == GeometryType.Line)
            {
                // 获取pickedGeometry
                if (geometryType == typeOfMode)
                {
                    return(PickWhateverItIs(stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    OneIndexLineSearcher searcher = GetLineSearcher(mode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchLine(arg, stageVertexId, x, y, lastVertexId, lastIndexId, searcher));
                    }
                    else if (mode == DrawMode.Points)// want a line when rendering GL_POINTS
                    {
                        return(null);
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", mode));
                    }
                }
            }
            else
            {
                if (typeOfMode == geometryType)// I want what it is
                {
                    return(PickWhateverItIs(stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    return(null);
                }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }
예제 #37
0
 private void TlmCurvedLine_Click(object sender, EventArgs e)
 {
     this.mode       = DrawMode.CURVED_LINE;
     StsCurrent.Text = "CurvedLine Mode";
 }
예제 #38
0
        /// <summary>
        /// Creates a <see cref="OneIndexBuffer"/> object directly in server side(GPU) without initializing its value.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="type"></param>
        /// <param name="mode"></param>
        /// <param name="usage"></param>
        /// <returns></returns>
        public static OneIndexBuffer GenIndexBuffer <T>(this T[] array, IndexBufferElementType type, DrawMode mode, BufferUsage usage) where T : struct
        {
            GCHandle pinned = GCHandle.Alloc(array, GCHandleType.Pinned);
            IntPtr   header = pinned.AddrOfPinnedObject();
            // same result with: IntPtr header = Marshal.UnsafeAddrOfPinnedArrayElement(array, 0);
            UnmanagedArrayBase unmanagedArray = new TempUnmanagedArray <T>(header, array.Length);// It's not neecessary to call Dispose() for this unmanaged array.
            int byteLength = unmanagedArray.ByteLength;

            uint[] buffers = new uint[1];
            {
                glGenBuffers(1, buffers);
                const uint target = GL.GL_ELEMENT_ARRAY_BUFFER;
                glBindBuffer(target, buffers[0]);
                glBufferData(target, byteLength, unmanagedArray.Header, (uint)usage);
                glBindBuffer(target, 0);
            }
            pinned.Free();

            var buffer = new OneIndexBuffer(
                buffers[0], mode, type, byteLength / type.GetSize(), byteLength);

            return(buffer);
        }
예제 #39
0
 /// <summary>
 /// 生成一个用于存储索引的VBO。索引指定了<see cref="VertexBuffer"/>里各个顶点的渲染顺序。
 /// Generates a Vertex Buffer Object storing vertexes' indexes, which indicate the rendering order of each vertex.
 /// </summary>
 /// <param name="array"></param>
 /// <param name="mode">用哪种方式渲染各个顶点?(GL.GL_TRIANGLES etc.)</param>
 /// <param name="usage"></param>
 /// <param name="primCount">primCount in instanced rendering.</param>
 /// <returns></returns>
 public static OneIndexBuffer GenIndexBuffer(this uint[] array, DrawMode mode, BufferUsage usage, int primCount = 1)
 {
     return(GenIndexBuffer <uint>(array, mode, usage, primCount));
 }
예제 #40
0
 internal FloatingDrawingContext(Worksheet worksheet, DrawMode drawMode, IRenderer r)
     : base(worksheet, drawMode, r)
 {
 }
예제 #41
0
 /// <summary>
 /// 没有显式索引时的渲染方法。
 /// </summary>
 /// <param name="bufferID">用GL.GenBuffers()得到的VBO的ID。</param>
 /// <param name="mode">用哪种方式渲染各个顶点?(OpenGL.GL_TRIANGLES etc.)</param>
 ///<param name="firstVertex">要渲染的第一个顶点的索引</param>
 /// <param name="vertexCount">要渲染多少个顶点?</param>
 internal ZeroIndexBufferPointer(DrawMode mode, int firstVertex, int vertexCount)
     : base(mode, 0)
 {
     this.FirstVertex = firstVertex;
     this.VertexCount = vertexCount;
 }
예제 #42
0
 public override void DrawIndexedVb(DrawMode mode, int indicesCount, int startIndex)
 {
     setupBatchFunc();
     GL.DrawElements(modeMappings[(int)mode], indicesCount, indexType, new IntPtr(startIndex * 2));
 }
예제 #43
0
        /// <summary>
        /// 文字列を描画したテクスチャを返す(メイン処理)
        /// </summary>
        /// <param name="rectDrawn">描画された領域</param>
        /// <param name="ptOrigin">描画文字列</param>
        /// <param name="drawstr">描画文字列</param>
        /// <param name="drawmode">描画モード</param>
        /// <param name="fontColor">描画色</param>
        /// <param name="edgeColor">縁取色</param>
        /// <param name="gradationTopColor">グラデーション 上側の色</param>
        /// <param name="gradationBottomColor">グラデーション 下側の色</param>
        /// <returns>描画済テクスチャ</returns>
        protected Bitmap DrawPrivateFont(string drawstr, DrawMode drawmode, Color fontColor, Color edgeColor, Color gradationTopColor, Color gradationBottomColor)
        {
            if (this._fontfamily == null || drawstr == null || drawstr == "")
            {
                // nullを返すと、その後bmp→texture処理や、textureのサイズを見て__の処理で全部例外が発生することになる。
                // それは非常に面倒なので、最小限のbitmapを返してしまう。
                // まずはこの仕様で進めますが、問題有れば(上位側からエラー検出が必要であれば)例外を出したりエラー状態であるプロパティを定義するなり検討します。
                if (drawstr != "")
                {
                    Trace.TraceWarning("DrawPrivateFont()の入力不正。最小値のbitmapを返します。");
                }
                _rectStrings = new Rectangle(0, 0, 0, 0);
                _ptOrigin    = new Point(0, 0);
                return(new Bitmap(1, 1));
            }
            bool bEdge      = ((drawmode & DrawMode.Edge) == DrawMode.Edge);
            bool bGradation = ((drawmode & DrawMode.Gradation) == DrawMode.Gradation);

            // 縁取りの縁のサイズは、とりあえずフォントの大きさの1/4とする
            //int nEdgePt = (bEdge)? _pt / 4 : 0;
            //int nEdgePt = (bEdge) ? (_pt / 3) : 0; // 縁取りが少なすぎるという意見が多かったため変更。 (AioiLight)
            int nEdgePt = (bEdge) ? (10 * _pt / TJAPlayer4.Skin.Font_Edge_Ratio) : 0; //SkinConfigにて設定可能に(rhimm)

            // 描画サイズを測定する
            Size stringSize = System.Windows.Forms.TextRenderer.MeasureText(drawstr, this._font, new Size(int.MaxValue, int.MaxValue),
                                                                            System.Windows.Forms.TextFormatFlags.NoPrefix |
                                                                            System.Windows.Forms.TextFormatFlags.NoPadding
                                                                            );

            stringSize.Width += 10; //2015.04.01 kairera0467 ROTTERDAM NATIONの描画サイズがうまくいかんので。

            //取得した描画サイズを基に、描画先のbitmapを作成する
            Bitmap bmp = new Bitmap(stringSize.Width + nEdgePt * 2, stringSize.Height + nEdgePt * 2);

            bmp.MakeTransparent();
            Graphics g = Graphics.FromImage(bmp);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Far;      // 画面下部(垂直方向位置)
            sf.Alignment     = StringAlignment.Center;   // 画面中央(水平方向位置)
            sf.FormatFlags   = StringFormatFlags.NoWrap; // どんなに長くて単語の区切りが良くても改行しない (AioiLight)
            sf.Trimming      = StringTrimming.None;      // どんなに長くてもトリミングしない (AioiLight)
            // レイアウト枠
            Rectangle r = new Rectangle(0, 0, stringSize.Width + nEdgePt * 2 + (TJAPlayer4.Skin.Text_Correction_X * stringSize.Width / 100), stringSize.Height + nEdgePt * 2 + (TJAPlayer4.Skin.Text_Correction_Y * stringSize.Height / 100));

            if (bEdge)                  // 縁取り有りの描画
            {
                // DrawPathで、ポイントサイズを使って描画するために、DPIを使って単位変換する
                // (これをしないと、単位が違うために、小さめに描画されてしまう)
                float sizeInPixels = _font.SizeInPoints * g.DpiY / 72;                  // 1 inch = 72 points

                System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
                gp.AddString(drawstr, this._fontfamily, (int)this._font.Style, sizeInPixels, r, sf);

                // 縁取りを描画する
                Pen p = new Pen(edgeColor, nEdgePt);
                p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                g.DrawPath(p, gp);

                // 塗りつぶす
                Brush br;
                if (bGradation)
                {
                    br = new LinearGradientBrush(r, gradationTopColor, gradationBottomColor, LinearGradientMode.Vertical);
                }
                else
                {
                    br = new SolidBrush(fontColor);
                }
                g.FillPath(br, gp);

                if (br != null)
                {
                    br.Dispose();
                }
                br = null;
                if (p != null)
                {
                    p.Dispose();
                }
                p = null;
                if (gp != null)
                {
                    gp.Dispose();
                }
                gp = null;
            }
            else
            {
                // 縁取りなしの描画
                System.Windows.Forms.TextRenderer.DrawText(g, drawstr, _font, new Point(0, 0), fontColor);
            }
#if debug表示
            g.DrawRectangle(new Pen(Color.White, 1), new Rectangle(1, 1, stringSize.Width - 1, stringSize.Height - 1));
            g.DrawRectangle(new Pen(Color.Green, 1), new Rectangle(0, 0, bmp.Width - 1, bmp.Height - 1));
#endif
            _rectStrings = new Rectangle(0, 0, stringSize.Width, stringSize.Height);
            _ptOrigin    = new Point(nEdgePt * 2, nEdgePt * 2);


            #region [ リソースを解放する ]
            if (sf != null)
            {
                sf.Dispose();
            }
            sf = null;
            if (g != null)
            {
                g.Dispose();
            }
            g = null;
            #endregion

            return(bmp);
        }
예제 #44
0
 /// <summary>
 /// I don't know how to implement this method in a high effitiency way.
 /// So keep it like this.
 /// Also, why would someone use glDrawElements() when rendering GL_POINTS?
 /// </summary>
 /// <param name="lastVertexId"></param>
 /// <param name="mode"></param>
 /// <returns></returns>
 private bool OnPrimitiveTest(uint lastVertexId, DrawMode mode)
 {
     return(true);
 }
예제 #45
0
 private void TlmCircle_Click(object sender, EventArgs e)
 {
     this.mode       = DrawMode.CIRCLE;
     StsCurrent.Text = "Circle Mode";
 }
예제 #46
0
 /// <summary>
 /// Wraps glDrawArrays(uint mode, int first, int count).
 /// </summary>
 /// <param name="mode">用哪种方式渲染各个顶点?(GL.GL_TRIANGLES etc.)</param>
 /// <param name="maxVertexCount">一共有多少个元素?<para>How many vertexes in total?</para></param>
 public DrawArraysCmd(DrawMode mode, int maxVertexCount)
     : this(mode, maxVertexCount, 0, maxVertexCount)
 {
 }
예제 #47
0
 private void TlmLine_Click(object sender, EventArgs e)
 {
     this.mode       = DrawMode.LINE;
     StsCurrent.Text = "Line Mode";
 }
예제 #48
0
 /// <summary>
 /// 索引buffer渲染器的基类。
 /// <para>Base type for Vertex Buffer Object' pointer storing vertex' index.</para>
 /// </summary>
 /// <param name="mode"></param>
 /// <param name="bufferId"></param>
 /// <param name="length">此VBO含有多个个元素?<para>How many elements?</para></param>
 /// <param name="byteLength">此VBO中的数据在内存中占用多少个字节?<para>How many bytes in this buffer?</para></param>
 /// <param name="primCount">primCount in instanced rendering.</param>
 internal IndexBuffer(DrawMode mode, uint bufferId, int length, int byteLength, int primCount)
     : base(bufferId, length, byteLength)
 {
     this.Mode      = mode;
     this.PrimCount = primCount;
 }
        private PickedGeometry PickWhateverItIs(RenderEventArgs arg, uint stageVertexId, uint lastVertexId, DrawMode mode, PickingGeometryType typeOfMode)
        {
            //PickedGeometry pickedGeometry = new PickedGeometry();
            //pickedGeometry.GeometryType = typeOfMode;
            //pickedGeometry.StageVertexId = stageVertexId;
            //pickedGeometry.FromRenderer = this;

            // Fill primitive's position information.
            int vertexCount = typeOfMode.GetVertexCount();

            if (vertexCount == -1)
            {
                vertexCount = this.PositionBuffer.Length;
            }

            uint[] vertexIds; vec3[] positions;

            if (lastVertexId == 0 && vertexCount == 2)
            {
                // This is when mode is GL_LINE_LOOP and picked last line(the loop back one)
                PickingLastLineInLineLoop(out vertexIds, out positions);
            }
            else
            {
                // Other conditions
                switch (typeOfMode)
                {
                case PickingGeometryType.Point:
                    vertexIds = new uint[] { lastVertexId, };
                    positions = FillPickedGeometrysPosition(lastVertexId, 1);
                    break;

                case PickingGeometryType.Line:
                    vertexIds = new uint[] { lastVertexId - 1, lastVertexId, };
                    positions = FillPickedGeometrysPosition(lastVertexId - 1, 2);
                    break;

                case PickingGeometryType.Triangle:
                    if (mode == DrawMode.TriangleFan)
                    {
                        vertexIds = new uint[] { 0, lastVertexId - 1, lastVertexId, };
                        positions = FillPickedGeometrysPosition(vertexIds);
                    }
                    else if (mode == DrawMode.TrianglesAdjacency || mode == DrawMode.TriangleStripAdjacency)
                    {
                        vertexIds = new uint[] { lastVertexId - 4, lastVertexId - 2, lastVertexId, };
                        positions = FillPickedGeometrysPosition(vertexIds);
                    }
                    else
                    {
                        vertexIds = new uint[] { lastVertexId - 2, lastVertexId - 1, lastVertexId, };
                        positions = FillPickedGeometrysPosition(lastVertexId - 2, 3);
                    }
                    break;

                case PickingGeometryType.Quad:
                    vertexIds = new uint[] { lastVertexId - 3, lastVertexId - 2, lastVertexId - 1, lastVertexId, };
                    positions = FillPickedGeometrysPosition(lastVertexId - 3, 4);
                    break;

                case PickingGeometryType.Polygon:
                    vertexIds = new uint[vertexCount];
                    for (uint i = 0; i < vertexCount; i++)
                    {
                        vertexIds[i] = lastVertexId + i;
                    }
                    positions = FillPickedGeometrysPosition(0, vertexCount);
                    break;

                default:
                    throw new Exception("Unexpected PickingGeometryType!");
                }
            }

            PickedGeometry pickedGeometry = new PickedGeometry(typeOfMode, positions, vertexIds, stageVertexId, this);

            return(pickedGeometry);
        }
예제 #50
0
        protected void InitializeVAO()
        {
            this.axisPrimitiveMode = DrawMode.QuadStrip; //PrimitiveModes.QuadStrip;
            this.axisVertexCount   = faceCount * 2;
            this.vao = new uint[4];

            GL.GenVertexArrays(4, vao);

            vec3[] colors = new vec3[] { new vec3(1, 0, 0), new vec3(0, 1, 0), new vec3(0, 0, 1) };
            // 计算三个坐标轴
            for (int axisIndex = 0; axisIndex < 3; axisIndex++)
            {
                GL.BindVertexArray(vao[axisIndex]);

                //  Create a vertex buffer for the vertex data.
                {
                    UnmanagedArray <vec3> positionArray = new UnmanagedArray <vec3>(faceCount * 2);
                    for (int i = 0; i < faceCount * 2; i++)
                    {
                        int     face       = i / 2;
                        float[] components = new float[] {
                            i % 2 == 1 ? 0 : this.axisLength,
                            (float)(this.radius * Math.Cos(face * (Math.PI * 2) / faceCount)),
                            (float)(this.radius * Math.Sin(face * (Math.PI * 2) / faceCount))
                        };
                        positionArray[i] = new vec3(
                            components[(0 + axisIndex) % 3], components[(2 + axisIndex) % 3], components[(4 + axisIndex) % 3]);
                    }

                    uint positionLocation = shaderProgram.GetAttributeLocation(strin_Position);

                    uint[] ids = new uint[1];
                    GL.GenBuffers(1, ids);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, ids[0]);
                    GL.BufferData(BufferTarget.ArrayBuffer, positionArray, BufferUsage.StaticDraw);
                    GL.VertexAttribPointer(positionLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero);
                    GL.EnableVertexAttribArray(positionLocation);
                    positionArray.Dispose();
                }

                //  Now do the same for the colour data.
                {
                    UnmanagedArray <vec3> colorArray = new UnmanagedArray <vec3>(faceCount * 2);
                    for (int i = 0; i < colorArray.Length; i++)
                    {
                        colorArray[i] = colors[axisIndex];
                    }

                    uint colorLocation = shaderProgram.GetAttributeLocation(strin_Color);

                    uint[] ids = new uint[1];
                    GL.GenBuffers(1, ids);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, ids[0]);
                    GL.BufferData(BufferTarget.ArrayBuffer, colorArray, BufferUsage.StaticDraw);
                    GL.VertexAttribPointer(colorLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero);
                    GL.EnableVertexAttribArray(colorLocation);
                    colorArray.Dispose();
                }
                {
                    UnmanagedArray <uint> cylinderIndex = new UnmanagedArray <uint>(faceCount * 2 + 2);
                    for (int i = 0; i < cylinderIndex.Length - 2; i++)
                    {
                        cylinderIndex[i] = (uint)i;
                    }
                    cylinderIndex[cylinderIndex.Length - 2] = 0;
                    cylinderIndex[cylinderIndex.Length - 1] = 1;

                    uint[] ids = new uint[1];
                    GL.GenBuffers(1, ids);
                    GL.BindBuffer(BufferTarget.ElementArrayBuffer, ids[0]);
                    GL.BufferData(BufferTarget.ElementArrayBuffer, cylinderIndex, BufferUsage.StaticDraw);
                    cylinderIndex.Dispose();
                }
                //  Unbind the vertex array, we've finished specifying data for it.
                GL.BindVertexArray(0);
            }
            // 计算XZ平面
            {
                this.planPrimitveMode = DrawMode.LineLoop;
                this.planVertexCount  = 4;

                GL.BindVertexArray(vao[3]);

                //  Create a vertex buffer for the vertex data.
                {
                    UnmanagedArray <vec3> plan = new UnmanagedArray <vec3>(4);
                    float length = this.axisLength;
                    plan[0] = new vec3(-length, 0, -length);
                    plan[1] = new vec3(-length, 0, length);
                    plan[2] = new vec3(length, 0, length);
                    plan[3] = new vec3(length, 0, -length);

                    uint positionLocation = shaderProgram.GetAttributeLocation(strin_Position);

                    uint[] ids = new uint[1];
                    GL.GenBuffers(1, ids);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, ids[0]);
                    GL.BufferData(BufferTarget.ArrayBuffer, plan, BufferUsage.StaticDraw);
                    GL.VertexAttribPointer(positionLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero);
                    GL.EnableVertexAttribArray(positionLocation);

                    plan.Dispose();
                }

                //  Now do the same for the colour data.
                {
                    UnmanagedArray <vec3> colorArray = new UnmanagedArray <vec3>(4);
                    for (int i = 0; i < colorArray.Length; i++)
                    {
                        colorArray[i] = this.planColor;
                    }

                    uint colorLocation = shaderProgram.GetAttributeLocation(strin_Color);

                    uint[] ids = new uint[1];
                    GL.GenBuffers(1, ids);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, ids[0]);
                    GL.BufferData(BufferTarget.ArrayBuffer, colorArray, BufferUsage.StaticDraw);
                    GL.VertexAttribPointer(colorLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero);
                    GL.EnableVertexAttribArray(colorLocation);

                    colorArray.Dispose();
                }

                //  Unbind the vertex array, we've finished specifying data for it.
                GL.BindVertexArray(0);
            }
        }
        /// <summary>
        /// 现在,已经判定了鼠标在某个点上。
        /// 我需要判定此点是否出现在图元上。
        /// now that I know the mouse is picking on some point,
        /// I need to make sure that point should appear.
        /// </summary>
        /// <param name="lastVertexId"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        private bool OnPrimitiveTest(uint lastVertexId, DrawMode mode)
        {
            bool result      = false;
            var  indexBuffer = this.indexBuffer as ZeroIndexBuffer;
            int  first       = indexBuffer.FirstVertex;

            if (first < 0)
            {
                return(false);
            }
            int vertexCount = indexBuffer.RenderingVertexCount;

            if (vertexCount <= 0)
            {
                return(false);
            }
            int last = first + vertexCount - 1;

            switch (mode)
            {
            case DrawMode.Points:
                result = true;
                break;

            case DrawMode.LineStrip:
                result = vertexCount > 1;
                break;

            case DrawMode.LineLoop:
                result = vertexCount > 1;
                break;

            case DrawMode.Lines:
                if (vertexCount > 1)
                {
                    if (vertexCount % 2 == 0)
                    {
                        result = (first <= lastVertexId && lastVertexId <= last);
                    }
                    else
                    {
                        result = (first <= lastVertexId && lastVertexId <= last - 1);
                    }
                }
                break;

            case DrawMode.LineStripAdjacency:
                if (vertexCount > 3)
                {
                    result = (first < lastVertexId && lastVertexId < last);
                }
                break;

            case DrawMode.LinesAdjacency:
                if (vertexCount > 3)
                {
                    var lastPart = last - (last + 1 - first) % 4;
                    if (first <= lastVertexId && lastVertexId <= lastPart)
                    {
                        var m = (lastVertexId - first) % 4;
                        result = (m == 1 || m == 2);
                    }
                }
                break;

            case DrawMode.TriangleStrip:
                if (vertexCount > 2)
                {
                    result = vertexCount > 2;
                }
                break;

            case DrawMode.TriangleFan:
                if (vertexCount > 2)
                {
                    result = vertexCount > 2;
                }
                break;

            case DrawMode.Triangles:
                if (vertexCount > 2)
                {
                    if (first <= lastVertexId)
                    {
                        result = ((vertexCount % 3 == 0) && (lastVertexId <= last)) ||
                                 ((vertexCount % 3 == 1) && (lastVertexId < last)) ||
                                 ((vertexCount % 3 == 2) && (lastVertexId + 1 < last));
                    }
                }
                break;

            case DrawMode.TriangleStripAdjacency:
                if (vertexCount > 5)
                {
                    var lastPart = last - (last + 1 - first) % 2;
                    if (first <= lastVertexId && lastVertexId <= lastPart)
                    {
                        result = (lastVertexId - first) % 2 == 0;
                    }
                }
                break;

            case DrawMode.TrianglesAdjacency:
                if (vertexCount > 5)
                {
                    var lastPart = last - (last + 1 - first) % 6;
                    if (first <= lastVertexId && lastVertexId <= lastPart)
                    {
                        result = (lastVertexId - first) % 2 == 0;
                    }
                }
                break;

            case DrawMode.Patches:
                // TODO: not know what to do for now
                break;

            case DrawMode.QuadStrip:
                if (vertexCount > 3)
                {
                    if (first <= lastVertexId && lastVertexId <= last)
                    {
                        result = (vertexCount % 2 == 0) ||
                                 (lastVertexId < last);
                    }
                }
                break;

            case DrawMode.Quads:
                if (vertexCount > 3)
                {
                    if (first <= lastVertexId && lastVertexId <= last)
                    {
                        var m = vertexCount % 4;
                        if (m == 0)
                        {
                            result = true;
                        }
                        else if (m == 1)
                        {
                            result = lastVertexId + 0 < last;
                        }
                        else if (m == 2)
                        {
                            result = lastVertexId + 1 < last;
                        }
                        else if (m == 3)
                        {
                            result = lastVertexId + 2 < last;
                        }
                        else
                        {
                            throw new Exception("This should never happen!");
                        }
                    }
                }
                break;

            case DrawMode.Polygon:
                if (vertexCount > 2)
                {
                    result = (first <= lastVertexId && lastVertexId <= last);
                }
                break;

            default:
                throw new Exception("Unexpected DrawMode!");
            }

            return(result);
        }
예제 #52
0
 /// <summary>
 /// Wraps glDrawArrays(uint mode, int first, int count).
 /// </summary>
 /// <param name="mode">用哪种方式渲染各个顶点?(GL.GL_TRIANGLES etc.)</param>
 /// <param name="firstVertex">要渲染的第一个顶点的位置。<para>Index of first vertex to be rendered.</para></param>
 /// <param name="vertexCount">要渲染多少个元素?<para>How many vertexes to be rendered?</para></param>
 /// <param name="primCount">primCount in instanced rendering.</param>
 /// <param name="frameCount">How many frames are there?</param>
 internal ZeroIndexBuffer(DrawMode mode, int firstVertex, int vertexCount, int primCount = 1, int frameCount = 1)
     : base(mode, 0, firstVertex, vertexCount, vertexCount * sizeof(uint), primCount, frameCount)
 {
     this.Target = BufferTarget.ZeroIndexArrayBuffer;
 }
예제 #53
0
        protected new Bitmap DrawPrivateFont(string drawstr, DrawMode drawmode, Color fontColor, Color edgeColor, Color gradationTopColor, Color gradationBottomColor)
        {
            #region [ 以前レンダリングしたことのある文字列/フォントか? (キャッシュにヒットするか?) ]
            int index = listFontCache.FindIndex(
                delegate(FontCache fontcache)
            {
                return(
                    drawstr == fontcache.drawstr &&
                    drawmode == fontcache.drawmode &&
                    fontColor == fontcache.fontColor &&
                    edgeColor == fontcache.edgeColor &&
                    gradationTopColor == fontcache.gradationTopColor &&
                    gradationBottomColor == fontcache.gradationBottomColor
                    // _font == fontcache.font
                    );
            }
                );
            #endregion
            if (index < 0)
            {
                // キャッシュにヒットせず。
                #region [ レンダリングして、キャッシュに登録 ]
                FontCache fc = new FontCache();
                fc.bmp                  = base.DrawPrivateFont(drawstr, drawmode, fontColor, edgeColor, gradationTopColor, gradationBottomColor);
                fc.drawstr              = drawstr;
                fc.drawmode             = drawmode;
                fc.fontColor            = fontColor;
                fc.edgeColor            = edgeColor;
                fc.gradationTopColor    = gradationTopColor;
                fc.gradationBottomColor = gradationBottomColor;
                fc.rectStrings          = RectStrings;
                fc.ptOrigin             = PtOrigin;
                listFontCache.Add(fc);
                Debug.WriteLine(drawstr + ": Cacheにヒットせず。(cachesize=" + listFontCache.Count + ")");
                #endregion
                #region [ もしキャッシュがあふれたら、最も古いキャッシュを破棄する ]
                if (listFontCache.Count > MAXCACHESIZE)
                {
                    Debug.WriteLine("Cache溢れ。" + listFontCache[0].drawstr + " を解放します。");
                    if (listFontCache[0].bmp != null)
                    {
                        listFontCache[0].bmp.Dispose();
                    }
                    listFontCache.RemoveAt(0);
                }
                #endregion

                // 呼び出し元のDispose()でキャッシュもDispose()されないように、Clone()で返す。
                return((Bitmap)listFontCache[listFontCache.Count - 1].bmp.Clone());
            }
            else
            {
                Debug.WriteLine(drawstr + ": Cacheにヒット!! index=" + index);
                #region [ キャッシュにヒット。レンダリングは行わず、キャッシュ内のデータを返して終了。]
                RectStrings = listFontCache[index].rectStrings;
                PtOrigin    = listFontCache[index].ptOrigin;
                // 呼び出し元のDispose()でキャッシュもDispose()されないように、Clone()で返す。
                return((Bitmap)listFontCache[index].bmp.Clone());

                #endregion
            }
        }
예제 #54
0
 // Token: 0x060001A1 RID: 417 RVA: 0x00002B92 File Offset: 0x00000D92
 static void smethod_30(ListBox listBox_1, DrawMode drawMode_0)
 {
     listBox_1.DrawMode = drawMode_0;
 }
예제 #55
0
        private async Task <DrawingItem> MakeShapeItem(DrawMode mode, string name)
        {
            this.IsPanMode = true;
            //ResetMode(mode);

            var drawing = await this.GetDrawingAsync(mode, true);

            if (drawing == null)
            {
                return(null);
            }

            var shapeItem = new DrawingItem()
            {
                Geometry = drawing
            };

            shapeItem.Title = name;

            shapeItem.RemoveAction = () =>
            {
                this.DrawingItems.Remove(shapeItem);
                this.RemoveLayer(shapeItem.AssociatedLayer);
                this.Refresh();
            };

            shapeItem.EditAction = async() =>
            {
                this.RemoveLayer(shapeItem.AssociatedLayer);

                var edittedShape = await this.Edit(shapeItem.Geometry, new EditableFeatureLayerOptions()
                {
                    IsDeleteButtonVisible = true, IsCancelButtonVisible = true, IsFinishButtonVisible = true
                });

                if (edittedShape != null)
                {
                    shapeItem.Geometry        = edittedShape;
                    shapeItem.AssociatedLayer = new VectorLayer(shapeItem.Title, new List <SqlGeometry>()
                    {
                        edittedShape.AsSqlGeometry()
                    }, VisualParameters.GetRandomVisualParameters(), LayerType.VectorLayer, RenderingApproach.Default, RasterizationApproach.DrawingVisual);

                    this.SetLayer(shapeItem.AssociatedLayer);
                    Refresh();
                }
            };

            shapeItem.RequestZoomToGeometry = (g) => { this.ZoomToExtent(g.Geometry.GetBoundingBox()); };

            shapeItem.RequestDownload = (s) =>
            {
                //this.OnRequestShowDownloadDialog?.Invoke(s);
            };

            shapeItem.AssociatedLayer = new VectorLayer(shapeItem.Title, new List <SqlGeometry>()
            {
                drawing.AsSqlGeometry()
            }, VisualParameters.GetRandomVisualParameters(), LayerType.VectorLayer, RenderingApproach.Default, RasterizationApproach.DrawingVisual);

            return(shapeItem);
        }
예제 #56
0
 public void OnDrawModeChanged()
 {
     drawMode = (DrawMode)DrawModeDropdown.value;
     RefreshUI();
 }
예제 #57
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="stageVertexId"></param>
        /// <returns></returns>
        public override PickedGeometry GetPickedGeometry(PickingEventArgs arg, uint stageVertexId)
        {
            PickableNode node = this.Renderer;

            uint lastVertexId;

            if (!node.GetLastVertexIdOfPickedGeometry(stageVertexId, out lastVertexId))
            {
                return(null);
            }

            // 找到 lastIndexId
            RecognizedPrimitiveInfo lastIndexId = this.GetLastIndexIdOfPickedGeometry(
                arg, lastVertexId);

            if (lastIndexId == null)
            {
                Debug.WriteLine(string.Format(
                                    "Got lastVertexId[{0}] but no lastIndexId! Params are [{1}] [{2}]",
                                    lastVertexId, arg, stageVertexId));
                { return(null); }
            }

            PickingGeometryTypes geometryType = arg.GeometryType;
            DrawMode             drawMode     = node.PickingRenderUnit.VertexArrayObject.IndexBuffer.Mode;
            GeometryType         typeOfMode   = drawMode.ToGeometryType();

            if ((geometryType & PickingGeometryTypes.Point) == PickingGeometryTypes.Point)
            {
                // 获取pickedGeometry
                if (typeOfMode == GeometryType.Point)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastIndexId, typeOfMode));
                }
                else if (typeOfMode == GeometryType.Line)
                {
                    if (this.OnPrimitiveTest(lastVertexId, drawMode))
                    {
                        return(PickPoint(arg, stageVertexId, lastVertexId));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    OneIndexPointSearcher searcher = GetPointSearcher(drawMode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchPoint(arg, stageVertexId, lastVertexId, lastIndexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", drawMode));
                    }
                }
            }
            else if ((geometryType & PickingGeometryTypes.Line) == PickingGeometryTypes.Line)
            {
                // 获取pickedGeometry
                if (typeOfMode == GeometryType.Point) // want a line when rendering GL_POINTS
                {
                    return(null);
                }
                if (typeOfMode == GeometryType.Line)
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    OneIndexLineSearcher searcher = GetLineSearcher(drawMode);
                    if (searcher != null)// line is from triangle, quad or polygon
                    {
                        return(SearchLine(arg, stageVertexId, lastIndexId, searcher));
                    }
                    else
                    {
                        throw new Exception(string.Format("Lack of searcher for [{0}]", drawMode));
                    }
                }
            }
            else
            {
                if (geometryType.Contains(typeOfMode)) // I want what it is
                {
                    return(PickWhateverItIs(arg, stageVertexId, lastIndexId, typeOfMode));
                }
                else
                {
                    return(null);
                }
                //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); }
            }
        }
예제 #58
0
        /// <summary>
        /// 文字列を描画したテクスチャを返す(メイン処理)
        /// </summary>
        /// <param name="rectDrawn">描画された領域</param>
        /// <param name="ptOrigin">描画文字列</param>
        /// <param name="drawstr">描画文字列</param>
        /// <param name="drawmode">描画モード</param>
        /// <param name="fontColor">描画色</param>
        /// <param name="edgeColor">縁取色</param>
        /// <param name="gradationTopColor">グラデーション 上側の色</param>
        /// <param name="gradationBottomColor">グラデーション 下側の色</param>
        /// <returns>描画済テクスチャ</returns>
        protected SixLabors.ImageSharp.Image <SixLabors.ImageSharp.PixelFormats.Rgba32> DrawPrivateFont_V(string drawstr, DrawMode drawMode, Color fontColor, Color edgeColor, int edge_Ratio)
        {
            if (this._fontfamily == null || drawstr == null || drawstr == "" || drawstr == " " || drawstr == " ")
            {
                // nullを返すと、その後bmp→texture処理や、textureのサイズを見て__の処理で全部例外が発生することになる。
                // それは非常に面倒なので、最小限のbitmapを返してしまう。
                // まずはこの仕様で進めますが、問題有れば(上位側からエラー検出が必要であれば)例外を出したりエラー状態であるプロパティを定義するなり検討します。
                if (drawstr != "")
                {
                    Trace.TraceWarning("DrawPrivateFont()の入力不正。最小値のbitmapを返します。");
                }
                _rectStrings = new Rectangle(0, 0, 0, 0);
                _ptOrigin    = new Point(0, 0);
                return(new SixLabors.ImageSharp.Image <SixLabors.ImageSharp.PixelFormats.Rgba32>(1, 1));
            }

            drawstr = drawstr.Replace("・", ".");

            string[] strName = new string[drawstr.Length];
            for (int i = 0; i < drawstr.Length; i++)
            {
                strName[i] = drawstr.Substring(i, 1);
            }

            #region [ キャンバスの大きさ予測 ]
            //大きさを計算していく。
            int nHeight = 0;
            for (int i = 0; i < strName.Length; i++)
            {
                Size strSize;
                using (Bitmap bmptmp = new Bitmap(1, 1))
                {
                    using (Graphics gtmp = Graphics.FromImage(bmptmp))
                    {
                        using (
                            StringFormat sf = new StringFormat()
                        {
                            LineAlignment = StringAlignment.Far,                        // 画面下部(垂直方向位置)
                            Alignment = StringAlignment.Center,                         // 画面中央(水平方向位置)
                            FormatFlags = StringFormatFlags.NoWrap,                     // どんなに長くて単語の区切りが良くても改行しない (AioiLight)
                            Trimming = StringTrimming.None,                             // どんなに長くてもトリミングしない (AioiLight)
                        })
                        {
                            //float to int
                            SizeF fstringSize = gtmp.MeasureString(strName[i], this._font, new PointF(0, 0), sf);
                            strSize = new Size((int)fstringSize.Width, (int)fstringSize.Height);
                        }
                    }
                }

                //stringformatは最初にやっていてもいいだろう。
                using (StringFormat sFormat = new StringFormat()
                {
                    LineAlignment = StringAlignment.Center,                 // 画面下部(垂直方向位置)
                    Alignment = StringAlignment.Center,                     // 画面中央(水平方向位置)
                })
                {
                    //できるだけ正確な値を計算しておきたい...!
                    Rectangle rect正確なサイズ = this.MeasureStringPrecisely(strName[i], strSize, sFormat, edge_Ratio);
                    int       n余白サイズ     = strSize.Height - rect正確なサイズ.Height;

                    if (strName[i] == "ー" || strName[i] == "-" || strName[i] == "~" || strName[i] == "<" || strName[i] == ">" || strName[i] == "(" || strName[i] == ")" || strName[i] == "「" || strName[i] == "」" || strName[i] == "[" || strName[i] == "]")
                    {
                        nHeight += (rect正確なサイズ.Width) + 2;
                    }
                    else if (strName[i] == "_")
                    {
                        nHeight += (rect正確なサイズ.Height) + 2;
                    }
                    else if (strName[i] == " ")
                    {
                        nHeight += (6);
                    }
                    else
                    {
                        nHeight += (rect正確なサイズ.Height) + 2;
                    }
                }
            }
            #endregion

            Bitmap bmpCambus = new Bitmap(46, nHeight);
            using (Graphics Gcambus = Graphics.FromImage(bmpCambus))
            {
                //キャンバス作成→1文字ずつ作成してキャンバスに描画という形がよさそうかな?
                int nNowPos  = 0;
                int nAdded   = 0;
                int nEdge補正X = 0;
                int nEdge補正Y = 0;
                if (this._pt < 18)
                {
                    nAdded -= 2;
                }

                for (int i = 0; i < strName.Length; i++)
                {
                    Size strSize;
                    using (Bitmap bmptmp = new Bitmap(1, 1))
                    {
                        using (Graphics gtmp = Graphics.FromImage(bmptmp))
                        {
                            using (
                                StringFormat sf = new StringFormat()
                            {
                                LineAlignment = StringAlignment.Far,                            // 画面下部(垂直方向位置)
                                Alignment = StringAlignment.Center,                             // 画面中央(水平方向位置)
                                FormatFlags = StringFormatFlags.NoWrap,                         // どんなに長くて単語の区切りが良くても改行しない (AioiLight)
                                Trimming = StringTrimming.None,                                 // どんなに長くてもトリミングしない (AioiLight)
                            })
                            {
                                //float to int
                                SizeF fstringSize = gtmp.MeasureString(strName[i], this._font, new PointF(0, 0), sf);
                                strSize = new Size((int)fstringSize.Width, (int)fstringSize.Height);
                            }
                        }
                    }

                    //stringformatは最初にやっていてもいいだろう。
                    StringFormat sFormat = new StringFormat()
                    {
                        LineAlignment = StringAlignment.Center,                     // 画面下部(垂直方向位置)
                        Alignment     = StringAlignment.Near,                       // 画面中央(水平方向位置)
                    };

                    //できるだけ正確な値を計算しておきたい...!
                    Rectangle rect正確なサイズ = this.MeasureStringPrecisely(strName[i], strSize, sFormat, edge_Ratio);
                    int       n余白サイズ     = strSize.Height - rect正確なサイズ.Height;

                    Bitmap bmpV = new Bitmap((rect正確なサイズ.Width + 6) + nAdded, (rect正確なサイズ.Height) + 6);
                    bmpV.MakeTransparent();

                    Graphics gV = Graphics.FromImage(bmpV);
                    gV.SmoothingMode = SmoothingMode.HighQuality;

                    if (CorrectionX_Chara_List_Vertical != null && CorrectionX_Chara_List_Value_Vertical != null)
                    {
                        int Xindex = Array.IndexOf(CorrectionX_Chara_List_Vertical, strName[i]);
                        if (-1 < Xindex && Xindex < CorrectionX_Chara_List_Value_Vertical.Length && strName[i].In(CorrectionX_Chara_List_Vertical))
                        {
                            nEdge補正X = CorrectionX_Chara_List_Value_Vertical[Xindex];
                        }
                        else
                        {
                            if (-1 < Xindex && CorrectionX_Chara_List_Value_Vertical.Length <= Xindex && strName[i].In(CorrectionX_Chara_List_Vertical))
                            {
                                nEdge補正X = CorrectionX_Chara_List_Value_Vertical[0];
                            }
                            else
                            {
                                nEdge補正X = 0;
                            }
                        }
                    }

                    if (CorrectionY_Chara_List_Vertical != null && CorrectionY_Chara_List_Value_Vertical != null)
                    {
                        int Yindex = Array.IndexOf(CorrectionY_Chara_List_Vertical, strName[i]);
                        if (-1 < Yindex && Yindex < CorrectionY_Chara_List_Value_Vertical.Length && strName[i].In(CorrectionY_Chara_List_Vertical))
                        {
                            nEdge補正Y = CorrectionY_Chara_List_Value_Vertical[Yindex];
                        }
                        else
                        {
                            if (-1 < Yindex && CorrectionY_Chara_List_Value_Vertical.Length <= Yindex && strName[i].In(CorrectionY_Chara_List_Vertical))
                            {
                                nEdge補正Y = CorrectionY_Chara_List_Value_Vertical[0];
                            }
                            else
                            {
                                nEdge補正Y = 0;
                            }
                        }
                    }

                    //X座標、Y座標それぞれについて、SkinConfig内でズレを直したい文字を , で区切って列挙して、
                    //補正値を記入することで、特定のそれらの文字について一括で座標をずらす。
                    //現時点では補正値をX,Y各座標について1個ずつしか取れない(複数対1)ので、
                    //文字を列挙して、同じ数だけそれぞれの文字の補正値を記入できるような枠組をつくりたい。(20181205 rhimm)←実装済み //2020.05.04 Mr-Ojii 文字ごとに補正をかけられるように。「,」区切りで書けるように。

                    Rectangle rect = new Rectangle(-3 - nAdded + (nEdge補正X * _pt / 100), -rect正確なサイズ.Y - 2 + (nEdge補正Y * _pt / 100), (strSize.Width + 12), (strSize.Height + 11));
                    //Rectangle rect = new Rectangle( 0, -rect正確なサイズ.Y - 2, 36, rect正確なサイズ.Height + 10);

                    // DrawPathで、ポイントサイズを使って描画するために、DPIを使って単位変換する
                    // (これをしないと、単位が違うために、小さめに描画されてしまう)
                    float sizeInPixels = _font.SizeInPoints * gV.DpiY / 72f;                      // 1 inch = 72 points

                    GraphicsPath gpV = new GraphicsPath();
                    gpV.AddString(strName[i], this._fontfamily, (int)this._font.Style, sizeInPixels, rect, sFormat);

                    // 縁取りを描画する
                    //int nEdgePt = (_pt / 3); // 縁取りをフォントサイズ基準に変更
                    float nEdgePt = (10f * _pt / edge_Ratio);                     // SkinConfigにて設定可能に(rhimm)
                    Pen   pV      = new Pen(edgeColor, nEdgePt);
                    pV.LineJoin = LineJoin.Round;
                    gV.DrawPath(pV, gpV);

                    // 塗りつぶす
                    Brush brV = new SolidBrush(fontColor);

                    gV.FillPath(brV, gpV);

                    if (brV != null)
                    {
                        brV.Dispose();
                    }
                    if (pV != null)
                    {
                        pV.Dispose();
                    }
                    if (gpV != null)
                    {
                        gpV.Dispose();
                    }
                    if (gV != null)
                    {
                        gV.Dispose();
                    }

                    int n補正  = 0;
                    int nY補正 = 0;

                    if (strName[i] == "ー" || strName[i] == "-" || strName[i] == "~")
                    {
                        bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        n補正 = 2;
                        if (this._pt < 20)
                        {
                            n補正 = 0;
                        }
                        //nNowPos = nNowPos - 2;
                    }
                    else if (strName[i] == "<" || strName[i] == ">" || strName[i] == "(" || strName[i] == ")" || strName[i] == "[" || strName[i] == "]" || strName[i] == "」" || strName[i] == ")" || strName[i] == "』")
                    {
                        bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        n補正 = 2;
                        if (this._pt < 20)
                        {
                            n補正 = 0;
                            //nNowPos = nNowPos - 4;
                        }
                    }
                    else if (strName[i] == "「" || strName[i] == "(" || strName[i] == "『")
                    {
                        bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        n補正 = 2;
                        if (this._pt < 20)
                        {
                            n補正 = 2;
                            //nNowPos = nNowPos;
                        }
                    }
                    else if (strName[i] == "・")
                    {
                        n補正 = -8;
                        if (this._pt < 20)
                        {
                            n補正 = -8;
                            //nNowPos = nNowPos;
                        }
                    }
                    else if (strName[i] == ".")
                    {
                        n補正 = 8;
                        if (this._pt < 20)
                        {
                            n補正 = 8;
                            //nNowPos = nNowPos;
                        }
                    }
                    else if (strName[i].In(Rotate_Chara_List_Vertical))
                    {
                        bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    }
                    //個別の文字に関して、カンマで区切ってSkinConfigに記入したものを回転させる(20181205 rhimm)
                    else if (strName[i] == " ")
                    {
                        nNowPos += 10;
                    }

                    if (i == 0)
                    {
                        nNowPos = 4;
                    }
                    Gcambus.DrawImage(bmpV, (bmpCambus.Width / 2) - (bmpV.Width / 2) + n補正, nNowPos + nY補正);
                    nNowPos += bmpV.Size.Height - 6;

                    if (bmpV != null)
                    {
                        bmpV.Dispose();
                    }

                    _rectStrings = new Rectangle(0, 0, strSize.Width, strSize.Height);
                    _ptOrigin    = new Point(6 * 2, 6 * 2);
                }
            }

            return(C変換.ToImageSharpImage(bmpCambus));
        }
예제 #59
0
 public override void DrawVb(DrawMode mode, int startVertex, int verticesCount)
 {
     setupBatchFunc();
     GL.DrawArrays(modeMappings[(int)mode], startVertex, verticesCount);
 }
        /// <summary>
        /// Convert <see cref="DrawMode"/> to <see cref="PickingGeometryType"/>.
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public static PickingGeometryType ToGeometryType(this DrawMode mode)
        {
            PickingGeometryType result = PickingGeometryType.Point;

            switch (mode)
            {
            case DrawMode.Points:
                result = PickingGeometryType.Point;
                break;

            case DrawMode.LineStrip:
                result = PickingGeometryType.Line;
                break;

            case DrawMode.LineLoop:
                result = PickingGeometryType.Line;
                break;

            case DrawMode.Lines:
                result = PickingGeometryType.Line;
                break;

            case DrawMode.LineStripAdjacency:
                result = PickingGeometryType.Line;
                break;

            case DrawMode.LinesAdjacency:
                result = PickingGeometryType.Line;
                break;

            case DrawMode.TriangleStrip:
                result = PickingGeometryType.Triangle;
                break;

            case DrawMode.TriangleFan:
                result = PickingGeometryType.Triangle;
                break;

            case DrawMode.Triangles:
                result = PickingGeometryType.Triangle;
                break;

            case DrawMode.TriangleStripAdjacency:
                result = PickingGeometryType.Triangle;
                break;

            case DrawMode.TrianglesAdjacency:
                result = PickingGeometryType.Triangle;
                break;

            case DrawMode.Patches:    // this is about tessellation shader. I've no idea about it now.
                throw new NotImplementedException();

            case DrawMode.QuadStrip:
                result = PickingGeometryType.Quad;
                break;

            case DrawMode.Quads:
                result = PickingGeometryType.Quad;
                break;

            case DrawMode.Polygon:
                result = PickingGeometryType.Polygon;
                break;

            default:
                throw new Exception("Unexpected DrawMode!");
            }

            return(result);
        }