[GitHub link]
Setpixelformat, Initialize Glew, create GL 4,2 context and other operations are encapsulated in MFC class Openglwidget. steps to use :
1. Include OpenGLWidget.h and OpenGLWidget.cpp in the project.
2. Inherit class Openglwidget, implement two virtual functions: Initialize () [responsible for loading data], renderscene () [responsible for rendering] two functions. For example, the following Leftwindow class:
#pragmaOnce#include"OpenGLWidget.h"#include<Cameras/phc.h>#include<OpenglWrappers/DemoMeshes/BlinnPhongMesh.h>classLeftwindow: Publicopenglwidget{redips::P HC*M_PHC =NewRedips::P HC ( $,1.0f,0.1f,10000); Redips::blinnphongmesh* M_mesh =nullptr; Public: Leftwindow () {}~Leftwindow () {
Delete M_mesh; Delete M_PHC;
} BOOLInitialize () {M_mesh=NewRedips::blinnphongmesh (NewRedips::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, -), Heart, REDIPS::FLOAT3 (0,1,0)); return true; } voidRenderscene () {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. Add the following code to the OnInitDialog () function, which creates a openglwidget in the current dialog box
New->create (null, NULL, WS_CHILD | ws_clipsiblings | Ws_clipchildren | ws_visible, CRect (00), This, // This is the parent 0);
MFC+OPENGL Programmable Pipeline