码迷,mamicode.com
首页 > 编程语言 > 详细

MFC+OpenGL可编程管线

时间:2018-05-06 20:10:46      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:.com   targe   let   oid   pen   opengl   class   虚函数   对话框   

[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(); } };

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);

 

MFC+OpenGL可编程管线

标签:.com   targe   let   oid   pen   opengl   class   虚函数   对话框   

原文地址:https://www.cnblogs.com/redips-l/p/8999184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!