• <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 閱讀(4242) 評論(1)  編輯 收藏 引用 所屬分類: 圖形編程

            評論

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

            支持。  回復  更多評論   

            導航

            統計

            公告

            留言簿(2)

            隨筆分類

            搜索

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            国产成人无码精品久久久免费| 中文无码久久精品| 99久久精品国产免看国产一区| 久久精品一本到99热免费| 丁香狠狠色婷婷久久综合| 久久黄视频| 99久久国语露脸精品国产| 久久九九久精品国产免费直播| 国产亚洲美女精品久久久2020| 久久ZYZ资源站无码中文动漫| 久久播电影网| 久久影院综合精品| 久久亚洲精品无码播放| 久久国产精品77777| 亚洲欧美日韩久久精品| 狠狠色丁香婷综合久久| 久久伊人精品一区二区三区| 嫩草影院久久99| 日产精品久久久久久久| 久久这里都是精品| 国产高潮国产高潮久久久91| 久久久久亚洲Av无码专| 亚洲伊人久久精品影院| 久久毛片一区二区| 久久亚洲AV永久无码精品| 999久久久免费国产精品播放| 精品久久久久香蕉网| 亚洲国产精品成人久久| 久久www免费人成看片| 欧美性大战久久久久久| 久久精品无码av| 精品久久久久久无码中文字幕 | 精品久久人人做人人爽综合| 久久香蕉国产线看观看精品yw| 久久精品国产99国产精品亚洲| 色综合合久久天天给综看| 久久久久久国产精品无码下载| 久久久久久免费一区二区三区| 久久午夜无码鲁丝片| 99久久777色| 九九久久精品无码专区|