На страницу группы практики...
. . .
#pragma warning(disable: 4244 4996)
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#pragma comment(lib, "opengl32")
#pragma comment(lib, "glu32")
. . .
typedef struct tagvg4ANIM
{
HWND hWnd;
HDC hDC;
HGLRC hRC;
. . .
} vg4ANIM;
. . .
BOOL VG4_Init( HWND hWnd )
{
INT i;
PIXELFORMATDESCRIPTOR pfd = {0};
. . .
VG4_Anim.hDC = GetDC(hWnd);
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI |
PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
i = ChoosePixelFormat(VG4_Anim.hDC, &pfd);
DescribePixelFormat(VG4_Anim.hDC, i,
sizeof(PIXELFORMATDESCRIPTOR), &pfd);
SetPixelFormat(VG4_Anim.hDC, i, &pfd);
VG4_Anim.hRC = wglCreateContext(VG4_Anim.hDC);
wglMakeCurrent(VG4_Anim.hDC, VG4_Anim.hRC);
. . .
}
VOID VG4_Close( VOID )
{
wglMakeCurrent(NULL, NULL);
wglDeleteContext(VG4_Anim.hRC);
ReleaseDC(VG4_Anim.hWnd, VG4_Anim.hDC);
. . .
}
VOID VG4_Resize( INT Width, INT Height )
{
. . .
glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0 * Width / Height, 1.0 * Width / Height, -1, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
}
VOID VG4_Render( VOID )
{
if (!VG4_IsInit)
return;
glClear(GL_COLOR_BUFFER_BIT);
if (VG4_RenderFunc != NULL)
VG4_RenderFunc(&VG4_Anim);
glFinish();
}
VOID VG4_CopyFrame( HDC hDC )
{
SwapBuffers(hDC);
VG4_FrameCount++;
}
. . .
static VOID Render( vg4ANIM *Ani )
{
static CHAR Buf[100];
sprintf(Buf, "FPS: %.3f ", Ani->FPS);
SetWindowText(Ani->hWnd, Buf);
glLoadIdentity();
glRotated(Ani->JAxisX * 90, 1, 0, 0);
glRotated(Ani->JAxisY * 90, 0, 1, 0);
glRotated(Ani->JAxisZ * 90, 0, 0, 1);
glColor3d(1, 0, 0);
glRectd(0, 0, 0.5, 0.5);
glLoadIdentity();
glColor3d(1, 1, 0);
glRectd(0, 0, -0.5, -0.5);
}