Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: 1 [2]   Go Down

Author Topic: [SDL] Tutorial help  (Read 8546 times)

0 Members and 1 Guest are viewing this topic.
Re: [SDL] Tutorial help
« Reply #20 on: May 28, 2011, 03:31:13 am »
  • Minalien
  • *
  • Reputation: +10/-1
  • Offline Offline
  • Gender: Female
  • Posts: 2119
The code you showed is trying to load "lazy.wttf" - Can't say for sure if this is the problem, I still need to get SDL on this machine and poke around.

You've also got a check for message being NULL, but I don't see anywhere in your code defining it - so at that point, it will be NULL/0.

Hrm.. Looking through this, there're quite a few issues. I'll poke around a bit more when I get back again.
« Last Edit: May 28, 2011, 03:34:34 am by Minalien »
Logged
Quote
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.

But if my friends and I gather, wear black robes, and say  "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
  • Development Blog
Re: [SDL] Tutorial help
« Reply #21 on: May 28, 2011, 04:21:40 am »
  • Hookshot to the Future!
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 517
i think i must just made that error tight butthole i swear it wasnt there before u can check in copy code on post 1 lol T_T
Logged
Check my ZRPG development blog at rev2k9blog.spaces.live.com
  • My Blog
Re: [SDL] Tutorial help
« Reply #22 on: May 28, 2011, 04:31:17 pm »
  • Minalien
  • *
  • Reputation: +10/-1
  • Offline Offline
  • Gender: Female
  • Posts: 2119
Running it through the debugger with breakpoints, it's definitely the font that's failing to load.

Here's the directory and file structure you should have:

SDL_TUTORIAL\ (Solution Directory)
   SDL_TUTORIAL.sdf   Intellisense database
   SDL_TUTORIAL.opensdf   A lock file for the Intellisense database
   SDL_TUTORIAL.sln   Visual Studio Solution File
   SDL_TUTORIAL.suo   Visual Studio Solution User Options
   ipch\
      (The contents here don't really matter to this)
   Debug\
      This is where Visual Studio is placing your files when you build a Debug configuration
   Release\
      This is where Visual Studio is placing your files when you build a Release configuration

   SDL_TUTORIAL\ (Project Directory)
      Debug\
         This is where Visual Studio is placing temporary files during the compilation and linking phases for a Debug build
      Release\
         This is where Visual Studio is placing temporary files during the compilation and linking phases for a Release build
      Source Files THIS IS NOT A SEPARATE FOLDER - THEY SHOULD BE IN SDL_TUTORIAL/SDL_TUTORIAL/
         All of your source files (.h and .cpp) are going to be in here.
      Media THIS IS NOT A SEPARATE FOLDER - THEY SHOULD BE IN SDL_TUTORIAL/SDL_TUTORIAL/
         This is also where all of your media files are going to need to be. This is because this directory is where the executable is considered to be running when you Debug/Run through Visual Studio (F5).

As far as the code goes, your game loop is all sorts of messed up.

Basically, here's what you want to do with your main loop:

Code: Text
  1. while (quit == false)
  2.         while there are events
  3.                 if event is key down
  4.                         if key is up, set message to up message
  5.                         if key is down, set message to down message
  6.                         if key is left, set message to left message
  7.                         if key is right, set message to right message
  8.                 if event is quit, set quit to true
  9.  
  10.         apply background surface
  11.  
  12.         if message is not null
  13.                 apply message surface
  14.  
  15.         flip rendering buffers

So your main function should become:
Code: C
  1. int main( int argc, char* args[] )
  2. {
  3.     //Quit flag
  4.     bool quit = false;
  5.  
  6.     //Initialize
  7.     if( init() == false )
  8.     {
  9.         return 1;
  10.     }
  11.  
  12.     //Load the files
  13.     if( load_files() == false )
  14.     {
  15.         return 2;
  16.     }
  17.  
  18.     //Render the text
  19.     upMessage = TTF_RenderText_Solid( font, "up was pressed", textColor );
  20.         downMessage = TTF_RenderText_Solid( font,"down was pressed",textColor);
  21.         leftMessage = TTF_RenderText_Solid(font, "left was pressed",textColor);
  22.         rightMessage = TTF_RenderText_Solid(font, "right was pressed",textColor);
  23.         apply_surface(0,0,background,screen);
  24.  
  25.     //Apply the images to the screen
  26.    
  27.    
  28.     //While the user hasn't quit
  29.     while( quit == false )
  30.     {
  31.         //While there's events to handle
  32.         while( SDL_PollEvent( &event ) )
  33.         {
  34.                         if (event.type == SDL_KEYDOWN)
  35.                         {
  36.                                 switch(event.key.keysym.sym)
  37.                                 {
  38.                                         case SDLK_UP : message = upMessage; break;
  39.                                         case SDLK_DOWN : message = downMessage; break;
  40.                                         case SDLK_LEFT : message = leftMessage; break;
  41.                                         case SDLK_RIGHT : message = rightMessage; break;
  42.                                 }
  43.  
  44.                         }
  45.             //If the user has Xed out the window
  46.                         else if( event.type == SDL_QUIT )
  47.             {
  48.                 //Quit the program
  49.                 quit = true;
  50.             }
  51.         }
  52.  
  53.                 apply_surface( 0, 0, background, screen );
  54.  
  55.                 if (message != NULL)
  56.                 {
  57.                          apply_surface((SCREEN_WIDTH - message->w) / 2, (SCREEN_HEIGHT - message->h) / 2, message,screen);
  58.                 }
  59.  
  60.                  //Update the screen
  61.                 if( SDL_Flip( screen ) == -1 )
  62.                 {
  63.                         return 4;
  64.                 }
  65.     }
  66.  
  67.  
  68.     //Free surfaces and font then quit SDL_ttf and SDL
  69.     clean_up();
  70.  
  71.     return 0;
  72. }

It's still not the cleanest code around, but it's functional. You don't want to set message to NULL after rendering it because you only receive an event when you press the key. If you want the message to only appear when the button is pressed, I can show you some modified event code to check for the button being held (basically, setting/clearing a boolean value on key up/down, then checking for the bool to set message).
Logged
Quote
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.

But if my friends and I gather, wear black robes, and say  "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
  • Development Blog
Re: [SDL] Tutorial help
« Reply #23 on: May 30, 2011, 01:33:23 am »
  • Minalien
  • *
  • Reputation: +10/-1
  • Offline Offline
  • Gender: Female
  • Posts: 2119
Did that help to resolve your issues, Rev?
Logged
Quote
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.

But if my friends and I gather, wear black robes, and say  "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
  • Development Blog
Re: [SDL] Tutorial help
« Reply #24 on: May 30, 2011, 03:03:12 am »
  • Hookshot to the Future!
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 517
i am gonna look into it , i got alot RL !@#$% going on at same time so its hard getting time i just got off from  9hr shift.
Logged
Check my ZRPG development blog at rev2k9blog.spaces.live.com
  • My Blog
Re: [SDL] Tutorial help
« Reply #25 on: May 30, 2011, 04:26:44 am »
  • Minalien
  • *
  • Reputation: +10/-1
  • Offline Offline
  • Gender: Female
  • Posts: 2119
Believe me, I know that feeling. If you're still having issues, I'll keep an eye on this post
Logged
Quote
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.

But if my friends and I gather, wear black robes, and say  "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
  • Development Blog
Pages: 1 [2]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.118 seconds with 51 queries.

anything