欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

wxWidgets第十七課采用AGG渲染庫

說明

創(chuàng)新互聯(lián)2013年開創(chuàng)至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元寧陜做網(wǎng)站,已為上家服務(wù),為寧陜各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792

    已有的wxDC以及所有的派生類相關(guān)的設(shè)備環(huán)境均沒有實(shí)現(xiàn)抗鋸齒的功能,畢竟wxDC也只是對(duì)CDC的封裝,只有GDI+才支持抗鋸齒。

    在如下的代碼中定義rasterizer等為靜態(tài)變量的核心原因是其在進(jìn)行渲染計(jì)算的時(shí)候會(huì)分配大量的內(nèi)存,容易造成內(nèi)存碎片,當(dāng)然agg::pixfmt_bgra32 和agg::renderer_scanline_aa_solid

等并沒有進(jìn)行什么內(nèi)存分配,但是統(tǒng)一起見,所以構(gòu)造為靜態(tài)變量,實(shí)際上,還有申請(qǐng)的渲染緩存指向的區(qū)域也應(yīng)該設(shè)置為靜態(tài)變量,然后通過指定寬和高,即可最大限度的避免了內(nèi)存碎片


代碼

頭文件

#include "wx/wx.h"


#include "agg/agg_scanline_p.h"

#include "agg/agg_renderer_scanline.h"

#include "agg/agg_pixfmt_rgba.h"

#include "agg/agg_rasterizer_scanline_aa.h"


struct PosCoordinate

{

double x;

double y;

};

class CFlightInstrumentCompassCtrl : public wxControl

{

private:

DECLARE_EVENT_TABLE()

public:

CFlightInstrumentCompassCtrl() {Init();}

void Init() {}


CFlightInstrumentCompassCtrl(wxWindow *parent,

wxWindowID id,

const wxPoint& pos = wxDefaultPosition,

const wxSize& size = wxDefaultSize,

long style = 0,

const wxValidator& validator = wxDefaultValidator)

{

Init();

Create(parent, id, pos, size, style, validator);

}


bool Create(wxWindow *parent,

wxWindowID id,

const wxPoint& pos = wxDefaultPosition,

const wxSize& size = wxDefaultSize,

long style = 0,

const wxValidator& validator = wxDefaultValidator);

~CFlightInstrumentCompassCtrl(void);


void SetCompassParameter(double leanAngle, double leanDistance, int rollAngle);


void SetSize(wxSize size)

{

m_size = size;

}


private:

void GetFitCircleInfo(double &circleRaduis, double &circleCenterX, double &circleCenterY);


private:

double m_arrowDiviationAngle;

double m_arrowAngle;

double m_leanDistance;

int   m_curRollAngle;

wxSize m_size;


protected:

void OnPaint(wxPaintEvent& event);


void OnEraseBackground(wxEraseEvent& event);


public:

//對(duì)需要使用的AGG對(duì)象進(jìn)行聲明,因?yàn)槭庆o態(tài)變量還需要在源文件中進(jìn)行定義,否則出現(xiàn)無法解析的外部符號(hào)錯(cuò)誤

static agg::rendering_buffer m_rbuf;

static agg::pixfmt_bgra32 m_pixf;

static agg::renderer_base<agg::pixfmt_bgra32> m_renb;

static agg::renderer_scanline_aa_solid<agg::renderer_base<agg::pixfmt_bgra32> > m_ren;

static agg::rasterizer_scanline_aa<> m_ras;

static agg::scanline_p8 m_sl;

};


源文件

#include "flightinstrumentcompass.h"

#include "wx/msw/window.h"

#include <windows.h>

#include "wx/dc.h"


BEGIN_EVENT_TABLE(CFlightInstrumentCompassCtrl, wxControl)

EVT_PAINT(CFlightInstrumentCompassCtrl::OnPaint)

EVT_ERASE_BACKGROUND(CFlightInstrumentCompassCtrl::OnEraseBackground)

END_EVENT_TABLE()


//靜態(tài)AGG對(duì)象的定義

agg::rendering_buffer CFlightInstrumentCompassCtrl::m_rbuf;

agg::pixfmt_bgra32 CFlightInstrumentCompassCtrl::m_pixf;

agg::renderer_base<agg::pixfmt_bgra32> CFlightInstrumentCompassCtrl::m_renb;

agg::renderer_scanline_aa_solid<agg::renderer_base<agg::pixfmt_bgra32> > CFlightInstrumentCompassCtrl::m_ren;

agg::rasterizer_scanline_aa<> CFlightInstrumentCompassCtrl::m_ras;

agg::scanline_p8 CFlightInstrumentCompassCtrl::m_sl;



bool CFlightInstrumentCompassCtrl::Create(wxWindow *parent,

  wxWindowID id,

  const wxPoint& pos ,

  const wxSize& size ,

  long style ,

  const wxValidator& validator)

{

if (!wxControl::Create(parent, id, pos, size, style, validator))

{

return false;

}

return true;

}



CFlightInstrumentCompassCtrl::~CFlightInstrumentCompassCtrl(void)

{


}


void CFlightInstrumentCompassCtrl::OnPaint( wxPaintEvent& event )

{

WXHWND hWnd = GetHWND();

PAINTSTRUCT ps;

HDC hdc = BeginPaint(hWnd, &ps);


RECT rt;

::GetClientRect(hWnd, &rt);


int width = rt.right - rt.left;

int height = rt.bottom - rt.top;


BITMAPINFO bmp_info; 

bmp_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 

bmp_info.bmiHeader.biWidth = width; 

bmp_info.bmiHeader.biHeight = height; 

bmp_info.bmiHeader.biPlanes = 1; 

bmp_info.bmiHeader.biBitCount = 32; 

bmp_info.bmiHeader.biCompression = BI_RGB; 

bmp_info.bmiHeader.biSizeImage = 0; 

bmp_info.bmiHeader.biXPelsPerMeter = 0; 

bmp_info.bmiHeader.biYPelsPerMeter = 0; 

bmp_info.bmiHeader.biClrUsed = 0; 

bmp_info.bmiHeader.biClrImportant = 0; 


HDC mem_dc = ::CreateCompatibleDC(hdc); 


void* buf = 0; 


HBITMAP bmp = ::CreateDIBSection( 

mem_dc, 

&bmp_info, 

DIB_RGB_COLORS, 

&buf, 

0, 

);



// Selecting the object before doing anything allows you 

// to use AGG together with native Windows GDI.

HBITMAP temp = (HBITMAP)::SelectObject(mem_dc, bmp);



//============================================================ 

// AGG lowest level code.

m_rbuf.attach((unsigned char*)buf, width, height, -width*4); // Use negative stride in order

m_pixf.attach(m_rbuf);

m_renb.attach(m_pixf);

m_ren.attach(m_renb);


m_renb.clear(agg::rgba8(255, 255, 255, 255));


m_ras.move_to_d(20.7, 34.15);

m_ras.line_to_d(398.23, 123.43);

m_ras.line_to_d(165.45, 401.87);


// Setting the attrribute (color) & Rendering

m_ren.color(agg::rgba8(80, 90, 60));

agg::render_scanlines(m_ras, m_sl, m_ren);

//============================================================




//------------------------------------------------------------ 

// Display the p_w_picpath. If the p_w_picpath is B-G-R-A (32-bits per pixel)

// one can use AlphaBlend instead of BitBlt. In case of AlphaBlend

// one also should clear the p_w_picpath with zero alpha, i.e. rgba8(0,0,0,0)


::BitBlt(

hdc,  

rt.left,      

rt.top,      

width,  

height, 

mem_dc,

0,

0,     

SRCCOPY

);


// Free resources 

::SelectObject(mem_dc, temp); 

::DeleteObject(bmp); 

::DeleteObject(mem_dc);


EndPaint(hWnd, &ps);

return;

}



注意

1 為了能夠使用wxClientDC等wxDC派生類,需要包含頭文件wx/wx.h,否則在調(diào)用DrawText渲染字體的時(shí)候出現(xiàn)如下的編譯錯(cuò)誤:DrawTextW不是wxClientDC 的成員


2 在使用了AGG渲染之后,沒有必要使用wxDC的派生類進(jìn)行渲染。AGG渲染是首先在構(gòu)建一張位圖,在此基礎(chǔ)上渲染完畢,進(jìn)行圖像的粘貼,如果要使用wxClientDC,會(huì)造成閃爍,如果使用wxMemoryDC(也是構(gòu)建一塊內(nèi)存位圖,然后進(jìn)行貼圖),也只能采用裁剪函數(shù)貼圖某一個(gè)區(qū)域,不可能進(jìn)行混合渲染,否則會(huì)覆蓋已有的渲染,并且在拉伸窗口的過程中,發(fā)現(xiàn)AGG渲染成功,但是wxClientDC等看不到任何渲染的結(jié)果

當(dāng)前標(biāo)題:wxWidgets第十七課采用AGG渲染庫
文章URL:http://www.chinadenli.net/article48/iiejhp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)面包屑導(dǎo)航品牌網(wǎng)站制作網(wǎng)站制作定制網(wǎng)站小程序開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計(jì)公司