zoukankan      html  css  js  c++  java
  • MFC+OpenGL可编程管线

    [github链接]

    网上的代码大都是固定管线渲染的,今天下午整理了下,把setPixelFormat、初始化glew、创建GL 4,2 context等操作封装到一个MFC类OpenGLWidget里。使用步骤

    1. 把OpenGLWidget.h和OpenGLWidget.cpp包含在项目里面。

    2. 继承类OpenGLWidget,实现两个虚函数:Initialize()[负责加载数据]、RenderScene()[负责渲染]两个函数。比如下面的LeftWindow类:

    #pragma once
    #include "OpenGLWidget.h"
    
    #include <Cameras/phc.h>
    #include <OpenglWrappers/DemoMeshes/BlinnPhongMesh.h>
    
    class LeftWindow : public OpenGLWidget{
        redips::PhC *m_phc = new redips::PhC(45, 1.0f, 0.1f, 10000);
        redips::BlinnPhongMesh* m_mesh = nullptr;
    public:
        LeftWindow(){}
        ~LeftWindow(){
        delete m_mesh; delete m_phc;
    }
    bool Initialize(){ m_mesh = new redips::BlinnPhongMesh(new redips::Triangles("E:/Documents/models/Effier/new_iffier.obj"));
         auto heart
    = m_mesh->model_ptr()->aabb_R().heart(); m_phc->lookAt(heart + redips::float3(0, 0, 500), heart, redips::float3(0, 1, 0)); return true; } void RenderScene(){ m_mesh->uniformFloat3("lightColor", redips::float3(1, 1, 1)); m_mesh->uniformFloat3("lightPos", m_phc->pos()); m_mesh->uniformFloat3("cameraPos", m_phc->pos()); m_mesh->uniformMat44f("model", redips::Mat44f::eye().ptr()); m_mesh->uniformMat44f("projection", m_phc->glProjection().ptr()); m_mesh->uniformMat44f("view", m_phc->glView().ptr()); m_mesh->draw(); } };

    [redips是我封装的渲染相关的类,详细介绍]

    3. 将下面代码添加到OnInitDialog()函数里,即在当前对话框里创建了一个OpenGLWidget

    m_leftWindow = new LeftWindow;
    m_leftWindow ->Create(NULL, NULL, WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE,
                                CRect(0, 0, 800, 800),
                                this,   //this is the parent
                                0);
  • 相关阅读:
    利用window.onerror收集js代码异常
    js 基础题复习
    正则12和\1的理解
    CodeReview 方法 规范
    前端的登陆 几种类型
    http协议相关知识
    javascript中apply、call和bind的区别 详细易懂
    http常见的状态码,400,401,403 前端看
    vue中使用file-saver 下载各类文件
    js下载文件到本地各种方法总结
  • 原文地址:https://www.cnblogs.com/redips-l/p/8999184.html
Copyright © 2011-2022 走看看