過載mfc中的wm_crate訊息響應函式int oncreate(lpcreatestruct lpcreatestruct),顯示呼叫init函式,如下:
int c3dstereoview::oncreate(lpcreatestruct lpcreatestruct)
在init函式(自定義的)中完成opengl環境初始化,定義如下:
void c3dstereoview::init()
//--- 初始化材料屬性、光照和深度快取 ----
glcleardepth(1.0f);
glenable(gl_depth_test);
glcolormaterial(gl_front_and_back,gl_diffuse);
glenable(gl_color_material);
glfloat m_light0ambient[4]=; // 環境光
glfloat m_light0diffuse[4]=; // 散射(漫反射)光
glfloat m_light0pos[4]=; // 光源位置
gllightfv(gl_light0,gl_ambient,m_light0ambient);
gllightfv(gl_light0,gl_diffuse,m_light0diffuse);
gllightfv(gl_light0,gl_position,m_light0pos);
if(m_pdisplaycontrol->dispalaytexture)
glenable(gl_lighting);
else
gldisable(gl_lighting);
glenable(gl_light0);
settimer(1, 2000, null); //設定時鐘
if(model!=null)
modelinit();
//--------- font 的初始化 ---------
glshademodel (gl_flat);
//---------- 使得 ctooltips 控制項可用----------
enabletooltips(true);
m_ttc.create(this);
m_ttc.activate(true);
m_ttc.addtool(this, "idc_button1 ");
m_ttc.settipbkcolor(rgb(255,255,255)); // 白底
m_ttc.settiptextcolor(rgb(0,0,255)); // 藍字
m_ttc.setdelaytime(150);
return;
}
在init函式中呼叫了bsetuppixelformat函式(也是自定義的),在這個函式中為dc設定指定的畫素格式
bool c3dstereoview::bsetuppixelformat()
; int pixelformat;
if ( (pixelformat = choosepixelformat(m_pdc->getsafehdc(), &pfd)) == 0 )
if (setpixelformat(m_pdc->getsafehdc(), pixelformat, &pfd) == false)
return true;
}
過載mfc中的wm_size訊息響應函式void onsize(uintntype,int cx, int cy),設定顯示尺寸
void c3dstereoview::onsize(uint ntype, int cx, int cy)
過載mfc的wm_erasebkgnd訊息響應函式onerasebkgnd(cdc* pdc) ,目的是消除螢幕閃爍
bool c3dstereoview::onerasebkgnd(cdc* pdc)
最後,記得解除hrc與dc的繫結關係,刪除hglrc物件,過載mfc的wm_destroy訊息
void c3dstereoview::ondestroy()
cview::ondestroy();
}
opengl框架其他搭建例子:
例1:例2:
openGL環境搭建
include include glshadermanager.h glbatch batch glshadermanager shadermanager 視窗大小改變時接受到的新的寬高,0,0為視窗左下角座標,w,h代表畫素 void changesize int w,int h 為程式作一次性的...
OpenGL環境搭建
2.配置三個檔案 把glut.h 複製到x program files microsoft visual studio 9.0 vc include gl資料夾中,如果沒有gl這個資料夾則可以自己新建乙個。x是你安裝vs的盤符號,如果裝的是vc 的話,裡面有個gl檔案,visual studio 2...
OpenGL環境搭建
2 安裝glad 參考 link 在畫出出色的效果之前,首先要做的就是建立乙個opengl上下文 context 和乙個用於顯示的視窗。然而,這些操作在每個系統上都是不一樣的,opengl有目的地從這些操作抽象 abstract 出去。這意味著我們不得不自己處理建立視窗,定義opengl上下文以及處...