4个回答
展开全部
MFC的程序太大,文件太多,这里贴不完,你可以去这个地址看看,学Opengl我是从这里入门的:http://nehe.gamedev.net
一个MFC的程序部分如下:
#include "stdafx.h"
#include "NeheMFC.h"
#include "NeheWindow.h"
#include "Main.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
static float angle=0,rot1,rot2;
CMain::CMain()
{
// Start Of User Initialization
}
CMain::~CMain()
{
}
BOOL CMain::KeyPressed(int nCode)
{
if( nCode >= 0 && nCode <= 255 )
{
return theApp.keyDown[ nCode ];
}
return FALSE;
}
BOOL CMain::Initialize()
{
angle = 0.0f; // Set Starting Angle To Zero
glClearColor (0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth (1.0f); // Depth Buffer Setup
glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
glEnable (GL_DEPTH_TEST); // Enable Depth Testing
glShadeModel (GL_SMOOTH); // Select Smooth Shading
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate
return TRUE;
}
void CMain::Deinitialize()
{
}
void CMain::Update(DWORD milliseconds)
{
if (KeyPressed(VK_ESCAPE) == TRUE) // Is ESC Being Pressed?
{
theApp.TerminateApplication (); // Terminate The Program
}
if (KeyPressed(VK_F1) == TRUE) // Is F1 Being Pressed?
{
theApp.ToggleFullScreen (); // Toggle Fullscreen Mode
}
angle += (float)(milliseconds) / 5.0f; // Update angle Based On The Clock
}
void CMain::Draw()
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity (); // Reset The Modelview Matrix
glTranslatef (0.0f, 0.0f, -6.0f); // Translate 6 Units Into The Screen
glRotatef (angle, 0.0f, 1.0f, 0.0f); // Rotate On The Y-Axis By angle
for (rot1=0; rot1<2; rot1++) // 2 Passes
{
glRotatef(90.0f,0.0f,1.0f,0.0f); // Rotate 90 Degrees On The Y-Axis
glRotatef(180.0f,1.0f,0.0f,0.0f); // Rotate 180 Degress On The X-Axis
for (rot2=0; rot2<2; rot2++) // 2 Passes
{
glRotatef(180.0f,0.0f,1.0f,0.0f); // Rotate 180 Degrees On The Y-Axis
glBegin (GL_TRIANGLES); // Begin Drawing Triangles
glColor3f (1.f, 0.f, 0.f); glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f (0.f, 1.f, 0.f); glVertex3f(-1.0f,-1.0f, 1.0f);
glColor3f (0.f, 0.f, 1.f); glVertex3f( 1.0f,-1.0f, 1.0f);
glEnd (); // Done Drawing Triangles
}
}
glFlush (); // Flush The GL Rendering Pipeline
}
请去NEHE的网站下载例子。
一个MFC的程序部分如下:
#include "stdafx.h"
#include "NeheMFC.h"
#include "NeheWindow.h"
#include "Main.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
static float angle=0,rot1,rot2;
CMain::CMain()
{
// Start Of User Initialization
}
CMain::~CMain()
{
}
BOOL CMain::KeyPressed(int nCode)
{
if( nCode >= 0 && nCode <= 255 )
{
return theApp.keyDown[ nCode ];
}
return FALSE;
}
BOOL CMain::Initialize()
{
angle = 0.0f; // Set Starting Angle To Zero
glClearColor (0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth (1.0f); // Depth Buffer Setup
glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
glEnable (GL_DEPTH_TEST); // Enable Depth Testing
glShadeModel (GL_SMOOTH); // Select Smooth Shading
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate
return TRUE;
}
void CMain::Deinitialize()
{
}
void CMain::Update(DWORD milliseconds)
{
if (KeyPressed(VK_ESCAPE) == TRUE) // Is ESC Being Pressed?
{
theApp.TerminateApplication (); // Terminate The Program
}
if (KeyPressed(VK_F1) == TRUE) // Is F1 Being Pressed?
{
theApp.ToggleFullScreen (); // Toggle Fullscreen Mode
}
angle += (float)(milliseconds) / 5.0f; // Update angle Based On The Clock
}
void CMain::Draw()
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity (); // Reset The Modelview Matrix
glTranslatef (0.0f, 0.0f, -6.0f); // Translate 6 Units Into The Screen
glRotatef (angle, 0.0f, 1.0f, 0.0f); // Rotate On The Y-Axis By angle
for (rot1=0; rot1<2; rot1++) // 2 Passes
{
glRotatef(90.0f,0.0f,1.0f,0.0f); // Rotate 90 Degrees On The Y-Axis
glRotatef(180.0f,1.0f,0.0f,0.0f); // Rotate 180 Degress On The X-Axis
for (rot2=0; rot2<2; rot2++) // 2 Passes
{
glRotatef(180.0f,0.0f,1.0f,0.0f); // Rotate 180 Degrees On The Y-Axis
glBegin (GL_TRIANGLES); // Begin Drawing Triangles
glColor3f (1.f, 0.f, 0.f); glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f (0.f, 1.f, 0.f); glVertex3f(-1.0f,-1.0f, 1.0f);
glColor3f (0.f, 0.f, 1.f); glVertex3f( 1.0f,-1.0f, 1.0f);
glEnd (); // Done Drawing Triangles
}
}
glFlush (); // Flush The GL Rendering Pipeline
}
请去NEHE的网站下载例子。
展开全部
MFC使用opengl作图,是需要安装opengl库的,自身是没有的!
安装好后,看opengl的手册才可以,M$自身的vc是没有的
而且opengl是不需要mfc的,符合标准c++即可。
安装好后,看opengl的手册才可以,M$自身的vc是没有的
而且opengl是不需要mfc的,符合标准c++即可。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
http://hi.baidu.com/aepsilon/blog/category/%BC%C6%CB%E3%BB%FA%CD%BC%D0%CE%D1%A7/index/1
opengl入门教程, 从安装到基本的画图过程设置都有. 共8个教程
opengl入门教程, 从安装到基本的画图过程设置都有. 共8个教程
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
首先要定义环境,就是设置像素格式,使OPenGL的函数和MFC的窗口联系在一起,之后的事情就是和C编程类似,调用OpenGL库函数。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询