我正在尝试为游戏加载openGL纹理。纹理是从GIMP导出为.C source file
的图像。当我#include
我的项目中的这个文件(使用Visual C ++ 2010 Ultimate)时,我收到编译错误fatal error C1091: compiler limit: string exceeds 65535 bytes in length
是否有 任何 解决方法?
我想将图像导出为 C头文件的原因是程序使用图像进行编译,我不必提供raw
图像文件和可执行文件
代码:
#include <iostream>
#include <Windows.h>
#include <glfw.h>
#include "X.c"
#define X 1
#define O 2
#pragma comment(lib, "glfw.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "gdi32.lib")
using namespace std;
float render();
void stepGame(float);
void keyboard(int, int);
int main(int argv, int *argc[])
{
glfwInit();
glfwOpenWindow(480, 480, 16, 16, 16, 16, 16, 16, GLFW_WINDOW);
glfwSetKeyCallback(keyboard);
glfwSetWindowTitle("Tic Tac Toe!");
glClearColor(1.0, 1.0, 1.0, 1.0);
float dT;
while(glfwGetWindowParam(GLFW_OPENED) > 0)
{
glfwPollEvents();
dT = render();
stepGame(dT);
}
return 0;
}
图片文件: X.c
答案 0 :(得分:2)
这是另一种解决方案。将图像导出为原始数据文件,然后使用bin2hex将其转换为C / C ++数组。这将正常工作,因为这个脚本不是一个巨大的字符串,而是生成一个char数组。这是一个例子:
$ bin2hex.pl
bin2hex.pl by Chami.com
usage:
perl bin2hex.pl <binary file> <language id>
<binary file> : path to the binary file
<language id> : 0 = Perl, 1 = C/C++/Java, 2 = Pascal/Delphi
$ bin2hex.pl x.bin 1
/* begin binary data: */
char bin_data[] = /* 112 */
{0x23,0x69,0x6E,0x63,0x6C,0x75,0x64,0x65,0x20,0x3C,0x73,0x74,0x64,0x69,0x6F
,0x2E,0x68,0x3E,0x0A,0x23,0x69,0x6E,0x63,0x6C,0x75,0x64,0x65,0x20,0x3C,0x74
,0x69,0x6D,0x65,0x2E,0x68,0x3E,0x0A,0x0A,0x69,0x6E,0x74,0x20,0x6D,0x61,0x69
,0x6E,0x28,0x69,0x6E,0x74,0x20,0x61,0x72,0x67,0x63,0x2C,0x20,0x63,0x68,0x61
,0x72,0x2A,0x20,0x61,0x72,0x67,0x76,0x5B,0x5D,0x29,0x0A,0x7B,0x0A,0x20,0x20
,0x20,0x20,0x70,0x72,0x69,0x6E,0x74,0x66,0x28,0x22,0x25,0x64,0x5C,0x6E,0x22
,0x2C,0x20,0x73,0x69,0x7A,0x65,0x6F,0x66,0x28,0x74,0x69,0x6D,0x65,0x5F,0x74
,0x29,0x29,0x3B,0x0A,0x7D,0x0A,0x0A};
/* end binary data. size = 112 bytes */