Results 1 to 4 of 4

Thread: Drawing a bitmap?

  1. #1

    Drawing a bitmap?

    Hello,
    I'm using JEDI-SDL in Freepascal with no problems. Initialisation is working, now I want to go a step further and draw bitmap on the screen. I've tried a bit, but it doesn't work.
    When I was using the example of the documentation, there was a compiling error. The demos of JEDI-SDL are a little too complex for me as a JEDI-SDL-beginner.
    Perhaps someone could help me and write a basic example how to load and display a bitmap.
    Freeze Development | Elysion Game Framework | Twitter: @Stoney_FD
    Check out my new book: Irrlicht 1.7.1 Realtime 3D Engine Beginner's Guide (It's C++ flavored though)

    Programmer: A device for converting coffein into software.

  2. #2

    Drawing a bitmap?

    Could you try this...
    [pascal]
    program HelloBitmap;

    uses
    sdl;

    var
    // Done flag
    Done : Boolean;

    // Event record
    event : TSDL_Event;

    // Our Screen Surface;
    screen : PSDL_Surface;

    // Our Background image
    imgBackGround : PSDL_Surface;
    begin
    // Initialize SDL
    if SDL_Init( SDL_INIT_VIDEO ) < 0 then
    begin
    // Display an error
    Halt( 1 );
    end;

    // Set the Window Caption
    SDL_WM_SetCaption( 'My first Bitmap', nil );

    // Set the video Mode
    screen := SDL_SetVideoMode( 800, 600, 16, SDL_DOUBLEBUF or SDL_ANYFORMAT );
    if screen = nil then
    begin
    // Display an error
    SDL_Quit;
    Halt( 1 );
    end;

    // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
    imgBackGround := SDL_LoadBMP( 'MyImage.bmp' );
    if ( imgBackGround <> nil ) then
    begin
    // wait for user to press a key or click the X
    Done := False;
    while ( not Done ) do
    begin
    // This could go in a separate function
    while ( SDL_PollEvent( @event ) = 1 ) do
    begin
    case event.type_ of
    SDL_QUITEV :
    begin
    // handle click to close Window - User Clicks on X on title bar
    Done := true;
    end;

    SDL_KEYDOWN :
    begin
    // handle key press - check for Escape key
    if event.key.keysym.sym = SDLK_ESCAPE then
    Done := true;
    end;
    end;
    end;
    // draw onto our back buffer
    SDL_BlitSurface( imgBackGround, nil, screen, nil );

    //Flip to our main surface
    SDL_Flip( screen );
    end;
    end
    else
    begin
    SDL_Quit;
    // Display an error
    Halt( 1 );
    end;

    // Free up any memory we may have used
    if ( imgBackGround <> nil ) then
    SDL_FreeSurface( imgBackGround );
    SDL_Quit;
    end.
    [/pascal]
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  3. #3

    Drawing a bitmap?

    Thanks, it works really well.
    After practising more and more with SDL, I love and enjoy JEDI-SDL now.
    Currently I'm working on an engine (and games based on this engine) with SDL and I have a new question: Is there any possibility to stretch a bitmap or an image?
    I tried a bit with TSDL_Rects, but the image is drawn originally, without any stretching effects.
    Freeze Development | Elysion Game Framework | Twitter: @Stoney_FD
    Check out my new book: Irrlicht 1.7.1 Realtime 3D Engine Beginner's Guide (It's C++ flavored though)

    Programmer: A device for converting coffein into software.

  4. #4

    Drawing a bitmap?

    If you look within JEDI-SDL, you should find a Utility unit ( sdlutils.pas ) that supports stretching your bitmap and other things. There should be some demos showing off what the utilities can do.

    SDL itself does not support this natively yet. I believe SDL will support this when the make the OpenGL back-end a permanent fixture.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •