• <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)

            隨筆分類

            搜索

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            波多野结衣久久| 看全色黄大色大片免费久久久| 亚洲精品蜜桃久久久久久| 久久精品极品盛宴观看| 7777久久久国产精品消防器材| 性欧美大战久久久久久久久| 91精品国产91久久| 久久午夜免费视频| 丁香狠狠色婷婷久久综合| 四虎国产精品成人免费久久| 国产亚洲精品美女久久久| 久久久久婷婷| 99久久成人国产精品免费| 久久久这里有精品| 99久久无码一区人妻| 久久精品蜜芽亚洲国产AV| 久久免费香蕉视频| 婷婷久久综合九色综合98| 国产A三级久久精品| 久久久受www免费人成| 久久亚洲精品中文字幕三区| 伊人久久大香线蕉亚洲| 性做久久久久久免费观看| 久久AAAA片一区二区| 久久精品免费一区二区三区| 午夜久久久久久禁播电影| 久久久久亚洲AV无码观看| 亚洲а∨天堂久久精品| 精品无码久久久久久久动漫| 超级碰久久免费公开视频| 2021少妇久久久久久久久久| 久久w5ww成w人免费| 无码人妻久久一区二区三区免费丨| 久久综合久久综合亚洲| 亚洲欧美日韩精品久久亚洲区 | 久久国产色av免费看| 日本精品久久久久影院日本 | 香蕉久久夜色精品升级完成| 人妻系列无码专区久久五月天| 狠狠色丁香婷婷综合久久来来去| 大伊人青草狠狠久久|