mfc opengl使用者嚮導原程式工程,此次修正了沒有中文支援的錯誤。
3.執行build命令,整合開發環境會生成mfc opengl.awx,並自動拷貝到」c:\program files\microsoft visual studio\common\msdev98\template「目錄下。
編輯opengl嚮導檔案。
1、在stdafx.h新增opengl標頭檔案,並新增lib。
2、編寫initopengl()、destroyopengl()函式。
fileview檔案檢視,在template files目錄下開啟view.h,在publiac新增hglrc hglrc;cclientdc *m_pdc;bool initopengl();
// attributes
public:
hglrc hglrc;
cclientdc *m_pdc;
// operations
public:
bool initopengl();
void destroyopengl();
在view.cpp新增函式實現
bool $$view_class$$::initopengl(
);void
$$view_class$$::destroyopengl()
/
// $$view_class$$ message handlers 自定義的函式一定要在此句話之後,不要放在末尾,否則指示錯誤檔案不正確結束。
bool $$view_class$$::initopengl()
if(!setpixelformat(m_pdc->getsafehdc(),m_glpixelindex,&pixeldesc)) //設定畫素格式
return false;
hglrc=wglcreatecontext(m_pdc->getsafehdc());//產生乙個新的opengl繪圖描述表使之適合在引數hdc給出的裝置上畫圖
wglmakecurrent(m_pdc->getsafehdc(),hglrc);
light();//設定光照環境
myinit();//設定繪圖環境
return true;
}
void $$view_class$$::destroyopengl()
$$view_class$$::~$$view_class$$()
3、新增light()設定光照條件和myinit()設定繪圖環境函式// operations
public:
bool initopengl();
void destroyopengl();
void light();
void myinit();
void $$view_class$$::light()
; float diffuseproperties = ;
float specularproperties = ;
// glfloat position = ;//光在水平座標系中的位置
gllightfv( gl_light0, gl_ambient, ambientproperties);
gllightfv( gl_light0, gl_diffuse, diffuseproperties);
gllightfv( gl_light0, gl_specular, specularproperties);
// gllightfv( gl_light0, gl_position, position);//設定光源引數,v表示引數用向量形式position被設定
gllightmodelf(gl_light_model_two_side, 1.0);
// back material
float matambientback = ;
glmaterialfv(gl_back,gl_ambient,matambientback);
// setmaterial(m_glmat[0],false);
float ambient = ;
float diffuse = ;
float specular = ;
float emission = ;
float shininess = ;
// change
// if(string == "silver")
glmaterialfv( gl_front, gl_ambient, ambient);
glmaterialfv( gl_front, gl_diffuse, diffuse);
glmaterialfv( gl_front, gl_specular, specular);
glmaterialfv( gl_front, gl_shininess, shininess);
glmaterialfv( gl_front, gl_emission, emission); }
void $$view_class$$::myinit()
4、新增視點、投影矩陣// attributes
public:
hglrc hglrc;
cclientdc *m_pdc;
glint m_viewport[4];
glfloat m_modelmatrix[16], m_prjmatrix[16];
5、新增resizeopengl,
void resizeopengl(glint *viewport, glfloat *projmatrix, int cx, int cy);
void $$view_class$$::resizeopengl(glint *m_viewport, glfloat *projmatrix, int cx, int cy)
6、新增繪製場景函式public:
bool initopengl();
void destroyopengl();
void light();
void myinit();
void resizeopengl(glint *viewport, glfloat *projmatrix, int cx, int cy);
void drawscene();
void $$view_class$$::drawscene()
//示例 下面添上繪圖**
gltranslatef(0.0f,0.0f,-3.0f);
glrotatef(90.0f,1.0f,0.0f,0.0f);
//gl_quads每四個連續的頂點定義乙個四邊形
glbegin(gl_quads); //立方體頂面
glcolor3f(1.0f,0.0f,1.0f);
glvertex3f(-0.5,0.5f,0.5f); //1點
glcolor3f(1.0f,1.0f,1.0f);
glvertex3f(0.5f,0.5f,0.5f); //3點
glcolor3f(0.0f,1.0f,1.0f);
glvertex3f(0.5f,0.5f,-0.5f); //5點
glcolor3f(0.0f,0.0f,1.0f);
glvertex3f(-0.5f,0.5f,-0.5f); //7點
glend();
}void $$view_class$$::ondraw(cdc* pdc)
bbusy=true; //雙快取應用
glclearcolor(0.0f,0.0f,0.0f,1.0f);//背景色
glclear(gl_color_buffer_bit|gl_depth_buffer_bit); //清除顏色快取和深度快取
glmatrixmode(gl_modelview); //設定矩陣為模型矩陣
glloadidentity(); //用單位矩陣替換當前矩陣
//繪製圖形
drawscene();
glfinish();//完成繪製
swapbuffers(wglgetcurrentdc());//雙快取應用
>bbusy=false;//結束
$$endif //verbose
}
使用mfc opengl嚮導創立應用程式,新建一單文件程式後,新增三行**即可,initopengl/destroyopengl/resizeopengl();
int cttview::oncreate(lpcreatestruct lpcreatestruct)
void cttview::ondestroy()
void cttview::onsize(uint ntype, int cx, int cy)
利用vc呼叫dll
一時興起,研究下關於dll的呼叫,算是作為我首次發表文章啦,怎麼說也是我的處子作啊 好吧入正題啦 關於dll的呼叫,查了下資料,有兩種 一 靜態呼叫 二 動態呼叫,下面是分別的呼叫方法 一 靜態呼叫 3 用vc開啟mytest工程,選中工程,然後選擇vc選單下的project settings 二 ...
利用DEBUG API編寫Loader Path
loader並不是什麼很神秘的技術,微軟提供了一組debug api來方便第三方監視程式.這裡我用debug api製作了乙個簡單的loader程式.這個loader要幹的事有 1.啟動目標程式.2.讀取 修改目標程式的記憶體 或 暫存器 用到的debug api有 createprocess 用於...
VC 利用ADO操作Excel
把excel當做資料庫來操作,步驟如下 1 在stdafx.h中加入 import c program files common files system ado msado15.dll no namespace rename eof adoeof connectionptr pcon ex cst...