无法加载 .bmp SDL2 IMG_LoadTexture
Can't load .bmp SDL2 IMG_LoadTexture
所以我一直在学习本教程,一切都很顺利,直到我遇到一个问题,即我无法加载.bmp。
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <stdio.h>
#include <iostream>
#include <SDL2/SDL_main.h>
using namespace std;
int main(int argc, char* argv[]) {
bool quit = false;
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window;
window = SDL_CreateWindow("window", 100, 100, 1280, 720, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
if(window == NULL){
cout << "Disn't work, here is why: " << SDL_GetError()<< endl;
return 0;
}
SDL_Renderer* renderer = NULL;
renderer= SDL_CreateRenderer(window, -1 ,SDL_RENDERER_ACCELERATED);
SDL_Event* mainEvent = new SDL_Event();
SDL_Texture* grass_image = NULL;
grass_image = IMG_LoadTexture(renderer, "grass.bmp");
SDL_Rect grass_rect;
grass_rect.x = 10;
grass_rect.y = 50;
grass_rect.w = 250;
grass_rect.h = 250;
while(!quit && mainEvent->type != SDL_QUIT){
SDL_PollEvent(mainEvent);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, grass_image, NULL, &grass_rect);
SDL_RenderPresent(renderer);
}
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
delete mainEvent;
return 0;
}
当我试图编译代码(在code::Blocks中)时,它会给我的错误
对"IMG_LoadTexture"的未定义引用
嗯,我尝试将IMG_LoadTexture(renderer, "grass.bmp");
更改为IMG_LoadTexture(renderer, "/the/full/path/of/grass.bmp");
,但这也不起作用。同样的错误。我是不是写错了什么,或者漏了什么地方?此外,grass.bmp与main.cpp(上面的代码)位于同一文件夹中。
这里的错误表明您已经声明了一个函数,但尚未定义它-未定义的引用。
发生这种情况很可能是因为您忘记链接函数IMG_LoadTexture
所属的库SDL_image。
相关文章:
- 如何将 cv::Mat & Img 复制到未签名的 char* img?opencv
- 列异常的 Img 矩阵迭代器<T>
- 如何在扩展 BMP 的 IMG 中找到 16 种最常见的颜色
- OpenCV VideoWriter Assertion Failed img.cols == width && img.rows == height*3
- 我在哪里可以找到完整的img包,用于训练opencv人脸识别系统?
- 如何在C++中声明一个定义为func(cv::Mat &img)的函数
- 当IMG(ROI)未返回正确的值时,如何正确提取ROI
- OpenCV 错误:断言失败((img.depth() == CV_8U || img.depth() == CV_32
- 带有opencv的值为0 1的imshow img
- Send img VTK for ITK
- 提升正则表达式、正则表达式、url 和 img
- OpenCV: assertation failed ((img.depth() == CV_8U || img.depth() == CV_32F) && img.type() == templ.t
- 使用 Img.at<cv::vec3 获取无符号短值???>
- 将src和dst-img设置为与opencv resize函数相同
- 我使用python3.5和OpenCV 3.1.0,OpenCV函数cv2.countNonZero(img)我得到了一
- 如何将文件夹中的所有img添加到CImage数组元素
- 我的第一个项目:编辑一个.img文件,需要指导
- opencv python transfer ((uchar*)(img->imageData img->widthStep*i))[j];
- 将使用PIL加载的图像转换为img图像对象
- 如何使用C++将.gis(地理信息系统)文件转换为.img格式