I am not sure if this is a problem of having both SDL1 and 2 installed. Some people said that it was Img_Load and others said that it was IMG_Load. Boith though get either undefined or non existant. This is on Arch Linux.
Code:
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include
class Control{
public:
SDL_Window* window = 0;
SDL_Renderer* renderer = 0;
std::string title;
int width = 0, height = 0;
bool running = true, fullscreen;
SDL_Texture* texture; // the new SDL_Texture variable
SDL_Rect source_rect; // the first rectangle
SDL_Rect dest_rect; // another rectangle
Control(std::string titlename, int window_width=0, int window_height=0, bool fullscr=false)
: title(titlename), width(window_width), height(window_height), fullscreen(fullscr){
if ( ! init()){
//problem
}
}
~Control(){
clean();
}
void clean(){
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_Quit();
}
bool init(){
if (SDL_Init(SDL_INIT_EVERYTHING) == 0){
int flags = 0;
if (fullscreen){
flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
}
window = SDL_CreateWindow(title.c_str(),
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
width, height,
flags);
if (window != 0){
renderer = SDL_CreateRenderer(window, -1, 0);
}
}
else{
return false;
}
//Img_Load IMG_Load
SDL_Surface* temp = IMG_Load("Pictures/1.png");
texture = SDL_CreateTextureFromSurface(renderer, temp);
SDL_FreeSurface(temp);
SDL_QueryTexture(texture, NULL, NULL, &source_rect.w, &source_rect.h);
dest_rect.x = source_rect.x = 0;
dest_rect.y = source_rect.y = 0;
dest_rect.w = source_rect.w;
dest_rect.h = source_rect.h;
return true;
}
void events(){
SDL_Event event;
if (SDL_PollEvent(&event)){
switch (event.type){
case SDL_QUIT:
running = false;
break;
case SDL_KEYDOWN:
running = false;
break;
default:
break;
}
}
}
void update(){
}
void render(){
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, &source_rect, &dest_rect);
SDL_RenderPresent(renderer);
}
void run(){
while (running){
events();
update();
render();
}
}
};
int main(){
Control app(“SDL test”, 800, 600, false);
app.run();
}
Code:
/tmp/ccQDoZ9P.o: In function Control::init()': test4.cpp:(.text._ZN7Control4initEv[_ZN7Control4initEv]+0xb9): undefined reference to
IMG_Load’
collect2: error: ld returned 1 exit status
command:
Code:
g++ -I/usr/include/SDL2 -std=c++11 -Wall -o “%e” “%f” -lSDL2 -LSDL_image &&"./%e"
header file
Code:
metulburr at arch /usr/include/SDL2 $ ls | grep SDL_image
SDL_image.h
metulburr at arch /usr/include/SDL2 $
lib files:
Code:
metulburr at arch /usr/lib $ ls | grep SDL
libSDL-1.2.so.0
libSDL-1.2.so.0.11.4
libSDL.so
libSDL2-2.0.so.0
libSDL2-2.0.so.0.1.0
libSDL2.so
libSDL2_image-2.0.so.0
libSDL2_image-2.0.so.0.0.0
libSDL2_image.a
libSDL2_image.la
libSDL2_image.so
libSDL_image-1.2.so.0
libSDL_image-1.2.so.0.8.4
libSDL_image.so
libSDL_mixer-1.2.so.0
libSDL_mixer-1.2.so.0.12.0
libSDL_mixer.so
libSDL_ttf-2.0.so.0
libSDL_ttf-2.0.so.0.10.1
libSDL_ttf.so
libSDLmain.a
metulburr at arch /usr/lib $
I did the usual on the downloaded SDL2_image-2.0.0
./configure
make
make install