This program simulates animation effects by constantly changing the position of the viewport, and introduces some of the necessary preparations for OpenGL drawing.
First, a new "Win32 application" of the Empty project.
Second, then "Glu32.lib glaux.lib opengl32.lib" into the project.
In the project-> setup->general, replace "Microsoft Foundation Classes" with "use MFC in a Static Library".
Because we are building an empty project, we must add the necessary class code for this project. First build a Openglapp class, the base class is CWinApp, the constructors and destructors are all empty, and a BOOL InitInstance () is added to display the window. The contents are as follows: OpenGLWin* pMainWnd = new OpenGLWin;
pMainWnd->ShowWindow(SW_SHOWNORMAL);
pMainWnd->UpdateWindow();
m_pMainWnd = pMainWnd;
return TRUE;
don't forget to add the App object Openglapp app in the implementation file;
Five, the following establishes another class Openglwin, its base class is CFrameWnd
Manually add the following message mappings: protected:
afx_msg int OnCreate (lpcreatestruct lpcreatestruct);
afx_msg void OnPaint ();
afx_msg void OnDestroy ();
Declare_message_map ()
Add the following functions and variables: void Drawsphere ();
void Ondrawsin ();
void Myinit (); The
HGLRC HGLRC//rc handle
header file is constructed. Here is the implementation file: First add header file #include "gl\gl.h"
#include "gl\glu.h"
#include "gl\glaux.h"
#include <math.h>
is added manually before the constructor: begin_message_map (Openglwin, CFrameWnd)
On_wm_create ()
On_wm_paint ()
On_ The contents of the Wm_destroy ()
End_message_map ()
constructor are as follows: Myinit ();
Create (NULL, "Openglapp---FLoat workstudio"); The
is used to create the default window and initialize it. initialization function: void Openglwin::myinit ()
{
Glclearcolor (0.0,0.0,0.0,1.0);////background color Clear screen
Glclear (gl_color_ Buffer_bit);
//Glvertex3d (0.4,0.4,0.4);
}
The following drawsphere () is used to draw the solid ball. The Ondrawsin () is used to simulate the sinusoidal curves of the two cycles by changing the viewport to use the Drawsphere ()-drawn ball. Finally, call Ondrawsin () in OnPaint () to draw the animation inside the window. And of course don't forget the necessary destruction work OnDestroy ().