MFC下如何用OpenGL实现贴图

怎么在MFC下用OpenGL把本地指定图片贴进去?我现在只会点OpenGL的一点小基础,我不知道怎么贴图,求求大家给点思路... 怎么在MFC下用OpenGL把本地指定图片贴进去?我现在只会点OpenGL的一点小基础,我不知道怎么贴图,求求大家给点思路 展开
 我来答
  • 你的回答被采纳后将获得:
  • 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
匿名用户
推荐于2016-09-12
展开全部
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
}
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式