[英]Can't load .bmp SDL2 IMG_LoadTexture
so I was following this tutorial, and everything was going all smooth and dandy, until I encountered a problem, namely that I couldn't load a .bmp. 因此我一直在遵循本教程,并且一切都变得顺利而繁琐,直到遇到一个问题,即我无法加载.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;
}
When I try to compile the code (in Code::Blocks) it gives me the error of 当我尝试编译代码(在Code :: Blocks中)时,出现以下错误
Undefined reference to "IMG_LoadTexture"
未定义对“ IMG_LoadTexture”的引用
Well, I tried to change IMG_LoadTexture(renderer, "grass.bmp");
好吧,我试图更改
IMG_LoadTexture(renderer, "grass.bmp");
to IMG_LoadTexture(renderer, "/the/full/path/of/grass.bmp");
到
IMG_LoadTexture(renderer, "/the/full/path/of/grass.bmp");
but this didn't work either. 但这也不起作用。 Same error.
同样的错误。 Have I written something wrong, or missed some part?
我写错了什么,还是错过了一部分? Also, grass.bmp is in the same folder as main.cpp (the code above).
另外,grass.bmp与main.cpp位于同一文件夹中(上面的代码)。
The error here says that you have declared a function but have not defined it - undefined reference . 此处的错误表明您已声明一个函数,但尚未定义它- 未定义的引用 。
Most probably it happened because you forgot to link against library SDL_image to which function IMG_LoadTexture
belongs. 最有可能的事情发生,因为你忘了对库链接SDL_image到功能
IMG_LoadTexture
所属。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.