int main(int argc, char** argv) { long iLen; unsigned char* pBytes; if (argc != 3) { fprintf(stderr, "Usage: %s datafile arrayname\n", argv[0]); return -1; } iLen = _getFileLength(argv[1]); pBytes = malloc(iLen); _readEntireFile(argv[1], pBytes, iLen); printf("unsigned char %s[] = {\n", argv[2]); _dumpHexCBytes(stdout, pBytes, iLen); printf("};\n"); printf("unsigned long %s_sizeof = sizeof(%s);\n",argv[2],argv[2]); return 0; }
int CShaderMngr::_loadShader(const char *strFileName, shaderData *pData) { ifstream file; file.open(strFileName, ios::in); // opens as ASCII! if(!file) return -1; pData->nLen = _getFileLength(file); if (pData->nLen == 0) return -2; // Error: Empty File pData->pSrc = (GLchar*) new char[pData->nLen+1]; if (pData->pSrc == 0) return -3; // can't reserve memory // len isn't always strlen cause some characters are stripped in ascii read... // it is important to 0-terminate the real length later, len is just max possible value... pData->pSrc[pData->nLen] = 0; unsigned int i=0; while (file.good()) { pData->pSrc[i] = file.get(); // get character from file. if (!file.eof()) i++; } pData->pSrc[i] = 0; // 0-terminate it at the correct position file.close(); return 0; // No Error }