SDL texture not appearing

I am dealing with a very very frustrating issue here,the issue is that my picture of a ball or texture is not appearing on the window,I have spent the last one hour debugging to see what the problem could be,

all headers are included,libraries are correctly linked,

the calls to both libraries init function returns successfully

so I thought there must be something I am missing,I cleared the renderer,I copied the texture to the renderer,and I then updated/presented the renderer to the screen but nothing appears(this is the correct order)

so then I said well maybe I created the renderer before the window but nope all done correct so finally I checked some old games I made to see if I was missing something but after an hour it's obvious I'm not missing anything.

I then rechecked the name of the file(correct),
I then made sure the png image was in the correct folder(same folder as the cpp file) yup.

so there is literally no excuse why the texture is not showing totally frustrated at this point.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  #include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

using namespace std;

const int HEIGHT = 500;
const int WIDTH = 800;

SDL_Renderer* renderer;
SDL_Window* window;
SDL_Event event;

// ball
SDL_Texture* ballTexture;
SDL_Surface* ballSurface;
SDL_Rect* ballSrcRect;
SDL_Rect* ballDstRect;


void initGame(){

   if(SDL_Init(SDL_INIT_EVERYTHING) < 0){

      cout << "failed to init" << endl;
   }
   if(IMG_Init(IMG_INIT_PNG) < 0){

     cout << "failed to init image" << endl;
   }

   SDL_CreateWindow("platforms",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,WIDTH,HEIGHT,SDL_WINDOW_RESIZABLE);
   SDL_CreateRenderer(window,-1,0);

   ballSrcRect = new SDL_Rect;
   ballDstRect = new SDL_Rect;

   ballSurface = IMG_Load("ball.png");
   ballTexture = SDL_CreateTextureFromSurface(renderer,ballSurface);

   //ballDstRect->x = 100;
   //ballDstRect->y = 100;



}

void render(){

  SDL_RenderClear(renderer);

  SDL_RenderCopy(renderer,ballTexture,NULL,ballDstRect);

  SDL_RenderPresent(renderer);

}


int SDL_main(int argc,char* argv[])
{

    initGame();

    bool quit = false;

    while(!quit){

        SDL_PollEvent(&event);
        if(event.type == SDL_QUIT){
            cout << "quit" << endl;
            quit = true;

        }

        render();

    }
}
It would have been a bright idea to actually set the renderer equal to something,

but in any case the ball/texture is still not appearing on the screen :/


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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

using namespace std;

const int HEIGHT = 500;
const int WIDTH = 800;

SDL_Renderer* renderer;
SDL_Window* window;
SDL_Event event;

// ball
SDL_Texture* ballTexture;
SDL_Surface* ballSurface;
SDL_Rect* ballSrcRect;
SDL_Rect* ballDstRect;


void initGame(){

   if(SDL_Init(SDL_INIT_EVERYTHING) < 0){

      cout << "failed to init" << endl;
   }
   if(IMG_Init(IMG_INIT_PNG) < 0){

     cout << "failed to init image" << endl;
   }

   window = SDL_CreateWindow("platforms",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,WIDTH,HEIGHT,SDL_WINDOW_RESIZABLE);
   renderer = SDL_CreateRenderer(window,-1,0); // changed
   SDL_SetRenderDrawColor(renderer,255,255,255,255);

   ballSrcRect = new SDL_Rect;
   ballDstRect = new SDL_Rect;

   ballSurface = IMG_Load("bb.png");
   ballTexture = SDL_CreateTextureFromSurface(renderer,ballSurface);

   ballDstRect->x = 100;
   ballDstRect->y = 100;

   ballDstRect->h =100;
   ballDstRect->w = 100;



}

void renderGame(){

  SDL_RenderClear(renderer);

  SDL_RenderCopy(renderer,ballTexture,NULL,ballDstRect);

  SDL_RenderPresent(renderer);

}


int SDL_main(int argc,char* argv[])
{

    initGame();

    bool quit = false;

    while(!quit){

        SDL_PollEvent(&event);
        if(event.type == SDL_QUIT){
            cout << "quit" << endl;
            quit = true;
        }
        renderGame();
    }
}

problem seems to be resolved for now,

I did a clean and rebuild seems to have done the job
Topic archived. No new replies allowed.