资源简介
基于MFC对话框的OpenGL三维显示(picture control 类版)
代码片段和文件信息
#include “stdafx.h“
#include “MyStatic.h“
#include
CMyStatic::CMyStatic()
{
}
CMyStatic::~CMyStatic()
{
}
BEGIN_MESSAGE_MAP(CMyStatic CStatic)
ON_WM_TIMER()
END_MESSAGE_MAP()
void CMyStatic::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
GLDraw(); //定时器中调用这个函数
CStatic::OnTimer(nIDEvent);
}
void CMyStatic::PreSubclassWindow()
{
// TODO: 在此添加专用代码和/或调用基类
InitGL();
CStatic::PreSubclassWindow();
}
// OpenGL绘制
void CMyStatic::GLDraw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-0.0f 0.0f -10.0f);
static int RotateDegTriangle = 1;
glRotatef(RotateDegTriangle++ 0.0f 1.0f 0.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f 0.0f 0.0f);
glVertex3f(0.0f 2.0f 0.0f);
glColor3f(0.0f 1.0f 0.0f);
glVertex3f(-1.0f 0.0f 1.0f);
glColor3f(0.0f 0.0f 1.0f);
glVertex3f(1.0f 0.0f 1.0f);
glColor3f(1.0f 0.0f 0.0f);
glVertex3f(0.0f 2.0f 0.0f);
glColor3f(0.0f 0.0f 1.0f);
glVertex3f(1.0f 0.0f 1.0f);
glColor3f(0.0f 1.0f 0.0f);
glVertex3f(1.0f 0.0f -1.0f);
glColor3f(1.0f 0.0f 0.0f);
glVertex3f(0.0f 2.0f 0.0f);
glColor3f(0.0f 1.0f 0.0f);
glVertex3f(1.0f 0.0f -1.0f);
glColor3f(0.0f 0.0f 1.0f);
glVertex3f(-1.0f 0.0f -1.0f);
glColor3f(1.0f 0.0f 0.0f);
glVertex3f(0.0f 2.0f 0.0f);
glColor3f(0.0f 0.0f 1.0f);
glVertex3f(-1.0f 0.0f -1.0f);
glColor3f(0.0f 1.0f 0.0f);
glVertex3f(-1.0f 0.0f 1.0f);
glEnd();
#ifdef TWO_OBJS
glLoadIdentity();
glTranslatef(5.0f 0.0f -15.0f);
RotateDegQuad += 3.0f;
glRotatef(RotateDegQuad 1.0f 1.0f 0.0f);
glBegin(GL_QUADS);
glColor3f(1.0f 1.0f 0.0f);
glVertex3f(-1.0f 1.0f 0.0f);
glVertex3f(-1.0f -1.0f 0.0f);
glVertex3f(1.0f -1.0f 0.0f);
glVertex3f(1.0f 1.0f 0.0f);
glEnd();
#endif
SwapBuffers(hdc); //利用双缓冲
}
// OpenGl初始化
bool CMyStatic::InitGL()
{
static PIXELFORMATDEscriptOR pfd =
{
sizeof(PIXELFORMATDEscriptOR)
1
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER
PFD_TYPE_RGBA
24
0 0 0 0 0 0
0
0
0
0 0 0 0
32
0
0
PFD_MAIN_PLANE
0
0 0 0
};
int pixelformat;
hdc = ::GetDC(this->GetSafeHwnd());
if (!(pixelformat = ChoosePixelFormat(hdc &pfd)))
{
MessageBox(“ChoosePixelFormat failed!“);
return false;
}
if (!SetPixelFormat(hdc pixelformat &pfd))
{
MessageBox(“SetPixelFormat failed!“);
return false;
}
if (!(hglrc = wglCreateContext(hdc)))
{
MessageBox(“CreateContext failed!“);
return false;
}
if (!wglMakeCurrent(hdc hglrc))
{
MessageBox(“MakeCurrent failed!“);
return false;
}
CRect rect; //在这个矩形中画图
GetClientRect(rect);
glViewport(0 0 rect.Width() rect.Height());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
/*gluPerspective(45.0f rect.Width()/rect.Height() 0.1f 100.0f);// 计算窗口的外观比例*/
gluPersp
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 23040 2017-01-05 16:14 [初级]PictureControl\.vs\OControl\v14\.suo
文件 213504 2017-01-05 16:09 [初级]PictureControl\Debug\OControl.exe
文件 1403800 2017-01-05 16:09 [初级]PictureControl\Debug\OControl.ilk
文件 2846720 2017-01-05 16:09 [初级]PictureControl\Debug\OControl.pdb
文件 34815 2017-01-05 16:09 [初级]PictureControl\OControl\Debug\MyStatic.obj
文件 308 2017-01-05 16:09 [初级]PictureControl\OControl\Debug\OControl.log
文件 69553 2017-01-05 16:08 [初级]PictureControl\OControl\Debug\OControl.obj
文件 55312384 2017-01-05 15:58 [初级]PictureControl\OControl\Debug\OControl.pch
文件 69260 2017-01-05 15:58 [初级]PictureControl\OControl\Debug\OControl.res
文件 2742 2017-01-05 16:09 [初级]PictureControl\OControl\Debug\OControl.tlog\CL.command.1.tlog
文件 82812 2017-01-05 16:09 [初级]PictureControl\OControl\Debug\OControl.tlog\CL.read.1.tlog
文件 2832 2017-01-05 16:09 [初级]PictureControl\OControl\Debug\OControl.tlog\CL.write.1.tlog
文件 1666 2017-01-05 16:09 [初级]PictureControl\OControl\Debug\OControl.tlog\li
文件 6396 2017-01-05 16:09 [初级]PictureControl\OControl\Debug\OControl.tlog\li
文件 824 2017-01-05 16:09 [初级]PictureControl\OControl\Debug\OControl.tlog\li
文件 192 2017-01-05 16:09 [初级]PictureControl\OControl\Debug\OControl.tlog\OControl.lastbuildstate
文件 346 2017-01-05 15:58 [初级]PictureControl\OControl\Debug\OControl.tlog\rc.command.1.tlog
文件 2950 2017-01-05 15:58 [初级]PictureControl\OControl\Debug\OControl.tlog\rc.read.1.tlog
文件 210 2017-01-05 15:58 [初级]PictureControl\OControl\Debug\OControl.tlog\rc.write.1.tlog
文件 30701 2017-01-05 16:08 [初级]PictureControl\OControl\Debug\OControlDlg.obj
文件 929616 2017-01-05 15:58 [初级]PictureControl\OControl\Debug\stdafx.obj
文件 2386944 2017-01-05 16:09 [初级]PictureControl\OControl\Debug\vc140.idb
文件 6754304 2017-01-05 16:09 [初级]PictureControl\OControl\Debug\vc140.pdb
文件 3322 2017-01-05 16:11 [初级]PictureControl\OControl\MyStatic.cpp
文件 317 2017-01-05 15:58 [初级]PictureControl\OControl\MyStatic.h
文件 107672 2017-01-05 15:58 [初级]PictureControl\OControl\OControl.aps
文件 2396 2017-01-05 15:44 [初级]PictureControl\OControl\OControl.cpp
文件 455 2017-01-05 15:44 [初级]PictureControl\OControl\OControl.h
文件 9490 2017-01-05 15:58 [初级]PictureControl\OControl\OControl.rc
文件 10679 2017-01-05 15:58 [初级]PictureControl\OControl\OControl.vcxproj
............此处省略24个文件信息
评论
共有 条评论