Hey I was going to load an image to my program with SDL2. I am using visual studio 2015. I place the image in my project folder in correct place but still image isn't loaded.my code as follows
#include <iostream>
#include <SDL_image.h>
#include <SDL.h>
using namespace std;
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = NULL;
window = SDL_CreateWindow("Game", 100, 100, 700, 400, SDL_WINDOW_SHOWN);
if (window = NULL) {
cout << "Window creation error" << endl;
}
SDL_Renderer* renderer = NULL;
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_Texture* man = IMG_LoadTexture(renderer, "img.png");
SDL_Event* ev = new SDL_Event();
if (man == NULL) {
cout << "image cannot load" << endl;
}
SDL_Rect boy_rect;
boy_rect.x = 10;
boy_rect.y = 10;
boy_rect.h = 220;
boy_rect.w = 300;
while (ev->type != SDL_QUIT) {
SDL_PollEvent(ev);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, man, NULL, &boy_rect);
SDL_RenderPresent(renderer);
}
SDL_DestroyTexture(man);
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
return 0;
}
the result is "image cant load" I cant find any error of this if you can find please inform me. thanks