SDL2 > PNG 图像 > 无法加载图像
SDL2 > PNG IMAGE > couldn't load the image
情况
我想在我的应用程序中加载和使用我的图像(.png)。但是,当我尝试加载图像时,出现以下错误
Error at ./sources/texture.c:9: 'The texture is NULL'
> Couldn't open pawn.png
代码
texture.c
texture_t*
texture_load(renderer_t *renderer, const char *path) {
texture_t *tex = IMG_LoadTexture(renderer, path);
if (tex == NULL)
error_print(AT, "The texture is NULL");
return tex;
}
game.c
game_t*
game_create() {
...
IMG_Init(IMG_INIT_PNG);
...
texture_load(renderer, "pawn.png")
...
}
文件夹结构
.
├── build
│ ├── app
│ └── pawn.png
├── headers
│ ...
│ ├── game.h
| ...
│ ├── texture.h
│ ...
├── resources
│ └── pawn.png
└── sources
...
├── game.c
...
├── texture.c
...
奖金
如果您想查看我的项目的完整“图像”,则可以单击 here
也许这是一个愚蠢的假设,但您确定该文件在当前应用程序目录中吗?
在 POSIX 系统上,您可以通过以下方式检查:
if (access("pawn.png", F_OK) == 0) {
printf("File exists\n");
} else {
printf("File doesn't exist\n");
}
如果它打印 File doesn't exist
,那么您需要指定文件的完整路径。
情况
我想在我的应用程序中加载和使用我的图像(.png)。但是,当我尝试加载图像时,出现以下错误
Error at ./sources/texture.c:9: 'The texture is NULL'
> Couldn't open pawn.png
代码
texture.c
texture_t*
texture_load(renderer_t *renderer, const char *path) {
texture_t *tex = IMG_LoadTexture(renderer, path);
if (tex == NULL)
error_print(AT, "The texture is NULL");
return tex;
}
game.c
game_t*
game_create() {
...
IMG_Init(IMG_INIT_PNG);
...
texture_load(renderer, "pawn.png")
...
}
文件夹结构
.
├── build
│ ├── app
│ └── pawn.png
├── headers
│ ...
│ ├── game.h
| ...
│ ├── texture.h
│ ...
├── resources
│ └── pawn.png
└── sources
...
├── game.c
...
├── texture.c
...
奖金
如果您想查看我的项目的完整“图像”,则可以单击 here
也许这是一个愚蠢的假设,但您确定该文件在当前应用程序目录中吗?
在 POSIX 系统上,您可以通过以下方式检查:
if (access("pawn.png", F_OK) == 0) {
printf("File exists\n");
} else {
printf("File doesn't exist\n");
}
如果它打印 File doesn't exist
,那么您需要指定文件的完整路径。