Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Jedi SDL - how to start?

  1. #11

    Jedi SDL - how to start?

    Quote Originally Posted by Loodziek
    @technomage
    Yep, I read this issue when it's only appear, but I want test pure SDL power But thanks for respond.

    @arthurprs
    Am from Poland, Arthur. I have a question. When I try to compile your source:
    [pascal]SDL_SetColorKey(surface, // surface is the surface that want to set a transparent color
    SDL_RLEACCEL or SDL_SRCCOLORKEY,
    SDL_MapRGB(surface.format, r, g, b)); // this color will be transparent[/pascal]

    It's ok when I compile it in Delphi 7, but when I try to compile it in Lazarus it's isn't works:

    Error image

    What's going on?

    @WILL
    I'ill try

    Thanks a lot again.
    :? No ideia, i don't see anything wrong at this line
    From brazil (:

    Pascal pownz!

  2. #12
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Jedi SDL - how to start?

    What version of JEDI-SDL do you have? And, you are using the JEDI-SDL headers right?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  3. #13

    Jedi SDL - how to start?

    1.0 Beta I think. Just try compile this code in Delphi, then compile it in Lazarus:

    [pascal]
    program Test;
    uses SDL;

    var
    surface : PSDL_Surface;

    begin

    SDL_SetColorKey(surface, SDL_RLEACCEL or SDL_SRCCOLORKEY, SDL_MapRGB(surface.format, 255, 0, 255));

    end.
    [/pascal]

    Runtime error doesn't matter.


    -Edit-

    Ok, I read some sources and I find where be an error. Well it should be "surface^.format" not "surface.format". Now everything should works fine

  4. #14

    Jedi SDL - how to start?

    Hi again. When I know basics of SDL it's time to try write something. But, at start I find a first problem. I wanna load map from file to dynamic table. So first I must do SetLength, right? I write a dwo functions to get X and Y. Here is my map file (data\maps\map1.txt):
    Code:
    1 1 1 2 1 1 1 1 1
    2 2 2 2 2 2 2 2 1
    1 1 2 1 1 1 1 2 1
    1 1 2 1 1 1 1 2 1
    1 1 2 2 2 2 2 2 1
    1 1 1 1 1 1 1 2 1
    There are two sprites. Map X is a spaces count in one line + 1, right? So there's my funciton:
    [pascal]
    function GetMapX : integer;
    var
    count : integer;
    StrChain : string;
    MapFile : TextFile;
    begin
    AssignFile(MapFile, MapPath); //Map path is a global cons 'data\maps\map1.txt'
    Reset(MapFile);
    Read(MapFile, StrChain);
    Result := 0;
    for count := 0 to Length(StrChain) do
    if StrChain[count] = ' ' then
    Result := Result + 1;
    Result := Result + 1;
    CloseFile(MapFile);
    end;
    [/pascal]

    I hope it's clear for u. This function is in "Maps.pas". And there's my project file. Everything works fine:
    [pascal]
    program SDL_proby;

    {$mode objfpc}{$H+}

    uses
    SDL, SDL_Image, ImagesDraw, SDL_TTF, FontsDraw, Maps, Player;

    const

    //Wymiary okna
    width = 900;
    height = 900;

    var
    screen : PSDL_Surface;
    grass : PSDL_Surface;

    logo : PSDL_Surface;
    road_horizontal : PSDL_Surface;

    pos : TSDL_Rect;

    i : integer;

    loop : boolean;

    procedure Init;
    begin
    SDL.SDL_Init(SDL_Init_Video);
    screen := SDL_SetVideoMode(width, height, 32, SDL.SDL_SWSurface);
    TTF_Init;
    loop := true;
    end;

    procedure OnQuit;
    begin
    SDL.SDL_FreeSurface(grass);
    SDL.SDL_FreeSurface(screen);
    TTF_Quit;
    SDL.SDL_Quit;
    end;

    procedure doGameInput;
    var
    KeyPress : TSDL_Event;
    begin
    while (SDL.SDL_PollEvent(@KeyPress) > 0) do
    case (KeyPress.Type_) of SDL.SDL_Keydown :
    if (KeyPress.Key.keysym.sym = SDL.SDLK_ESCAPE) then loop := false;
    end;
    end;


    //*************************************************
    //************ KOD G¬£?ìWNY PROGRAMU*****************
    //*************************************************

    begin
    Init;
    for i := 0 to 5 do ImagesDraw.DrawImage('C:\Documents and Settings\WINDOWS XP\Moje dokumenty\Moje obrazy\grass.jpg', i * 64, 0, 64, 64, screen);
    for i := 0 to 5 do ImagesDraw.DrawImage('C:\Documents and Settings\WINDOWS XP\Moje dokumenty\Moje obrazy\road.jpg', i * 64, 128, 64, 64, screen);
    ImagesDraw.DrawImage('C:\Documents and Settings\WINDOWS XP\Moje dokumenty\Moje obrazy\beczka.bmp', 0, 0, 64, 64, screen);

    repeat
    SDL.SDL_Delay(30);
    doGameInput;
    SDL.SDL_Flip(screen);
    until loop = false;

    OnQuit;
    end.
    [/pascal]

    I know, I know there's a not used vars and it's not optimized yet. Anyway, it works. But when I put "mx : integer" to var and put "mx := GetMapX" to code it's compiling but I get only black screen. Why it don't work? When I compile my GetMapX function in Delphi and do:
    [pascal]
    mx := GetMapX;
    ShowMessage(IntToStr(mx));
    [/pascal]

    Then I get 9 (it works). I'm trying, and tying but after some tryies I must restar coputer because something is wrong with exe file... So it's very bored And sorry for double posting - I just want to set topic into "New Posts" state.

  5. #15

    Jedi SDL - how to start?

    Yeah you get the function working but you drawed the map ?

    I use Tstringlist in my bitmapfont unit, but in your case i think its not suitable, i don't have sure but TTF are veryyy slow on asphyre {that is lot faster than SDL} compared to prerendered fonts so i would suggest you to use bitmap fonts instead.

    About the exe problem i don't know :?
    From brazil (:

    Pascal pownz!

  6. #16

    Jedi SDL - how to start?

    Yes, I don't draw map yet. I just want to check my function and prgram crashes. And I don't know why :/ What bitmapfonts and TTF have to mine problem? :think:

  7. #17

    Jedi SDL - how to start?

    Quote Originally Posted by Loodziek
    Yes, I don't draw map yet. I just want to check my function and prgram crashes. And I don't know why :/ What bitmapfonts and TTF have to mine problem? :think:
    If you don't nothing the screen will be black,

    *no its only a suggestion for better speed.
    From brazil (:

    Pascal pownz!

  8. #18

    Jedi SDL - how to start?

    Arthur, look to my code again. There is a procedure "DrawImage" I draw 4 grass sprites, 4 road sprites and one barrel But when I just put my function to file program don't render anything and it cannot be closed (I must use Crtl + Alt + Delete). I found a line where's program crash:
    [pascal] Read(MapFile, StrChain); [/pascal]
    When I write ReadLn theres a the same problem. What do u think?

  9. #19

    Jedi SDL - how to start?

    Quote Originally Posted by Loodziek
    Arthur, look to my code again. There is a procedure "DrawImage" I draw 4 grass sprites, 4 road sprites and one barrel But when I just put my function to file program don't render anything and it cannot be closed (I must use Crtl + Alt + Delete). I found a line where's program crash:
    [pascal] Read(MapFile, StrChain); [/pascal]
    When I write ReadLn theres a the same problem. What do u think?
    Make use of SDL_Blitsurface insted..

    So it crashes while reading the file ?
    From brazil (:

    Pascal pownz!

  10. #20

    Jedi SDL - how to start?

    My DrawImage is a IMG_Load, BlitSurface and others

    And yes, program crashes when I try to read file. Is it possible to use TextFiles with JEDI-SDL?

Page 2 of 3 FirstFirst 123 LastLast

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
  •