SDL Not Compiling Correctly

Hello,

I have written a program whose purpose is to create two surfaces, load bitmaps to them, and then blit one surface onto the other. This program compiles, but does not run correctly. The error logs yield nothing that tells me of any errors.
This at first led me to assume my source code was wrong, and so I double-checked and wrote another program.
Then I compiled a tutorial (whose link can be found on the SDL website: http://www.sdltutorials.com/sdl-coordinates-and-blitting/ ), and found that it did not work when I compiled it either, but instead showed the same result as the program below: a black surface with no blitting and nothing special about it. However, the application which came with the source code clearly showed what the application was meant to do: display a few bitmaps, which the application demonstrated.
This has therefore led me to conclude that my compiler or the library is faulty.
I use Dev C/C++ with the DevPak SDL 1.2.13 (there’s no 1.2.14 DevPak yet). I tried getting the DevPak with Code::Blocks, but my download encounters an error every time after downloading about 40 kilobytes. My only thought is that this must be a server error, because my internet is quite good.

I know that SDL works, because the headers include fine and I am able to write programs that are intended to simply display a surface without manipulating it or blitting to it in any way. This is useless, but it at least allows me to conclude that at least part of my SDL library works.

I therefore ask you to identify the problem and provide a solution :smiley:

Code:

#include “SDL/SDL.h”
#include
#include
using namespace std;

// C++ PROGRAM

class MyClass
{
private:
SDL_Surface* SDL_Background;
SDL_Surface* SDL_ToBlit;
ofstream errorlog;

  int OnInit()
  {
      if((SDL_Init(SDL_INIT_EVERYTHING) < 0))
      {
                                        errorlog << "error initializing the SDL ( OnInit() : SDL_Init(SDL_INIT_EVERYTHING) < 0)\n";
                                        return -1;
                                        }
      else
      {
          errorlog << "SDL initialized successfully.\n";
          }
      SDL_Background = NULL;
      SDL_ToBlit = NULL;
      if( (SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF)) == NULL)
      {
                                errorlog << "error setting video mode ( OnInit() : SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF)\n";
                                return -1;
                                }
      else
      {
          errorlog << "Video mode set successfully.\n";
          }
         }
  
       
      
      
       
      
      
  int Draw(SDL_Surface* DrawBG, SDL_Surface* DrawBlit, int X, int Y)
  {
     if(DrawBG == NULL || DrawBlit == NULL)
     {
               errorlog << "BG or To Draw was equal to null.\n";
               return -1;
               }
      
     SDL_Rect DestR;
     DestR.x = X;
     DestR.y = Y; 
     
      
     SDL_BlitSurface(DrawBlit, NULL, DrawBG, &DestR);
     SDL_Flip(DrawBlit);
     SDL_Delay(10000);
     return 0;
     }
  
  
  
  
  int Cleanup()
  {
      SDL_FreeSurface(SDL_Background);
      SDL_FreeSurface(SDL_ToBlit);
      SDL_Quit();
      }
  
  
      
      
  public:
  MyClass()
  {
           errorlog.open("errorlog.txt");
           errorlog << "MyClass constructor begun.\n";
           OnInit();
           
           
           
           
           
  if((SDL_Background = SDL_LoadBMP("bg.bmp")) == NULL)
      {
             errorlog << "error loading background bmp  (GetImages : BG == SDL_LoadBMP(bg.bmp)\n";

             }
       else
       {
           errorlog << "background bitmap loaded successfully.\n";
           }
       
       
             
  if((SDL_ToBlit = SDL_LoadBMP("todraw.bmp")) == NULL)
  {
           errorlog << "error loading to draw bmp (GetImages : BLIT == SDL_LoadBMP(todraw.bmp)\n";

           }
  else
  {
      errorlog << "to draw bitmap loaded successfully.\n";
      }
           
           
           
           
           Draw(SDL_Background, SDL_ToBlit, 0, 0);
           Cleanup();
           }
           };

int main(int argc, char* argv[])
{
MyClass object1;
}

Please keep in mind that I am obviously learning this API, and don’t have any particular advanced knowledge of it. I have encountered an error which has halted my progress in learning it.

Your help is appreciated :smiley:

dragonwrenn

Great! I applied the changes you advised, and it works!
Thanks very much! :smiley: