Esempio n. 1
0
        private void Render(ConvexPolyForm poly)
        {
            if (poly == _selectedPoly)
            {
                GLUtil.SetColor(new Color(0, 0, 0, 1));
            }
            else
            {
                GLUtil.SetColor(new Color(0.1f, 0.1f, 0.1f, 0.5f));
            }
            PolyDrawer.RenderPoly(poly);

            RenderNormals(poly);
            RenderCentroid(poly);


            if (poly == _selectedPoly)
            {
                RenderNearestEdge(poly);
                RenderVerts(poly);
            }

            if (_editState == EditState.ConnectPressed)
            {
                GLUtil.SetColor(new Color(0, 0, 0, 1));
                PrimitiveDrawer.DrawLine2d(_connectStart, _input.Mouse.Position);
                RenderCrossedEdges();
            }
        }
        public void Render()
        {
            Gl.glClearColor(1, 1, 1, 0);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);

            _pathFinder.Polygons.ForEach(x => PolyDrawer.RenderPoly(x));



            if (_drawingPath)
            {
                PrimitiveDrawer.DrawFilledCircle(_pathStart, 15, new Color(0, 0, 0, 1));
            }


            GLUtil.SetColor(new Color(1, 0, 0, 1));
            Gl.glBegin(Gl.GL_LINE_STRIP);
            {
                foreach (Point p in _path)
                {
                    GLUtil.DrawPointVertex(p);
                }
            }
            Gl.glEnd();



            _renderer.DrawText(0, 0, "Path Drawing State", _font);
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
            _renderer.Render();
            Gl.glDisable(Gl.GL_TEXTURE_2D);
        }
 private void DrawPath(List <NavNode> list)
 {
     GLUtil.SetColor(new Color(0, 0, 0, 1));
     Gl.glBegin(Gl.GL_LINE_STRIP);
     {
         foreach (NavNode node in list)
         {
             GLUtil.DrawPointVertex(node.Position);
         }
     }
     Gl.glEnd();
 }
 internal static void RenderPoly(ConvexPolyForm poly)
 {
     Gl.glBegin(Gl.GL_LINE_STRIP);
     {
         foreach (Point p in poly.Vertices)
         {
             GLUtil.DrawPointVertex(p);
         }
         GLUtil.DrawPointVertex(poly.Vertices.First());
     }
     Gl.glEnd();
 }
        internal CPUFractalEngine(CPUDeviceEntry devEntry)
        {
            int fractalSize, branchesSize, variWeightsSize;

            Fractal.GetNativeFractalSizes(out fractalSize, out branchesSize, out variWeightsSize);

            //these are allocated from unmanaged memory so we don't have to worry about pinning them all the time
            fractal     = (NativeFractal *)Marshal.AllocHGlobal(fractalSize);
            branches    = (NativeBranch *)Marshal.AllocHGlobal(branchesSize);
            variWeights = (float *)Marshal.AllocHGlobal(variWeightsSize);

            int iterCount = Util.Clamp(2 * devEntry.NumCores, 2, MaxUseableIterators);

            iterators = new Iterator[iterCount];

            int dotBufferSize = Marshal.SizeOf(typeof(Dot)) * DotsPerCycle;

            dots = (Dot *)Marshal.AllocHGlobal(dotBufferSize);
            int dotIndiciesSize = Marshal.SizeOf(typeof(ushort)) * DotsPerCycle;

            dotIndicies = (ushort *)Marshal.AllocHGlobal(dotIndiciesSize);
            for (int i = 0; i < DotsPerCycle; i++)
            {
                dotIndicies[i] = (ushort)i;
            }

            for (int i = 0; i < IteratorCount; i++)
            {
                iterators[i] = new Iterator(i);
                iterators[i].SetFractal(this.fractal, branches, variWeights);
                iterators[i].SetOutput(dots);
            }

            globalStats = new NativeGlobalStatEntry();

            tonemapVertShader     = GLUtil.MakeShader("tonemap_vert_glsl", Kernels.KernelResources.tonemap_vert_glsl, ShaderType.VertexShader);
            tonemapFragShader     = GLUtil.MakeShader("tonemap_frag_glsl", Kernels.KernelResources.tonemap_frag_glsl, ShaderType.FragmentShader);
            tonemapProgram        = GLUtil.MakeProgram("tonemap_program", tonemapVertShader, tonemapFragShader);
            accumSamplerLocation  = GL.GetUniformLocation(tonemapProgram, "accumSampler");
            scaleConstantLocation = GL.GetUniformLocation(tonemapProgram, "scaleConstant");
            brightnessLocation    = GL.GetUniformLocation(tonemapProgram, "brightness");
            invGammaLocation      = GL.GetUniformLocation(tonemapProgram, "invGamma");
            vibrancyLocation      = GL.GetUniformLocation(tonemapProgram, "vibrancy");
            upScaleFactorLocation = GL.GetUniformLocation(tonemapProgram, "upScaleFactor");
            subStepXLocation      = GL.GetUniformLocation(tonemapProgram, "subStepX");
            subStepYLocation      = GL.GetUniformLocation(tonemapProgram, "subStepY");
#if DEBUG
            FractalManager.Blip += delegate(object obj, EventArgs ea){
                iterators[0].GetStuck();
            };
#endif
        }
Esempio n. 6
0
        private void RenderCrossedEdges()
        {
            foreach (var tuple in _connectIntersectedEdges)
            {
                ConvexPolyForm poly = tuple.Item1;
                EdgeIndex      edge = tuple.Item2;

                Point start = poly.Vertices[edge.Start];
                Point end   = poly.Vertices[edge.End];

                GLUtil.SetColor(new Color(0, 0, 1, 1));
                PrimitiveDrawer.DrawLine2d(start, end);
            }
        }
Esempio n. 7
0
        private void RenderNormals(ConvexPolyForm poly)
        {
            GLUtil.SetColor(new Color(0, 1, 0, 1));

            foreach (EdgeIndex edge in poly.Edges)
            {
                Point start  = poly.Vertices[edge.Start];
                Point end    = poly.Vertices[edge.End];
                Point middle = LineSegment.GetMiddle(start, end);
                Point normal = EdgeIndex.GetLineNormal(start, end);
                Gl.glBegin(Gl.GL_LINES);
                {
                    GLUtil.DrawPointVertex(middle);
                    GLUtil.DrawPointVertex(new Point(middle.X + (normal.X * 50), middle.Y + (normal.Y * 50)));
                }
                Gl.glEnd();
            }
        }
Esempio n. 8
0
        private void RenderNearestEdge(ConvexPolyForm poly)
        {
            EdgeIndex edge = poly.GetClosestEdge(_input.Mouse.Position);

            GLUtil.SetColor(new Color(1, 0, 0, 1));
            Gl.glBegin(Gl.GL_LINE_STRIP);
            {
                GLUtil.DrawPointVertex(poly.Vertices[edge.Start]);
                GLUtil.DrawPointVertex(poly.Vertices[edge.End]);
            }
            Gl.glEnd();

            // Render closest point
            Point p = EdgeIndex.GetClosestPoint(poly.Vertices[edge.Start], poly.Vertices[edge.End], _input.Mouse.Position);

            Gl.glBegin(Gl.GL_POINTS);
            {
                GLUtil.DrawPointVertex(p);
            }
            Gl.glEnd();
        }
Esempio n. 9
0
        /// <summary>
        /// 盤の描画を行います。
        /// </summary>
        private void AddRenderBoard(GLUtil.RenderBuffer renderBuffer)
        {
            // 盤
            renderBuffer.AddRender(
                this.boardTexture, BlendType.Diffuse,
                BoardBounds, Transform,
                ShogiZOrder.BoardZ, BoardOpacity);

            // 上部に描画する盤の符号の領域
            var totalBounds = RectangleF.FromLTRB(
                BoardSquareBounds.Left,
                BoardBounds.Top,
                BoardSquareBounds.Right,
                BoardSquareBounds.Top); // Topはミスではありません。
            var w = totalBounds.Width / Board.BoardSize;
            for (int n = 1; n <= Board.BoardSize; ++n)
            {
                // 符号を描画する領域
                var bounds = new RectangleF(
                    totalBounds.Left + w * (n - 1),
                    totalBounds.Top,
                    w,
                    totalBounds.Height);
                bounds.Inflate(0, -2.5f);
                var str = IntConverter.Convert(
                    NumberType.Big,
                    ViewSide == BWType.Black ? 10 - n : n);
                AddRenderText(
                    renderBuffer, str, this.boardSignFont,
                    bounds, ShogiZOrder.BoardZ);
            }

            // 右側に描画する盤の符号の領域
            totalBounds = RectangleF.FromLTRB(
                BoardSquareBounds.Right, // Rightはミスではありません。
                BoardSquareBounds.Top,
                BoardBounds.Right,
                BoardSquareBounds.Bottom);
            var h = totalBounds.Height / Board.BoardSize;
            for (int n = 1; n <= Board.BoardSize; ++n)
            {
                // 符号を描画する領域
                var bounds = new RectangleF(
                    totalBounds.Left,
                    totalBounds.Top + h * (n - 1),
                    totalBounds.Width,
                    w);
                bounds.Inflate(-1.5f, 0);
                var str = IntConverter.Convert(
                    NumberType.Kanji,
                    ViewSide == BWType.Black ? n : 10 - n);
                AddRenderText(
                    renderBuffer, str, this.boardSignFont,
                    bounds, ShogiZOrder.BoardZ);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 盤上の全ての駒を描画します。
        /// </summary>
        private void AddRenderPieceAll(GLUtil.RenderBuffer renderBuffer)
        {
            if (this.pieceTexture == null || !this.pieceTexture.IsAvailable)
            {
                return;
            }

            var mp = this.movingPiece;
            var mpSquare = (mp != null ? mp.Square : null);
            var mpPiece = (mp != null ? mp.BoardPiece : null);

            // 盤上の駒
            foreach (var sq in Board.AllSquares())
            {
                var piece = Board[sq];
                if (piece != null && sq != mpSquare)
                {
                    var cpos = SquareToPoint(sq);
                    AddRenderPiece(
                        renderBuffer, piece, 1, cpos,
                        ShogiZOrder.PieceZ);
                }
            }

            // 先手・後手の駒台上の駒を更新します。
            var handList =
                from bw in EnumEx.GetValues<BWType>()
                from pc in EnumEx.GetValues<PieceType>()
                where bw != BWType.None || IsKomaBoxVisible
                where pc != PieceType.None
                let piece = new BoardPiece(pc, bw)
                let count = GetHandCount(pc, bw)
                let subCount = (mpSquare == null && mpPiece == piece ? 1 : 0)
                //where count - subCount > 0
                select new
                {
                    Piece = piece,
                    Count = count - subCount,
                };
            foreach (var hand in handList)
            {
                var cpos = HandPieceToPoint(hand.Piece);
                AddRenderPiece(
                    renderBuffer, hand.Piece, hand.Count, cpos,
                    ShogiZOrder.PieceZ);
            }

            // 移動中の駒を描画します。
            if (mp != null)
            {
                AddRenderPiece(
                    renderBuffer, mp.BoardPiece, 1, mp.Center,
                    ShogiZOrder.MovingPieceZ);
            }
        }
Esempio n. 11
0
        public override void DoIterationCycle(int numIterationsPerThread)
        {
            if (!IsAllocated())
            {
                return;
            }

            int perThreadCount = 0;

            while (perThreadCount < numIterationsPerThread)
            {
                foreach (Iterator iter in iterators)
                {
                    iter.StartIterateTask();
                }
                foreach (Iterator iter in iterators)
                {
                    iter.Finish();
                }

                globalStats.IterCount  += (ulong)DotsPerCycle;
                globalStats.DotCount    = 0;
                globalStats.PeakDensity = 0.0f;
                for (int i = 0; i < iterators.Length; i++)
                {
                    globalStats.DotCount += iterators[i].Stats.DotCount;
                }
                uint  totalSubPixels = (uint)(xRes * yRes * AALevel * AALevel);
                float density        = (float)globalStats.DotCount / (float)totalSubPixels;
                float invPixArea     = Math.Abs((fractal->VpsTransform.XAxis.X * fractal->VpsTransform.YAxis.Y) - (fractal->VpsTransform.XAxis.Y * fractal->VpsTransform.YAxis.X));
                globalStats.ScaleConstant = Tone_C2 * (invPixArea * (float)(AALevel * AALevel)) / (float)globalStats.IterCount;

                GL.BindFramebuffer(FramebufferTarget.Framebuffer, accumFBO);
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, accumTexID, 0);
                GL.Enable(EnableCap.Blend);
                GL.BlendEquation(BlendEquationMode.FuncAdd);
                GL.BlendFunc((BlendingFactor)BlendingFactorSrc.One, (BlendingFactor)BlendingFactorDest.One);

                GL.Disable(EnableCap.PointSmooth);

                GL.PointSize(1.0f);
                GL.Viewport(0, 0, xRes * AALevel, yRes * AALevel);
                GL.MatrixMode(MatrixMode.Projection);
                GLUtil.GLLoadAffineMatrix(projTransform, -1.0f);
                GL.MatrixMode(MatrixMode.Modelview);
                GLUtil.GLLoadAffineMatrix(viewTransform);

                GL.Enable(EnableCap.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, paletteTexID);

                GL.Color4(DownScaleFactor, DownScaleFactor, DownScaleFactor, DownScaleFactor);
                GL.EnableClientState((ArrayCap)EnableCap.VertexArray);
                GL.EnableClientState((ArrayCap)EnableCap.TextureCoordArray);
                GL.VertexPointer(2, VertexPointerType.Float, 16, (IntPtr)dots);
                GL.TexCoordPointer(2, TexCoordPointerType.Float, 16, (IntPtr)((byte *)dots + 8));
                GL.DrawElements(BeginMode.Points, DotsPerCycle, DrawElementsType.UnsignedShort, (IntPtr)dotIndicies);
                GL.DisableClientState((ArrayCap)EnableCap.VertexArray);
                GL.DisableClientState((ArrayCap)EnableCap.TextureCoordArray);

                GL.Disable(EnableCap.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, 0);

                GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
                GL.Finish();

                perThreadCount += DotsPerIterator;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// 駒の描画を行います。
        /// </summary>
        private void AddRenderPiece(GLUtil.RenderBuffer renderBuffer, BoardPiece piece,
                                    int count, PointF cpos, double zorder)
        {
            if (this.pieceTexture == null || !this.pieceTexture.IsAvailable)
            {
                return;
            }

            if (count <= 0)
            {
                return;
            }

            var s = SquareSize;
            var bounds = new RectangleF(
                cpos.X - s.Width / 2, cpos.Y - s.Height / 2,
                s.Width, s.Height);

            // 駒自体の描画を行います。
            renderBuffer.AddRender(
                this.pieceTexture, BlendType.Diffuse,
                bounds, Transform, GetPieceMesh(piece), zorder);

            // 必要なら持ち駒の数も描画します。
            if (count >= 2)
            {
                var text = IntConverter.Convert(NumberType.Big, count);
                bounds = new RectangleF(
                    cpos.X - s.Width * 0.1f, cpos.Y - s.Height * 0.6f,
                    s.Width * 0.8f, s.Height * 0.5f);
                AddRenderText(
                    renderBuffer, text, this.pieceCountFont,
                    bounds, zorder + 0.05);
            }
        }
Esempio n. 13
0
        //TODO: these are getting messy, and really should be using display lists or something.
        private void DrawWidget(Branch branch, bool selected)
        {
            GL.PushMatrix();
            GLUtil.GLMultAffineMatrix(branch.Transform);

            GL.LineWidth(3.0f);
            if (selected)
            {
                GL.Color4(0.0f, 0.0f, 0.0f, 1.0f);
            }
            else
            {
                GL.Color4(0.0f, 0.0f, 0.0f, 0.5f);
            }
            DrawWidgetHelper(branch, selected);

            GL.LineWidth(1.0f);
            if (selected)
            {
                GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);
            }
            else
            {
                GL.Color4(1.0f, 1.0f, 1.0f, 0.75f);
            }
            DrawWidgetHelper(branch, selected);

            GL.PointSize(5.0f);
            GL.Begin(BeginMode.Points);
            if (selected)
            {
                GL.Color4(0.0f, 0.0f, 0.0f, 1.0f);
            }
            else
            {
                GL.Color4(0.0f, 0.0f, 0.0f, 0.5f);
            }
            GL.Vertex2(0.0f, 0.0f);
            GL.Vertex2(1.0f, 0.0f);
            GL.Vertex2(0.0f, 1.0f);
            GL.End();

            if (selected)
            {
                GL.LineWidth(2.0f);
            }
            else
            {
                GL.LineWidth(1.0f);
            }

            GL.Begin(BeginMode.Lines);
            GL.Color4(branch.GetChromaColor(FractalManager.Fractal.Palette));
            GL.Vertex2(0.0f, 0.0f);
            if (selected)
            {
                GL.Color4(branch.GetChromaColor(FractalManager.Fractal.Palette));
            }
            else
            {
                GL.Color4(1.0f, 1.0f, 1.0f, 0.375f);
            }
            GL.Vertex2(0.0f, 1.0f);
            GL.End();

            GL.PointSize(3.0f);
            GL.Begin(BeginMode.Points);
            if (selected)
            {
                GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);
            }
            else
            {
                GL.Color4(1.0f, 1.0f, 1.0f, 0.5f);
            }
            GL.Vertex2(0.0f, 0.0f);
            GL.Vertex2(1.0f, 0.0f);
            GL.Vertex2(0.0f, 1.0f);
            GL.End();

            GL.PopMatrix();
        }
Esempio n. 14
0
        public void Render(int glOutputTexID)
        {
            if (!SafeToRender)
            {
                return;
            }

            GL.Viewport(0, 0, ClientSize.Width, ClientSize.Height);

            Vec4 bgCol = FractalManager.Fractal.BackgroundColor;

            GL.ClearColor(bgCol.X, bgCol.Y, bgCol.Z, bgCol.W);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.Enable(EnableCap.LineSmooth);
            GL.Enable(EnableCap.PointSmooth);
            GL.Enable(EnableCap.Blend);
            GL.BlendFuncSeparate(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha, BlendingFactorSrc.One, BlendingFactorDest.Zero);

            GL.MatrixMode(MatrixMode.Projection);
            GLUtil.GLLoadAffineMatrix(projTransform, -1.0f);
            GL.MatrixMode(MatrixMode.Modelview);
            GLUtil.GLLoadAffineMatrix(viewTransform);


            if (glOutputTexID != 0)
            {
                GL.MatrixMode(MatrixMode.Projection);
                GL.PushMatrix();
                GL.LoadIdentity();
                GL.Ortho(0, 1, 0, 1, -1, 1);
                GL.MatrixMode(MatrixMode.Modelview);
                GL.PushMatrix();
                GL.LoadIdentity();

                GL.BindTexture(TextureTarget.Texture2D, glOutputTexID);
                GL.Enable(EnableCap.Texture2D);

                GL.Begin(BeginMode.Quads);
                GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);
                GL.TexCoord2(0.0f, 0.0f);
                GL.Vertex2(0.0f, 0.0f);
                GL.TexCoord2(1.0f, 0.0f);
                GL.Vertex2(1.0f, 0.0f);
                GL.TexCoord2(1.0f, 1.0f);
                GL.Vertex2(1.0f, 1.0f);
                GL.TexCoord2(0.0f, 1.0f);
                GL.Vertex2(0.0f, 1.0f);
                GL.End();

                GL.BindTexture(TextureTarget.Texture2D, 0);

                GL.MatrixMode(MatrixMode.Projection);
                GL.PopMatrix();
                GL.MatrixMode(MatrixMode.Modelview);
                GL.PopMatrix();
            }
            if (EditMode && (dragModifier & DragModifier.Ctrl) == DragModifier.Ctrl)
            {
                GL.LineWidth(1.0f);
                DrawGrid();
            }

            if (EditMode)
            {
                if (dragState == DragState.Dragging)
                {
                    if (hoverBranch != null)
                    {
                        DrawWidget(hoverBranch, true);
                    }

                    GL.PointSize(6.0f);
                    GL.Begin(BeginMode.Points);
                    GL.Color4(1.0f, 1.0f, 0.5f, 1.0f);
                    GL.Vertex2(dragHandlePos.X, dragHandlePos.Y);
                    GL.End();
                    GL.PointSize(1.0f);
                }
                else
                {
                    foreach (Branch branch in FractalManager.Branches)
                    {
                        DrawWidget(branch, branch == FractalManager.SelectedBranch);
                    }

                    if (hoverType != SelectionType.None)
                    {
                        GL.PointSize(6.0f);
                        GL.Begin(BeginMode.Points);
                        GL.Color4(0.5f, 1.0f, 1.0f, 1.0f);
                        GL.Vertex2(hoverHandlePos.X, hoverHandlePos.Y);
                        GL.End();
                        GL.PointSize(1.0f);
                    }
                }
            }

            //GL.PointSize(6.0f);
            //GL.Begin(BeginMode.Points);
            //GL.Color4(1.0f,1.0f,1.0f,1.0f);
            //GL.Vertex2(debugPos.X, debugPos.Y);
            //GL.End();


            GL.Finish();
            SwapBuffers();
        }
Esempio n. 15
0
        /// <summary>
        /// 評価値を数字として描画リストに加えます。
        /// </summary>
        private void AddRenderValue(GLUtil.RenderBuffer renderBuffer, Score score)
        {
            var textTexture = GLUtil.TextureCache.GetTextTexture(
                score.Value.ToString(), ValueFont);
            var texture = textTexture.Texture;

            var textTexture2 = GLUtil.TextureCache.GetTextTexture(
                score.Name ?? string.Empty, NameFont);
            var texture2 = textTexture2.Texture;

            if (texture != null && texture.IsAvailable)
            {
                var Margin = 0.02f;

                // 描画領域はテクスチャサイズの割合から決定します。
                // 評価値は画像の下部or上部の
                // 横幅が全体の 3/4 以上になるか、
                // 縦幅が全体の 1/5 以上になるまで
                // 拡大します。拡大は縦横比を保存した状態で行います。

                // フォントの描画サイズを全体の高さからの割合で指定。
                var eh = this.valueHeight;
                var ew = eh * texture.OriginalWidth / texture.OriginalHeight; 

                // 文字幅がエレメントサイズを超えていたら、
                // 文字列サイズの調整を行います。
                if (ew > 0.9f)
                {
                    ew = 0.9f;
                    eh = ew * texture.OriginalHeight / texture.OriginalWidth;
                }

                // 評価値の背景描画
                var bounds = new RectangleF(
                    -0.5f, this.valueTop, 1.0f, this.valueHeight);
                renderBuffer.AddRender(
                    BlendType.Diffuse, Color.FromArgb(128, Color.Black),
                    bounds, Transform, 1.0);

                // 先手後手の描画 (左側のマージンはつけません)
                bounds = new RectangleF(
                    -0.5f, this.valueTop, eh * texture2.OriginalWidth / texture2.OriginalHeight, eh);
                renderBuffer.AddRender(
                    texture2, BlendType.Diffuse,
                    bounds, Transform, 1.0);

                // 評価値の描画
                bounds = new RectangleF(
                    0.5f - Margin - ew, this.valueTop, ew, eh);
                renderBuffer.AddRender(
                    texture, BlendType.Diffuse,
                    bounds, Transform, 1.0);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// indexに対応した駒台を描画します。
        /// </summary>
        /// <param name="index">0なら駒箱、1なら先手用、2なら後手用の駒台となります。</param>
        private void AddRenderPieceBox(GLUtil.RenderBuffer renderBuffer, int index)
        {
            // テクスチャがないときは帰ります。
            if (this.pieceTexture == null || this.pieceTexture.TextureName == 0)
            {
                return;
            }

            // 駒箱の場合はキャンセルするかもしれません
            if (index == 0 && !IsKomaBoxVisible)
            {
                return;
            }

            // 盤面が反転している場合は、見た目の先後を入れ替えます。
            var viewIndex = (
                ViewSide != BWType.Black ? 
                (index == 0 ? 0 : index == 1 ? 2 : 1) :
                index);
            var pieceBoxBounds = this.pieceBoxBounds[viewIndex];

            // 駒箱テクスチャ
            renderBuffer.AddRender(
                this.pieceBoxTexture, BlendType.Diffuse,
                pieceBoxBounds, Transform,
                ShogiZOrder.BoardZ,  BoardOpacity);

            // 駒台の上に対局者名を描画します。
            {
                var y = (viewIndex == 2 ?
                    pieceBoxBounds.Bottom - 5 - 15 :
                    pieceBoxBounds.Top + 5);
                var bounds = new RectangleF(
                    pieceBoxBounds.Left + 5, y,
                    pieceBoxBounds.Width - 10, 15);

                // 名前の背景に色をつけます。
                var color = (
                    Board.Turn == (BWType)index ?
                    TebanPlayerNameBackgroundColor :
                    UnTebanPlayerNameBackgroundColor);
                renderBuffer.AddRender(
                    BlendType.Diffuse, bounds, Transform,
                    color, ShogiZOrder.PostBoardZ);

                // 対局者名を描画
                var name = (
                    index == 1 ? BlackPlayerName :
                    index == 2 ? WhitePlayerName :
                    "駒箱");
                if (name.HankakuLength() > 17)
                {
                    name = name.HankakuSubstring(14) + "...";
                }
                bounds.Inflate(-1, -1);
                AddRenderText(
                    renderBuffer, name, this.nameFont,
                    bounds, ShogiZOrder.PostBoardZ);
            }

            // 合計時間や消費時間の描画を行います。
            // 局面編集中など駒箱が表示されているときは残り時間を表示しません。
            if (IsTimeVisible && !IsKomaBoxVisible)
            {
                var y = (viewIndex == 2 ?
                    pieceBoxBounds.Bottom :
                    pieceBoxBounds.Top - 15);
                var bounds = new RectangleF(
                    pieceBoxBounds.Left, y,
                    pieceBoxBounds.Width, 15);
                renderBuffer.AddRender(
                    BlendType.Diffuse, bounds, Transform,
                    TimeBackgroundColor, ShogiZOrder.PostBoardZ);

                // 消費時間などを描画
                // 時間のフォーマットは '消費時間 / 合計時間' となっています。
                var totalTime = (index == 1 ? BlackTotalTime : WhiteTotalTime);
                var time = (index == 1 ? BlackTime : WhiteTime);
                var str = string.Format(
                    "{0:000}:{1:00} / {2:000}:{3:00}",
                    (int)time.TotalMinutes, time.Seconds,
                    (int)totalTime.TotalMinutes, totalTime.Seconds);
                bounds.Inflate(-4, -1);
                AddRenderText(
                    renderBuffer, str, this.timeFont,
                    bounds, ShogiZOrder.PostBoardZ);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// 描画オブジェクトを追加します。
        /// </summary>
        public void AddRender(GLUtil.Texture texture, BlendType blend,
                              RectangleF bounds, Matrix44d transform,
                              Mesh mesh, double zorder,
                              double opacity = 1.0)
        {
            if (texture == null || texture.TextureName == 0)
            {
                return;
            }

            var alphaByte = (byte)Math.Min(256 * opacity, 255);
            var color = Color.FromArgb(alphaByte, Color.White);
            var transform2 = ToMatrix(bounds, transform);

            AddRender(texture, blend, color, mesh, transform2, zorder);
        }
Esempio n. 18
0
 /// <summary>
 /// テクスチャを読み込みます。
 /// </summary>
 private void LoadTexture(GLUtil.Texture texture, Bitmap bitmap)
 {
     if (bitmap != null)
     {
         if (!texture.Create(bitmap))
         {
             throw new RagnarokException(
                 "テクスチャの作成に失敗しました。");
         }
     }
     else
     {
         texture.Destroy();
     }
 }
Esempio n. 19
0
        /// <summary>
        /// 文字列の描画を行います。
        /// </summary>
        private void AddRenderText(GLUtil.RenderBuffer renderBuffer, string text,
                                   GLUtil.TextTextureFont font, RectangleF bounds,
                                   double zorder, double opacity = 1.0)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var textTexture = GLUtil.TextureCache.GetTextTexture(text, font);
            if (textTexture == null || textTexture.Texture == null)
            {
                // エラーだけどどうしようか。
                return;
            }

            var texture = textTexture.Texture;
            var r = (float)texture.OriginalWidth / texture.OriginalHeight;
            var br = (float)bounds.Width / bounds.Height;
            var w = (r >= br ? bounds.Width : bounds.Height * r);
            var h = (r >= br ? bounds.Width / r : bounds.Height);

            var result = new RectangleF(
                (bounds.Left + bounds.Right) / 2 - w / 2,
                (bounds.Top + bounds.Bottom) / 2 - h / 2,
                w, h);
            renderBuffer.AddRender(
                texture, BlendType.Diffuse,
                result, Transform, zorder, 1.0);
        }
Esempio n. 20
0
        /// <summary>
        /// 自動再生用のエフェクト描画を行います。
        /// </summary>
        private void AddRenderAutoPlayEffect(GLUtil.RenderBuffer renderBuffer)
        {
            if (AutoPlayState != AutoPlayState.Playing)
            {
                return;
            }

            if (AutoPlayOpacity == 0.0)
            {
                return;
            }

            var bounds = new RectangleF(0.0f, 0.0f, 640.0f, 480.0f);
            var alpha = (byte)(AutoPlayColor.A * AutoPlayOpacity);

            renderBuffer.AddRender(
                BlendType.Diffuse, bounds, Transform,
                Color.FromArgb(alpha, AutoPlayColor), ShogiZOrder.PostEffectZ2);
        }