OpenGL + MFC basic method for drawing a single document

Source: Internet
Author: User

OpenGL has been searching for images on the Internet for a long time in a single MFC Document, but he has been dissatisfied with what he found, finally, I found a satisfactory answer in the book OpenGL advanced programming and visual system development, but this code has not been found on the internet yet, so I sent it to my blog.

This blog post focuses on the basic framework in the next blog will give the specific function code: http://www.5dkx.com/arch/164.html

Theoretical Basis:
1) set the display pixel format during the creation of a single document window, and set the properties and style of the window as required by OpenGL.
2) first obtain the description table of the Windows device, and then connect it with the preset OpenGL Drawing description table.
3) Call OpenGL to draw images.
4) When you exit the OpenGL Graphic window, release the RC and DC descriptions tables drawn by OpenGL.
The specific programming steps in the MFC single document are as follows:
Eg. Create a project 5dkx.com
1) Add the wm_create, wm_destroy, wm_size, and wm_timer response functions for the 4dkx. comview class.
2) Add the source code to 5dkx. comview. h.
//////////////////////////////////////// ////////////
// Add member functions and member variables
Bool renderscene ();
Bool setuppixelformat (void );
Void setlogicalpalette (void );
Bool initializeopengl (CDC * PDC );
Hglrc m_hrc; // OpenGL plotting description table
HPALETTE m_hPalette; // OpenGL palette
CDC * m_pDC; // OpenGL device description table
3) modify and add the following functions in the 5dkc. comview. cpp file.
5dkx. comVeiw: preCreateWindow ()
5dkx. comVeiw: OnDraw ()
5dkx. comVeiw: OnCreate ()
5dkx. comVeiw: OnDestroy
5dkx. comVeiw: OnSize ()
5dkx. comVeiw: OnTimer (UINT nIDEvent)
Functions to be added
Void 5dkx. comVeiw: SetLogiclPalette (void)
BOOL 5dkx. comVeiw: InitializeOpenGL (CDC * pDC)
BOOL 5dkx. comVeiw: SetupPixelFormat ()
BOOL 5dkx. comVeiw: RenderScene ()

Initial: http://www.5dkx.com/arch/163.html

Non-special instructions are original articles such as reprint, please note: reprint from 5D happy blog [http://www.5DKX.com/]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.