Jump to content
  • Advertisement
Sign in to follow this  
CarlosNYM

A Real Quick SDL Question

This topic is 3918 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been looking over a few tutorials on Game Programming in SDL and I made a project in C++ and I have 2 files in it. They both compile but generate one error. First File(complies by itself no problem)
#include "SDL/SDL.h"
#include "SDL/SDL_TTF.h"

const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;
const char* WINDOW_TITLE = "SDL Start";

int main(int argc, char **argv)
{
   SDL_Init( SDL_INIT_VIDEO );

   SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0,
      SDL_HWSURFACE | SDL_DOUBLEBUF );
   SDL_WM_SetCaption( WINDOW_TITLE, 0 );

   SDL_Surface* bitmap = SDL_LoadBMP("bat.bmp");
   SDL_SetColorKey( bitmap, SDL_SRCCOLORKEY, SDL_MapRGB(bitmap->format, 255, 0, 255) );
   // Part of the bitmap that we want to draw
   SDL_Rect source;
   source.x = 24;
   source.y = 63;
   source.w = 65;
   source.h = 44;

   // Part of the screen we want to draw the sprite to
   SDL_Rect destination;
   destination.x = 300;
   destination.y = 200;
   destination.w = 65;
   destination.h = 44;

   SDL_Event event;
   bool gameRunning = true;

   while (gameRunning)
   {
      if (SDL_PollEvent(&event))
      {
         if (event.type == SDL_QUIT)
         {
            gameRunning = false;
         }
      }

      SDL_BlitSurface(bitmap, &source, screen, &destination);
      

      SDL_Flip(screen);

   }

   SDL_FreeSurface(bitmap);

   SDL_Quit();

   return 0;
}


Second File(added to the project and im now getting the problem)
#include "SDL/SDL.h"
#include "SDL/SDL_TTF.h"

const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;
const char* WINDOW_TITLE = "SDL Start";

int main(int argc, char **argv)
{
   SDL_Init( SDL_INIT_VIDEO );

   TTF_Init();

   SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0,
      SDL_HWSURFACE | SDL_DOUBLEBUF );
   SDL_WM_SetCaption( WINDOW_TITLE, 0 );

   TTF_Font* font = TTF_OpenFont("ARIAL.TTF", 12);

   SDL_Color foregroundColor = { 255, 255, 255 };
   SDL_Color backgroundColor = { 0, 0, 255 };

   SDL_Surface* textSurface = TTF_RenderText_Shaded(font, "This is my text.",
      foregroundColor, backgroundColor);

   // Pass zero for width and height to draw the whole surface
   SDL_Rect textLocation = { 100, 100, 0, 0 };

   SDL_Event event;
   bool gameRunning = true;

   while (gameRunning)
   {
      if (SDL_PollEvent(&event))
      {
         if (event.type == SDL_QUIT)
         {
            gameRunning = false;
         }
      }

      SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));

      SDL_BlitSurface(textSurface, NULL, screen, &textLocation);

      SDL_Flip(screen);
   }

   SDL_FreeSurface(textSurface);

   TTF_CloseFont(font);

   TTF_Quit();

   SDL_Quit();

   return 0;
}


I get this error. C:\Dev-Cpp\Makefile.win [Build Error] [SDL_Tutorial.exe] Error 1 This is probably occurring because I'm compiling them simultaneously. If so how can I fix it? I want to test the font file but I cant seem to get it to compile by itself w/o compiling the other and without making a seperate project just to test it. Thanks for the help!

Share this post


Link to post
Share on other sites
Advertisement
That surely is an undescriptive error... Bytheway, Dev-C++ isn't updated anymore and uses an outdated version of the GCC compiler. There are some good, and free, alternatives, like Visual C++ 2005 Express, or Code::Blocks.

As for these two files, both contain a main function, which isn't good - there should only be one in your project. Creating another project to test that code with shouldn't be too much work, right? :)

Share this post


Link to post
Share on other sites
but im lazy.....


Lol, Yea, its not too much trouble I just wanted to know if there was any other reason. But the main theory makes a lot of sense.

I have tried going to another compiler but Code Blocks is ehh, i dunno I just dont like a lot of things about it. Dev-C++ is simplistic but effective, stinks they stopped updating it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!