标签:stdcall ane gis buffer wpa extra remove oop release
作者:i_dovelemon
日期:2017-03-12
来源:CSDN
主题:OpenGL, Render Context
g_DC = GetDC(g_Hwnd); // Set surface pixel format PIXELFORMATDESCRIPTOR pixel_desc; pixel_desc.nSize = sizeof(pixel_desc); //WORD nSize; pixel_desc.nVersion = 1; //WORD nVersion; pixel_desc.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;//DWORD dwFlags; pixel_desc.iPixelType = PFD_TYPE_RGBA; //BYTE iPixelType; pixel_desc.cColorBits = 32; //BYTE cColorBits; pixel_desc.cRedBits = 0;//BYTE cRedBits; pixel_desc.cRedShift = 0;//BYTE cRedShift; pixel_desc.cGreenBits = 0;//BYTE cGreenBits; pixel_desc.cGreenShift = 0;//BYTE cGreenShift; pixel_desc.cBlueBits = 0;//BYTE cBlueBits; pixel_desc.cBlueShift = 0;//BYTE cBlueShift; pixel_desc.cAlphaBits = 0;//BYTE cAlphaBits; pixel_desc.cAlphaShift = 0;//BYTE cAlphaShift; pixel_desc.cAccumBits = 0;//BYTE cAccumBits; pixel_desc.cAccumRedBits = 0;//BYTE cAccumRedBits; pixel_desc.cAccumGreenBits = 0;//BYTE cAccumGreenBits; pixel_desc.cAccumBlueBits = 0;//BYTE cAccumBlueBits; pixel_desc.cAccumAlphaBits = 0;//BYTE cAccumAlphaBits; pixel_desc.cDepthBits = 24;//BYTE cDepthBits; pixel_desc.cStencilBits = 8;//BYTE cStencilBits; pixel_desc.cAuxBuffers = 0;//BYTE cAuxBuffers; pixel_desc.iLayerType = PFD_MAIN_PLANE;//BYTE iLayerType; pixel_desc.bReserved = 0;//BYTE bReserved; pixel_desc.dwLayerMask = 0;//DWORD dwLayerMask; pixel_desc.dwVisibleMask = 0;//DWORD dwVisibleMask; pixel_desc.dwDamageMask = 0;//DWORD dwDamageMask; int pixel_fmt = ChoosePixelFormat(g_DC, &pixel_desc); if (pixel_fmt == 0) { MessageBox(NULL, NULL, L"Error", MB_OK); return; } if (SetPixelFormat(g_DC, pixel_fmt, &pixel_desc) == FALSE) { MessageBox(NULL, NULL, L"Error", MB_OK); return; } int n = GetPixelFormat(g_DC); DescribePixelFormat(g_DC, n, sizeof(pixel_desc), &pixel_desc);
// Create opengl render context g_GLRC = wglCreateContext(g_DC); if (g_GLRC == NULL) { MessageBox(NULL, NULL, L"Error", MB_OK); return; } wglMakeCurrent(g_DC, g_GLRC);
wglMakeCurrent(g_DC, NULL); wglDeleteContext(g_GLRC);
#include <Windows.h> #include <GL\glew.h> //-------------------------------------------------------------------------------------- // Variables //-------------------------------------------------------------------------------------- HWND g_Hwnd; HDC g_DC; HGLRC g_GLRC; //-------------------------------------------------------------------------------------- // Function Declaration //-------------------------------------------------------------------------------------- void opengl_init(); void opengl_run(); void opengl_destroy(); LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); //-------------------------------------------------------------------------------------- // Function Definition //-------------------------------------------------------------------------------------- int _stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR cmdLine, int nShowCmd) { // Register window class WNDCLASSEX wnd; wnd.cbClsExtra = 0; wnd.cbSize = sizeof(wnd); wnd.cbWndExtra = NULL; wnd.hbrBackground = HBRUSH(COLOR_WINDOW + 1); wnd.hCursor = LoadCursor(NULL, IDC_ARROW); wnd.hIcon = NULL; wnd.hIconSm = NULL; wnd.hInstance = hInstance; wnd.lpfnWndProc = WndProc; wnd.lpszClassName = L"OpenGLRC"; wnd.lpszMenuName = NULL; wnd.style = CS_HREDRAW | CS_VREDRAW; if (!RegisterClassEx(&wnd)) { MessageBox(NULL, NULL, L"Fuck you", MB_OK); return -1; } // Create window RECT client_rect = {0, 0, 800, 600}; AdjustWindowRect(&client_rect, WS_OVERLAPPEDWINDOW, FALSE); g_Hwnd = CreateWindowEx(0, L"OpenGLRC", L"OpenGL", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT , client_rect.right - client_rect.left, client_rect.bottom - client_rect.top, NULL, NULL, hInstance, NULL); if (g_Hwnd == NULL) { int err = GetLastError(); MessageBox(NULL, NULL, L"Error", MB_OK); return -1; } ShowWindow(g_Hwnd, nShowCmd); opengl_init(); // Message loop MSG msg = {0}; while (msg.message != WM_QUIT) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { opengl_run(); } } opengl_destroy(); return 0; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } void opengl_init() { g_DC = GetDC(g_Hwnd); // Set surface pixel format PIXELFORMATDESCRIPTOR pixel_desc; pixel_desc.nSize = sizeof(pixel_desc); //WORD nSize; pixel_desc.nVersion = 1; //WORD nVersion; pixel_desc.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;//DWORD dwFlags; pixel_desc.iPixelType = PFD_TYPE_RGBA; //BYTE iPixelType; pixel_desc.cColorBits = 32; //BYTE cColorBits; pixel_desc.cRedBits = 0;//BYTE cRedBits; pixel_desc.cRedShift = 0;//BYTE cRedShift; pixel_desc.cGreenBits = 0;//BYTE cGreenBits; pixel_desc.cGreenShift = 0;//BYTE cGreenShift; pixel_desc.cBlueBits = 0;//BYTE cBlueBits; pixel_desc.cBlueShift = 0;//BYTE cBlueShift; pixel_desc.cAlphaBits = 0;//BYTE cAlphaBits; pixel_desc.cAlphaShift = 0;//BYTE cAlphaShift; pixel_desc.cAccumBits = 0;//BYTE cAccumBits; pixel_desc.cAccumRedBits = 0;//BYTE cAccumRedBits; pixel_desc.cAccumGreenBits = 0;//BYTE cAccumGreenBits; pixel_desc.cAccumBlueBits = 0;//BYTE cAccumBlueBits; pixel_desc.cAccumAlphaBits = 0;//BYTE cAccumAlphaBits; pixel_desc.cDepthBits = 24;//BYTE cDepthBits; pixel_desc.cStencilBits = 8;//BYTE cStencilBits; pixel_desc.cAuxBuffers = 0;//BYTE cAuxBuffers; pixel_desc.iLayerType = PFD_MAIN_PLANE;//BYTE iLayerType; pixel_desc.bReserved = 0;//BYTE bReserved; pixel_desc.dwLayerMask = 0;//DWORD dwLayerMask; pixel_desc.dwVisibleMask = 0;//DWORD dwVisibleMask; pixel_desc.dwDamageMask = 0;//DWORD dwDamageMask; int pixel_fmt = ChoosePixelFormat(g_DC, &pixel_desc); if (pixel_fmt == 0) { MessageBox(NULL, NULL, L"Error", MB_OK); return; } if (SetPixelFormat(g_DC, pixel_fmt, &pixel_desc) == FALSE) { MessageBox(NULL, NULL, L"Error", MB_OK); return; } int n = GetPixelFormat(g_DC); DescribePixelFormat(g_DC, n, sizeof(pixel_desc), &pixel_desc); // Create opengl render context g_GLRC = wglCreateContext(g_DC); if (g_GLRC == NULL) { MessageBox(NULL, NULL, L"Error", MB_OK); return; } wglMakeCurrent(g_DC, g_GLRC); // Init glew glewInit(); glClearColor(0.0f, 1.0f, 0.0f, 1.0f); } void opengl_run() { GLfloat clear_c[4] = {rand() % 100 / 100.0f, rand() % 100 / 100.0f ,rand() % 100 / 100.0f, 1.0f}; glClearColor(clear_c[0], clear_c[1], clear_c[2], 1.0f); glClear(GL_COLOR_BUFFER_BIT); glFlush(); SwapBuffers(g_DC); } void opengl_destroy() { wglMakeCurrent(g_DC, NULL); wglDeleteContext(g_GLRC); ReleaseDC(g_Hwnd, g_DC); }
标签:stdcall ane gis buffer wpa extra remove oop release
原文地址:http://blog.csdn.net/i_dovelemon/article/details/61616189