Using OpenGL to realize animation effect

Source: Internet
Author: User
Tags clear screen constructor

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 ().

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.