Note that there are some explanatory texts on larger screens.

plurals
  1. POBitmap won't load in SDL
    primarykey
    data
    text
    <p><em><strong></em>****</strong><em>FIXED</em><strong><em>*</em>**<em>*</em>**</strong> It turns out my bitmap file was somehow corrupted. I could open the file to view it but my application couldn't. I made a new image and it works fine.</p> <p>I am having problems displaying a bitmap image in sdl. The program exits with code 2 so I know the bitmap is not loading. I am using vc2010 on windows 7 64bit. The name of the BMP is hello.bmp and I tried placing it next to the application file, source file, and project file but it still won't load it. I have also tried just placing it in c:\ and loading it from there with no luck. This is the first time I have tried using SDL. Here is the code:</p> <pre><code>#include "stdlib.h" #include "SDL.h" int main(int argc, char *argv[]) { SDL_Surface *screen; //This pointer will reference the backbuffer SDL_Surface *image; //This pointer will reference our bitmap sprite SDL_Surface *temp; //This pointer will temporarily reference our bitmap sprite SDL_Rect src, dest; //These rectangles will describe the source and destination regions of our blit //We must first initialize the SDL video component, and check for success if (SDL_Init(SDL_INIT_VIDEO) != 0) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); return 1; } //When this program exits, SDL_Quit must be called atexit(SDL_Quit); //Set the video mode to fullscreen 640x480 with 16bit colour and double-buffering screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF | SDL_FULLSCREEN); if (screen == NULL) { printf("Unable to set video mode: %s\n", SDL_GetError()); return 1; } //Load the bitmap into a temporary surface, and check for success temp = SDL_LoadBMP("hello.bmp"); if (temp == NULL) { printf("Unable to load bitmap: %s\n", SDL_GetError()); return 2; } //Convert the surface to the appropriate display format image = SDL_DisplayFormat(temp); //Release the temporary surface SDL_FreeSurface(temp); //Construct the source rectangle for our blit src.x = 0; src.y = 0; src.w = image-&gt;w; //Use image-&gt;w to display the entire width of the image src.h = image-&gt;h; //Use image-&gt;h to display the entire height of the image //Construct the destination rectangle for our blit dest.x = 100; //Display the image at the (X,Y) coordinates (100,100) dest.y = 100; dest.w = image-&gt;w; //Ensure the destination is large enough for the image's entire width/height dest.h = image-&gt;h; //Blit the image to the backbuffer SDL_BlitSurface(image, &amp;src, screen, &amp;dest); //Flip the backbuffer to the primary SDL_Flip(screen); //Wait for 2500ms (2.5 seconds) so we can see the image SDL_Delay(2500); //Release the surface SDL_FreeSurface(image); //Return success! return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload