diff --git a/main.cpp b/main.cpp index 1919a12..e79962e 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,28 @@ #include "ggl.h" #include "scene.h" +#include "utils.h" #pragma comment(lib, "opengl32.lib") #pragma comment(lib, "glew32.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; +} + /** *消息处理函数 */ diff --git a/utils.h b/utils.h new file mode 100644 index 0000000..44038fc --- /dev/null +++ b/utils.h @@ -0,0 +1,2 @@ +#pragma once +unsigned char * LoadFileContent(const char*path, int&filesize); \ No newline at end of file