【转】《基于MFC的OpenGL编程》Part 2 Setting up OpenGL on Windows(1)

本文源代码下载:OpenGL_ch2.rar
 
WGL – Windows OpenGL 扩展层
The WGL extension consists of a set of functions (wglCreateContext, wglDeleteContext etc.) and structures (such as PIXELFORMATDESCRIPTOR, GLYPHMETRICSFLOAT) etc. Thus every OpenGL implementation has a platform-specific portion which has to be set up and used according to the particular platform.
设备上下文
The Windows Graphical Device Interface (GDI) is capable of drawing to screen, to memory, to printers or to any other device that provides a GDI interface layer and that can process GDI calls. GDI accomplishes this by a rendering handle to the currently selected device, which is called the device context, or DC.
绘制上下文
A rendering context is the OpenGL equivalent of the GDI DC. All OpenGL calls are rendered to the device through a RC. The rendering context maintains OpenGL state variables such as current background color, current color etc. just as the DC maintains GDI state variables such as current pen, current brush etc.
像素格式
Pixel formats are the translation layer between OpenGL calls and the rendering operation that Windows performs.
举个例子,若像素格式只支持很少一部分颜色值,则 OpenGL 在用 RGB 值 (128,120,135) 绘制一个像素时,就可能使用转换后的值 (128,128,128) 来绘制 .
The pixel format selected essentially describes such things as how colors are displayed, depth of field resolution and what additional capabilities are supported by the rendering context created.
第一个基于MFCOpenGL应用程
开发环境:VC6.0
1, 首先下载需要的 GLUT 头文件 ,DLL 和 Lib 文件,下载链接 : glutdlls37beta.zip (149 kilobytes), 解压缩后把 gltu.h 放到 "VC98/Include/GL" 下,把 glut.lib 和 glut32.lib 放到 "VC9/Lib" 下 , glut32.dll 和 glut.dll 放到你创建的应用程序的运行目录下
2, 创建一个 MFC SDI 应用程序,在项目属性中加入所需要链接的库文件
2008110501.jpg
1, 在stdafx.h中加入下列语句: 2, 打开ClassWizard,选择CCY457OpenGLView类,为下述消息加入消息处理函数:WM_CREATE (for OnCreate), WM_DESTROY (for OnDestroy), WM_SIZE (for OnSize), WM_ERASEBACKGROUND (for OnEraseBkground).
//OpenGL Headers

#include
<gl/gl.h>

#include
<gl/glu.h>

#include
<gl/glut.h>

#include
<gl/glaux.h>
 
3,在窗口创建之前我们必须设置窗口风格包含WS_CLIPCHILDREN WS_CLIPSIBLINGS,从而避免OpenGL绘制到其他窗口中去。这些应该放在PreCreateWindow()中。
BOOL CCY457OpenGLView::PreCreateWindow(CREATESTRUCT& cs)
{
    
// TODO: Modify the Window class or styles here by modifying
    
//    the CREATESTRUCT cs
    
//An OpenGL Window must be created with the following flags
     cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
    
return CView::PreCreateWindow(cs);
}
4, 在 CCY457OpenGLView.h 中加入如下语句:
     HGLRC m_hRC;    //Rendering Context
     CDC* m_pDC;        //Device Context
     BOOL InitializeOpenGL();    //Initialize OpenGL
     BOOL SetupPixelFormat();    //Set up the Pixel Format
    void RenderScene();            //Render the Scene
 
 

转载于:https://www.cnblogs.com/lcxu2/archive/2010/11/23/2004067.html

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、下4载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、下4载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、 4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值