이것은 내가 가지고있는 모든 코드입니다. zx로 시작하는 함수는 마치 완료되면 해당 함수를 기반으로 사용자 정의 라이브러리를 빠르게 조합 할 수 있습니다. 도움이 필요한 기능은 입니다. WM_SIZE 이벤트 atm에서만 사용되는 zxResizeGL입니다.크기 조정 기능을 수정하는 방법
#include <windows.h>
#include <gl/gl.h>
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
void EnableOpenGL(HWND hwnd, HDC*, HGLRC*);
void DisableOpenGL(HWND, HDC, HGLRC);
/* Necessary value we need access to */
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
#define ZX_THIS_INSTANCE ((HINSTANCE)&__ImageBase)
/* We define 2 here so dev can retrieve the FPN b4 it is multiplied by 100 */
#define ZX__PERCENT(NUM, OF) ((NUM)/(OF))
#define ZX_PERCENT(NUM, OF) (ZX__PERCENT(NUM, OF) * 100)
WNDCLASSEX zxGetOSWindowClassEX(void);
BOOL zxInitOSClasses(void);
HWND zxNewOSWindow(int w, int h, int x, int y, char const *text);
HDC hDC = NULL;
HGLRC hRC = NULL;
void zxResizeGL(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1.0, 1.0);
glFlush();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0,
width = 256,
height = width,
w = ZX__PERCENT(width - 20, width),
h = w;
if (!zxInitOSClasses())
return 0;
hwnd = zxNewOSWindow(480, 480, 0, 0, "OpenGL Sample");
ShowWindow(hwnd, nCmdShow);
/* enable OpenGL for the window */
EnableOpenGL(hwnd, &hDC, &hRC);
/* program main loop */
while (!bQuit)
{
/* check for messages */
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
/* handle or dispatch messages */
switch (msg.message)
{
case WM_QUIT:
bQuit = TRUE;
break;
case WM_SIZE:
/* This is where I'm trying to peform the resize */
width = LOWORD(msg.lParam);
height = HIWORD(msg.lParam);
w = ZX__PERCENT(width - 20, width );
h = ZX__PERCENT(height - 20, height);
zxResizeGL(width, height);
break;
default:
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
/* OpenGL animation code goes here */
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(theta, 0.0f, 0.0f, 1.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(0.0f, h);
glColor3f(0.0f, 1.0f, 0.0f); glVertex2f( w, -h);
glColor3f(0.0f, 0.0f, 1.0f); glVertex2f( -w, -h);
glEnd();
glPopMatrix();
SwapBuffers(hDC);
theta += 1.0f;
Sleep (1);
}
}
/* shutdown OpenGL */
DisableOpenGL(hwnd, hDC, hRC);
/* destroy the window explicitly */
DestroyWindow(hwnd);
return msg.wParam;
}
주 코드에서 분리 된 기능에 대한 정의.
WNDCLASSEX zxGetOSWindowClassEX(void)
{
WNDCLASSEX wx = {0};
wx.cbSize = sizeof(WNDCLASSEX);
wx.style = CS_OWNDC;
wx.lpfnWndProc = WindowProc;
wx.hInstance = ZX_THIS_INSTANCE;
wx.hIcon = LoadIcon( NULL, IDI_APPLICATION);
wx.hCursor = LoadCursor(NULL, IDC_ARROW);
wx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wx.lpszClassName = "zxOSWindow";
wx.hIconSm = LoadIcon( NULL, IDI_APPLICATION);
return wx;
}
BOOL zxInitOSClasses(void)
{
WNDCLASSEX wx = zxGetOSWindowClassEX();
if (!RegisterClassEx(&wx))
return 0;
return 1;
}
HWND zxNewOSWindow(int w, int h, int x, int y, char const *text)
{
WNDCLASSEX wx = zxGetOSWindowClassEX();
return CreateWindowEx(
0, wx.lpszClassName, text,
WS_OVERLAPPEDWINDOW,
x, y, w, h, NULL, NULL,
wx.hInstance, NULL);
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
case WM_DESTROY:
return 0;
case WM_KEYDOWN:
{
switch (wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
}
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
void EnableOpenGL(HWND hwnd, HDC* hDC, HGLRC* hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
/* get the device context (DC) */
*hDC = GetDC(hwnd);
/* set the pixel format for the DC */
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat(*hDC, &pfd);
SetPixelFormat(*hDC, iFormat, &pfd);
/* create and enable the render context (RC) */
*hRC = wglCreateContext(*hDC);
wglMakeCurrent(*hDC, *hRC);
}
void DisableOpenGL (HWND hwnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
ReleaseDC(hwnd, hDC);
}
[출력] (https://drive.google.com/file/d/0B7XEqelNSvg9WVVNb3diWl9HUHM/edit?usp=sharing) –
-1 : 확실하지 않은 질문입니다. –
어떻게 불분명합니까? –