#include "scene.h"#pragma comment(lib,"opengl32.lib")#pragma comment(lib,"glu32.lib")#pragma comment(lib,"glew32.lib")#pragma comment(lib,"winmm.lib")unsigned char * LoadFileContent(const char *path, int &filesize) {unsigned char*fileContent = nullptr;filesize = 0;FILE*pFile = fopen(path, "rb");if (pFile) {fseek(pFile, 0, SEEK_END);int nLen = ftell(pFile);if (nLen > 0) {rewind(pFile);fileContent = new unsigned char[nLen + 1];fread(fileContent, sizeof(unsigned char), nLen, pFile);fileContent[nLen] = '0円';filesize = nLen;}fclose(pFile);}return fileContent;}float GetFrameTime() {static unsigned long lastTime = 0, timeSinceComputerStart = 0;timeSinceComputerStart = timeGetTime();unsigned long frameTime = lastTime == 0 ? 0 : timeSinceComputerStart - lastTime;lastTime = timeSinceComputerStart;return float(frameTime) / 1000.0f;}LRESULT CALLBACK GLWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){switch (msg){case WM_CLOSE:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, msg, wParam, lParam);}INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){WNDCLASSEX wndclass;wndclass.cbClsExtra = 0;wndclass.cbSize = sizeof(WNDCLASSEX);wndclass.cbWndExtra = 0;wndclass.hbrBackground = NULL;wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);wndclass.hIcon = NULL;wndclass.hIconSm = NULL;wndclass.hInstance = hInstance;wndclass.lpfnWndProc = GLWindowProc;wndclass.lpszClassName = L"GLWindow";wndclass.lpszMenuName = NULL;wndclass.style = CS_VREDRAW | CS_HREDRAW;ATOM atom = RegisterClassEx(&wndclass);if (!atom) {MessageBox(NULL, L"Register Fail", L"Error", MB_OK);return 0;}RECT rect;rect.left = 0;rect.right = 1280;rect.top = 0;rect.bottom = 720;AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, NULL);int windowWidth = rect.right - rect.left;int windowHeight = rect.bottom - rect.top;HWND hwnd = CreateWindowEx(NULL, L"GLWindow", L"OpenGL Window", WS_OVERLAPPEDWINDOW,100, 100, windowWidth, windowHeight,NULL, NULL, hInstance, NULL);HDC dc = GetDC(hwnd);PIXELFORMATDESCRIPTOR pfd;memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));pfd.nVersion = 1;pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);pfd.cColorBits = 32;pfd.cDepthBits = 24;pfd.cStencilBits = 8;pfd.iPixelType = PFD_TYPE_RGBA;pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;int pixelFormat = ChoosePixelFormat(dc, &pfd);SetPixelFormat(dc, pixelFormat, &pfd);HGLRC rc = wglCreateContext(dc);wglMakeCurrent(dc, rc);glewInit();Init();SetViewPortSize(1280.0f, 720.0f);ShowWindow(hwnd, SW_SHOW);UpdateWindow(hwnd);MSG msg;while (true){if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)){if (msg.message == WM_QUIT){break;}TranslateMessage(&msg);DispatchMessage(&msg);}Draw();SwapBuffers(dc);}return 0;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。