Results 1 to 10 of 31

Thread: Game Developement

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Tried your solution, it dosen't work...

  2. #2
    Quote Originally Posted by Realeg View Post
    Code:
    program grafica;
    
    uses SysUtils,crt,SDL2,SDL2_image;
    
    type Textures=array[1..100] of pSDL_Texture;
    
    var Window:pSDL_Window; var Tex:Textures; Ren:pSDL_Renderer;
    
    procedure Graphic_Initialisation(var Window:pSDL_Window);
    begin
        if SDL_INIT(SDL_INIT_VIDEO)<0 then
            writeln('An error ocurred, the program will now quit')
        else
            begin
                writeln('Graphic mode succesfully initialisated');
                Window:=SDL_CreateWindow('Test',50,50,600,400,SDL_WINDOW_SHOWN);
            end;
    end;
    
    procedure Texture_Loading;
    var path:pChar;
    begin
        Ren:=SDL_CreateRenderer(window,-1,0);
        path:=ExtractFilePath('grafica.exe');
        Tex[1]:=IMG_LoadTexture(Ren,path+'\monster.bmp');
        Tex[2]:=IMG_LoadTexture(Ren,path+'\monster1.bmp');;
    end;
    
    procedure Graphic_Composer;
    var i:byte;
    begin
        Texture_Loading;
        for i:=1 to 100 do
            begin
                if (i mod 2)=1 then
                    begin
                        SDL_RenderCopy(Ren,Tex[1],nil,nil);
                        SDL_RenderPresent(Ren);
                        SDL_DELAY(50);
                    end
                else
                    begin
                        SDL_RenderCopy(Ren,Tex[2],nil,nil);
                        SDL_RenderPresent(Ren);
                        SDL_Delay(50);
                    end;
            end;
    end;
    
    procedure Graphic_Destroy;
    var i:byte;
    begin
        for i:=1 to 100 do    
            SDL_DestroyTexture(Tex[i]);
        SDL_DestroyRenderer(Ren);
        SDL_DestroyWindow(Window);
        SDL_QUIT;
    end;
    
    begin
        clrscr;
        Graphic_Initialisation(Window);
        Graphic_Composer;
        Graphic_Destroy;
    end.
    I think you must validate that ExtractFilePath didn't gets you a string path with '\' at the end. That could produce unexpected results as you are having.

  3. #3
    Am i doing it wrong or... i tried to use what you told me below and got this
    Code:
     path:=pChar(ExtractFilePath(grafica.exeName));
    I know it's wrong, but with what should i replace that to make it work?

  4. #4
    Ahh now I see what is confusing you.

    When I write use Application.ExeName I mean that literally.

    You see in modern pascal dialects the Application is actually a global variable for TApplication class which contains several properties and methods. Best example of seeing this in use is looking ath the source of your project file (*.dpr file).

    And one of its properties is ExeName which contains full filename of your application executable.

  5. #5
    With Freepascal you can also use the "old school" way:
    Code:
    path:=ExtractFilePath(ParamStr(0));
    (No need for pChar as you can see.)
    Best regards,
    Cybermonkey

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
  •