2

一段时间以来,我一直在尝试修复这个特定的 SDL 错误,但奇怪的是没有通过搜索发现一次提到的相同错误。

这是 Visual Studio 错误输出:

Error   1   error LNK2019: unresolved external symbol _IMG_LoadTexture referenced in function "struct SDL_Texture * __cdecl LoadImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadImage@@YAPAUSDL_Texture@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)    C:\Users\DemonicSmokingJacket\Documents\Visual Studio 2012\Projects\ShitHappens\ShitHappens\main.obj    ShitHappens

这是代码:

#include <SDL.h>
#include <SDL_image.h>
#include <string>

const int screen_x = 640;
const int screen_y = 480;

SDL_Window *window = nullptr;
SDL_Renderer *renderer = nullptr;

using namespace std;

SDL_Texture *LoadImage(string file)
{

    //Initialized variables for texture.
    SDL_Texture *texture = nullptr;

    //Load image.
    texture = IMG_LoadTexture(renderer, file.c_str());
    return texture;
}

void ApplySurface(int x, int y, SDL_Texture *texture, SDL_Renderer *second_renderer)
{
    //Initialize variables and set x and y axis.
    SDL_Rect pos;
    pos.x = x;
    pos.y = y;
    SDL_QueryTexture(texture, NULL, NULL, &pos.w, &pos.h);
    SDL_RenderCopy(second_renderer, texture, NULL, &pos);
}

int main(int argc, char* argv[])
{
    //Initialize variables limited to function 'main'.
    int bW, bH, iW, iH, x, y;
    SDL_Texture *background = nullptr, *image = nullptr;

    //Initialize all of SDL's features; an SDL window and make the window rendable.
    SDL_Init(SDL_INIT_EVERYTHING);
    window = SDL_CreateWindow("Shit Happens", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_x, screen_y, SDL_WINDOW_SHOWN);
    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

    //Load background images from 'LoadImage' function.
    background = LoadImage("background.png");
    image = LoadImage("image.png");

    //Clear Render 'renderer'.
    SDL_RenderClear(renderer);

    //Display and tile background image. "background.bmp"
    SDL_QueryTexture(background, NULL, NULL, &bW, &bH);
    ApplySurface(bW, bH, background, renderer);
    ApplySurface(bW, 0, background, renderer);
    ApplySurface(0, bH, background, renderer);
    ApplySurface(0, 0, background, renderer);

    //Display front image. "image.bmp"
    SDL_QueryTexture(image, NULL, NULL, &iW, &iH);
    x = screen_x / 2 - iW / 2;
    y = screen_y / 2 - iH / 2;

    //Apply changes to renderer.
    ApplySurface (x, y, image, renderer);

    //Apply renderer to screen.
    SDL_RenderPresent(renderer);
    SDL_Delay(2000);

    //Destroy the SDL Textures (images); the SDL Renderer and the SDL window.  
    SDL_DestroyTexture(background);
    SDL_DestroyTexture(image);
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);

    //Quit SDL.
    SDL_Quit();

    return 0;

}

非常感谢您的宝贵时间,希望这对其他用户有所帮助。此致, (DamnitIForgotMyName)

4

1 回答 1

1

感谢self.,我得出了一个结论。IMG_LoadTexture问题是我没有从http://www.libsdl.org/projects/SDL_image/下载包含该功能的最新版本的 SDL_Image 。

再次感谢自己。

于 2013-09-24T22:22:40.520 回答