zoukankan      html  css  js  c++  java
  • 【转】《基于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头文件,DLLLib文件,下载链接: glutdlls37beta.zip (149 kilobytes),解压缩后把gltu.h放到"VC98/Include/GL"下,把glut.libglut32.lib放到"VC9/Lib" 下glut32.dllglut.dll放到你创建的应用程序的运行目录下
    2, 创建一个MFC SDI应用程序,在项目属性中加入所需要链接的库文件
    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
     
     
  • 相关阅读:
    马踏棋盘的贪心算法
    Windows Phone开发(13):如何规范用户的输入行为
    Windows Phone开发(16):样式和控件模板
    Windows Phone开发(18):变形金刚第九季——变换
    Windows Phone开发(10):常用控件(上)
    Windows Phone开发(14):数据模板
    Windows Phone开发(12):认识一下独具个性的磁贴
    Windows Phone开发(15):资源
    Windows Phone开发(11):常用控件(下)
    Windows Phone开发(17):URI映射
  • 原文地址:https://www.cnblogs.com/lcxu2/p/2004067.html
Copyright © 2011-2022 走看看