Reputation: 171
Ive been trying to fix this particular SDL error for a while and strangely haven't found the same error mentioned once through searches.
Here is the Visual Studio error output:
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
And here is the code:
#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;
}
Thank you very much for your time, hopefully this will help other users. Sincerely, (DamnitIForgotMyName)
Upvotes: 2
Views: 3037
Reputation: 171
Thanks to self., I have come to a conclusion. The problem was I hadnt downloaded the newest version of SDL_Image ,which does contain the function IMG_LoadTexture
, from http://www.libsdl.org/projects/SDL_image/.
Thanks once again to self.
Upvotes: 1