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
}
一个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
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询