• <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入門(mén)(六) - 練習(xí)和細(xì)節(jié)

            學(xué)到目前為止,已經(jīng)認(rèn)識(shí)了六個(gè)類型:
            • platform_support
            • rendering_buffer
            • rgba8
            • pixfmt_rgb24
            • rect_i
            • renderer_base
            現(xiàn)在來(lái)做些練習(xí),看看有沒(méi)有掌握學(xué)過(guò)的東西,并且靈活運(yùn)用吧。

            一、基本框架

            這一節(jié)的程序都以這個(gè)框架為基礎(chǔ),都是在on_draw中稍微改動(dòng)的:
            #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;
            }

            二、畫(huà)線函數(shù)

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

            • x1, y1, x2, y2分別是兩個(gè)端點(diǎn)的坐標(biāo);
            • color是顏色;

             

            三、畫(huà)圓函數(shù)

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

            • C_x, C_y 是圓心的坐標(biāo);
            • color是顏色;
            • step是步長(zhǎng),也就是吧圓細(xì)分成1/step邊形;

             

            四、答案

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

                  for(int i=0; i <= precision; i++)
                      ren_bas.copy_pixel( x1 + ( x2 - x1 ) / precision * i, //x
                          y1 + ( y2 - y1 ) / precision * i, //y
                          color);
              }
            • 畫(huà)圓函數(shù)
              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; //保存上一個(gè)點(diǎn)

                  int x, y; //保存當(dāng)前的點(diǎn)
                  for(double rad = 0; rad < 2 * PI + step; rad+= step) {
                      x = int(r * cos(rad)) + C_x;
                      y = int(r * sin(rad)) + C_y; //計(jì)算弧度為rad時(shí)的坐標(biāo)
                      stroke_line(x, y, prev_x, prev_y, color);
                      prev_x = x; prev_y = y;
                  }
              }

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

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

            評(píng)論

            # re: AGG入門(mén)(六) - 練習(xí)和細(xì)節(jié) 2012-07-24 23:02 agg

            支持。  回復(fù)  更多評(píng)論   

            導(dǎo)航

            統(tǒng)計(jì)

            公告

            留言簿(2)

            隨筆分類

            搜索

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            91精品国产91热久久久久福利| 国产精品久久午夜夜伦鲁鲁| 99热精品久久只有精品| 99久久亚洲综合精品成人| 成人国内精品久久久久影院VR| 久久99精品久久久久久不卡| 一级做a爰片久久毛片免费陪| 奇米综合四色77777久久| 99精品久久精品| 久久综合视频网| 香港aa三级久久三级| 欧美亚洲国产精品久久| 欧美久久精品一级c片片| 久久久久久久91精品免费观看| 久久99热只有频精品8| 日韩久久久久中文字幕人妻| 久久久无码人妻精品无码| 四虎影视久久久免费| 99久久精品免费看国产| 精品无码久久久久久午夜| 久久中文字幕精品| 久久久免费观成人影院 | 久久综合伊人77777| 99久久人妻无码精品系列蜜桃| 久久夜色精品国产亚洲| 国内精品久久久久久久coent| 97久久国产亚洲精品超碰热| 狠狠色噜噜色狠狠狠综合久久| 久久高清一级毛片| 国产99久久久久久免费看| 97r久久精品国产99国产精| 色欲综合久久躁天天躁蜜桃| 中文字幕精品无码久久久久久3D日动漫| 欧美精品一本久久男人的天堂| 久久精品国产亚洲av影院| 伊人久久大香线蕉综合影院首页| 色老头网站久久网| 亚洲欧美成人综合久久久| 亚洲国产精品无码成人片久久| 久久久久久久久久久精品尤物| 精产国品久久一二三产区区别 |