• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            AGG入門(六) - 練習和細節

            學到目前為止,已經認識了六個類型:
            • platform_support
            • rendering_buffer
            • rgba8
            • pixfmt_rgb24
            • rect_i
            • renderer_base
            現在來做些練習,看看有沒有掌握學過的東西,并且靈活運用吧。

            一、基本框架

            這一節的程序都以這個框架為基礎,都是在on_draw中稍微改動的:
            #include <agg_pixfmt_rgb.h>
            #include <agg_renderer_base.h>
            #include <platform/agg_platform_support.h>

            class the_application : public agg::platform_support
            {
            public:
                the_application(agg::pix_format_e format, bool flip_y) : 
                    agg::platform_support(format, flip_y),
                    pix_fmt(rbuf_window()),
                    ren_bas(pix_fmt) //初始化渲染器
                { }
                
                virtual void on_draw()
                {
                     ren_bas.reset_clipping(true);
                     ren_bas.clear(agg::rgba8(255, 255, 255));
                }
            private:
                agg::pixfmt_rgb24 pix_fmt;
                agg::renderer_base<agg::pixfmt_rgb24> ren_bas;

            };

            int agg_main(int argc, char* argv[])
            {
                the_application app(agg::pix_format_bgr24, true);
                app.caption("AGG Test");
                
                if(app.init(500, 500, agg::window_resize)) {
                    return app.run();
                }
                return -1;
            }

            二、畫線函數

            編寫如下函數,實現在渲染緩存中畫線的功能(無需反鋸齒):
                inline void stroke_line(int x1, int y1, int x2, int y2, agg::rgba8& color);
            參數:

            • x1, y1, x2, y2分別是兩個端點的坐標;
            • color是顏色;

             

            三、畫圓函數

            編寫如下函數,實現在渲染緩存中畫圓的功能(無需反鋸齒):
                void stroke_round(int r, int C_x, int C_y, agg::rgba8& color, float step = 0.01)
            參數:

            • C_x, C_y 是圓心的坐標;
            • color是顏色;
            • step是步長,也就是吧圓細分成1/step邊形;

             

            四、答案

            • 畫線函數
              inline void stroke_line(int x1, int y1, int x2, int y2, agg::rgba8& color)
              {
                  double precision = max(abs(x1 - x2), abs(y1 - y2));
                  //精度,也就是畫多少個點

                  for(int i=0; i <= precision; i++)
                      ren_bas.copy_pixel( x1 + ( x2 - x1 ) / precision * i, //x
                          y1 + ( y2 - y1 ) / precision * i, //y
                          color);
              }
            • 畫圓函數
              void stroke_round(int r, int C_x, int C_y, agg::rgba8& color, float step = 0.01)
              {
                  int prev_x = int(r * cos(-0.01)) + C_x,
                      prev_y = int(r * sin(-0.01)) + C_y; //保存上一個點

                  int x, y; //保存當前的點
                  for(double rad = 0; rad < 2 * PI + step; rad+= step) {
                      x = int(r * cos(rad)) + C_x;
                      y = int(r * sin(rad)) + C_y; //計算弧度為rad時的坐標
                      stroke_line(x, y, prev_x, prev_y, color);
                      prev_x = x; prev_y = y;
                  }
              }

            可能有的人會覺得奇怪的是,為什么在畫線函數中,不用pix_fmt.copy_pixel()而用ren_bas.copy_pixel()呢?因為,在pix_fmt中,混合器不進行檢查,像素拷貝的時候會拷貝到剪裁區域以外,這樣會造成很奇怪的情況,以至于如果寫到了緩存以外,還會出現異常。注意,剪裁盒功能是基礎渲染器級別才提供的,更加底層的操作,比如像素格式混合和直接操作緩存,高層次的渲染器是無從管理的。為了安全起見,建議少碰基礎渲染器以下的工具……

            posted on 2012-07-24 16:30 Shihira 閱讀(4229) 評論(1)  編輯 收藏 引用 所屬分類: 圖形編程

            評論

            # re: AGG入門(六) - 練習和細節 2012-07-24 23:02 agg

            支持。  回復  更多評論   

            導航

            統計

            公告

            留言簿(2)

            隨筆分類

            搜索

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            色综合久久中文色婷婷| 亚洲精品无码久久久久sm| 日本精品久久久久中文字幕8| 97久久精品午夜一区二区| 国产午夜精品理论片久久| 久久精品综合网| 奇米综合四色77777久久| 一本久久a久久精品综合夜夜| 久久精品国产黑森林| 久久99亚洲网美利坚合众国| 久久亚洲国产成人精品无码区| 亚洲精品国产美女久久久| 女同久久| 精品国产一区二区三区久久| 久久久久久国产精品无码下载| segui久久国产精品| 久久久老熟女一区二区三区| 国产精品狼人久久久久影院| 国内精品久久久久影院日本| 久久99热这里只频精品6| 老司机国内精品久久久久| 久久狠狠高潮亚洲精品| 亚洲综合久久夜AV | 国内精品久久久久久久亚洲| 99久久婷婷免费国产综合精品| 久久人人爽人人爽人人片AV麻烦| 久久综合九色综合欧美就去吻| 伊人久久综在合线亚洲2019 | 97热久久免费频精品99| A级毛片无码久久精品免费| 久久综合五月丁香久久激情| 99久久99久久精品国产| 久久99精品久久久久久久久久| 无码人妻少妇久久中文字幕蜜桃| 香蕉99久久国产综合精品宅男自 | 亚洲综合熟女久久久30p| 一级做a爰片久久毛片毛片| 亚洲欧洲精品成人久久曰影片 | 久久久久久久国产免费看| 国产精品无码久久四虎| 久久无码AV中文出轨人妻|