C++, Xcode und SDL - Bekomme kein Bild angezeigt

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • C++, Xcode und SDL - Bekomme kein Bild angezeigt

    Hallo zusammen,

    Ich verwende Xcode und SDL und habe aus einem Tutorial den nachfolgenden C++ Code. Ein Fenster öffnet sich, aber darin wird kein Bild angezeigt. Es gibt auch keine Fehlermeldung.
    Hat jemand eine Idee wo das Problem sein könnte?

    C-Quellcode

    1. #include "SDL/SDL.h"
    2. #include "SDLMain.h"
    3. #include <string>
    4. const int SCREEN_WIDTH = 640;
    5. const int SCREEN_HEIGHT = 480;
    6. const int SCREEN_BPP = 32;
    7. SDL_Surface* message = NULL;
    8. SDL_Surface* background = NULL;
    9. SDL_Surface* screen = NULL;
    10. SDL_Surface* load_image( std::string filename )
    11. {
    12. //Temporary storage for the image that's loaded
    13. SDL_Surface* loadedImage = NULL;
    14. //The optimized image that will be used
    15. SDL_Surface* optimizedImage = NULL;
    16. //Load the image
    17. loadedImage = SDL_LoadBMP( filename.c_str() );
    18. //If nothing went wrong in loading the image
    19. if( loadedImage != NULL )
    20. {
    21. //Create an optimized image
    22. optimizedImage = SDL_DisplayFormat( loadedImage );
    23. //Free the old image
    24. SDL_FreeSurface( loadedImage );
    25. }
    26. //Return the optimized image
    27. return optimizedImage;
    28. }
    29. void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
    30. {
    31. //Make a temporary rectangle to hold the offsets
    32. SDL_Rect offset;
    33. //Give the offsets to the rectangle
    34. offset.x = x;
    35. offset.y = y;
    36. //Blit the surface
    37. SDL_BlitSurface( source, NULL, destination, &offset );
    38. }
    39. int main( int argc, char* args[] )
    40. {
    41. //Initialize all SDL subsystems
    42. if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    43. {
    44. return 1;
    45. }
    46. //Set up the screen
    47. screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
    48. //If there was an error in setting up the screen
    49. if( screen == NULL )
    50. {
    51. return 1;
    52. }
    53. //Set the window caption
    54. SDL_WM_SetCaption( "Hello World", NULL );
    55. //Load the images
    56. message = load_image( "bild.bmp" );
    57. //background = load_image( "background.bmp" );
    58. //Apply the background to the screen
    59. apply_surface( 0, 0, background, screen );
    60. apply_surface( 320, 0, background, screen );
    61. apply_surface( 0, 240, background, screen );
    62. apply_surface( 320, 240, background, screen );
    63. //Apply the message to the screen
    64. apply_surface( 180, 140, message, screen );
    65. //Update the screen
    66. if( SDL_Flip( screen ) == -1 )
    67. {
    68. return 1;
    69. }
    70. //sWait 2 seconds
    71. SDL_Delay( 2000 );
    72. //Free the surfaces
    73. SDL_FreeSurface( message );
    74. SDL_FreeSurface( background );
    75. //Quit SDL
    76. SDL_Quit();
    77. return 0;
    78. }
    Alles anzeigen
  • Modius schrieb:

    Wie kann ich das den genau auswertern? Also das Bild liegt im selben Ordner wie die main.cpp
    ich habe mal versucht mir den Wert des Zeigers ausgeben zu lassen mit cout, aber da kommt nur 0x0 raus

    Tja, 0x0 ist der klassische null-pointer. Also kein Bild.
    Ich habe keine Ahnung, wie der Compiler diese Pfadangabe auswertet. Gibt es eine Preprozessor-Direktive für 'Verzeichnis der .cpp Datei'?
    «Applejack» "Don't you use your fancy mathematics to muddle the issue!"

    Iä-86! Iä-64! Awavauatsh fthagn!

    kmr schrieb:

    Ach, Du bist auch so ein leichtgläubiger Zeitgenosse, der alles glaubt, was irgendwelche Typen vor sich hin brabbeln. :-P
  • Modius schrieb:

    Wie kann ich das den genau auswertern? Also das Bild liegt im selben Ordner wie die main.cpp
    ich habe mal versucht mir den Wert des Zeigers ausgeben zu lassen mit cout, aber da kommt nur 0x0 raus


    0x0 sagt ja aus, dass da nix ist.
    Zum dritten mal, du brauchst den kompletten!!!!! Pfad zum Bild