1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| //SDL_Window * w = SDL_CreateWindow("Hi", 0, 0, 640, 480, SDL_WINDOW_SHOWN);
SDL_Window * w = SDL_CreateWindowFrom((void *)GetHandle());
if(!w)
{
cerr << "Unable to create SDL_Window" << endl;
}
SDL_Renderer * r = SDL_CreateRenderer(w, -1, SDL_RENDERER_ACCELERATED);
if(!r)
{
cerr << "Unable to create SDL_Renderer" << endl;
}
SDL_Texture * s = NULL;
SDL_Surface *bitmapSurface = SDL_LoadBMP("image.bmp");
s = SDL_CreateTextureFromSurface(r, bitmapSurface);
if (s == NULL)
{
cout << "FAILED TO FIND THE IMAGE" << endl; //we did this to check if IMG_LoadTexture found the image, if it showed this message in the cmd window (the black system-like one) then it means that the image can't be found
}
SDL_Rect s_rect; // CREATES THE IMAGE'S SPECS
s_rect.x = 0; // just like the window, the x and y values determine it's displacement from the origin which is the top left of your window
s_rect.y = 0;
s_rect.w = 640; //width of the texture
s_rect.h = 480; // height of the texture
SDL_RenderClear(r);
SDL_RenderCopy(r, s, NULL, &s_rect); // THE NULL IS THE AREA YOU COULD USE TO CROP THE IMAGE
SDL_RenderPresent(r);
Refresh(false); |
Partager