title: SDL, How can I make the background picture render?
body: <p>I had a render problem, but I fixed that. The problem is, is that the picture won't actually show up. I know the picture gets loaded because I have an error handler if it isn't loaded. I know the code is messy, but I just need the picture to show up.</p>
  
  <pre><code>#include &lt;SDL/SDL.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  const int fps = 60;
  
  SDL_Window *window;
  
  
  int main(int argc, char **argv)
  {
      SDL_Init(SDL_INIT_EVERYTHING);
      window = SDL_CreateWindow("", 300, 100, 1024, 800, SDL_WINDOW_OPENGL);
  
      if (window == NULL)
      {
          cout &lt;&lt; ("could not create window: %s/n", SDL_GetError());
          return 1;
      }
      SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
      int x = 0, y = 0;
      SDL_Surface  *screen;
      SDL_Surface *background = SDL_LoadBMP("hockeyrink.bmp");
      if(background == NULL)
      {
          SDL_ShowSimpleMessageBox(0, "Background init error",         SDL_GetError(), window);
      }
  
      if(renderer == NULL)
      {
          SDL_ShowSimpleMessageBox(0, "Renderer init error", SDL_GetError(), window);
      }
      SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer,background);
      if(texture == NULL)
      {
          SDL_ShowSimpleMessageBox(0, "Texture init error", SDL_GetError(), window);
      }
  
      const int speed = 5;
      SDL_Rect camera;
      camera.x = 0; //Don't worry about this camera, I need this after i get the background working.
      camera.y = 0;
      camera.w = 800;
      camera.h = 600;
      bool b[2] = {0,0};
      Uint32 start;
  
      bool running = true;
      while (running)
      {
          start = SDL_GetTicks();
          SDL_Event event;
  
          while(SDL_PollEvent(&amp;event))
          {
              switch(event.type)
              {
              case SDL_QUIT:
                  running = false;
                  SDL_DestroyTexture(texture);
                  SDL_FreeSurface(background);
                  SDL_DestroyRenderer(renderer);
                  SDL_DestroyWindow(window);
                  SDL_Quit();
                  break;
              case SDL_KEYDOWN:
                  switch(event.key.keysym.sym)
                  {
                  case SDLK_UP:
                      b[0]=1;
                      break;
                  case SDLK_LEFT:
                      b[1]=1;
                      break;
                  }
                  break;
              case SDL_KEYUP:
                  switch(event.key.keysym.sym)
                  {
                  case SDLK_UP:
                      b[0]=0;
                      break;
                  case SDLK_LEFT:
                      b[1]=0;
                      break;
                  }
                  break;
              }
          }
  
          if(b[0])
          {
              x+=speed;
              camera.y+=speed;
              if (camera.y &gt; 3000-800)
              {
                  camera.y=0;
              }
  
          }
          else if(b[1])
          {
              x-=speed;
              camera.y-=speed;
  
              if (camera.y &lt;= 0)
              {
                  camera.y = 2000-800;
              }
  
  
              SDL_RenderCopy(renderer, texture, NULL, NULL);
              SDL_RenderPresent(renderer);
          }
          if(1000/fps&gt;SDL_GetTicks()-start)
          {
              SDL_Delay(1000/fps-(SDL_GetTicks() - start));
          }
      }
  
      return 0;
  }
  </code></pre>