Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 31

Thread: Game Developement

  1. #11
    This is the code i write to manipulate the *.exe file path extractor:

    Code:
    program TextureLoad;
    
    
    uses crt,SDL2,SDL2_image,SysUtils;
    
    
    type R=array[1..100] of pSDL_Renderer;
    	 T=array[1..100] of pSDL_Texture;
    
    
    var window:pSDL_Window; Render:R; Texture:T; i:byte;
    
    
    procedure Graphic_Initialisation;
    begin
    	clrscr;
    	if SDL_INIT(SDL_INIT_VIDEO)<0 then
    		begin
    			writeln('The graphic mode could not be initializated');
    			writeln('The application will now exit');
    			exit;
    		end
    	else
    		window:=SDL_CreateWindow('Texture Window',50,50,600,480,SDL_WINDOW_SHOWN);
    end;
    
    
    Procedure Load_Texture(ExePath:AnsiString);
    begin
    	T[1]:=IMG_LOADTEXTURE(R[1],ExePath+'data\space_armada1.bmp');
    	T[2]:=IMG_LOADTEXTURE(R[2],ExePath+'data\space_armada2.bmp');
    	T[3]:=IMG_LOADTEXTURE(R[3],ExePath+'data\space_armada3.bmp');
    end;
    
    
    
    
    Procedure ComposerFrame;
    var Path:AnsiString;
    begin
    	Path:=ExtractPathFile('Texture.exe');
    	Load_Texture(Path);	
    end;
    			
    	
    	
    procedure Graphic_Destruction;
    begin
    	SDL_DestroyWindow(window);
    	SDL_QUIT;
    end;
    
    
    Begin
    	Graphic_Initialisation;
    	SDL_Delay(2000);
    	ComposerFrame;
    	Graphic_Destruction;
    end.
    And the error is this: Arg no 2: AnsiString found but expected PChar.
    How do i solve it? Is there some kind of function that convert a AnsiString to a PChar? Or something like this?

  2. #12
    This is the code i just write to handle the files. The error i recive is that the path variable gets an AnsiString and the parameter for the IMG_LoadTexture is a pChar. How do i convert them?


    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.

  3. #13
    Quote Originally Posted by Realeg View Post
    This is the code i just write to handle the files. The error i recive is that the path variable gets an AnsiString and the parameter for the IMG_LoadTexture is a pChar. How do i convert them?
    Wrap the code defining path into PChar method:

    Code:
        Tex[1]:=IMG_LoadTexture(PChar(Ren,path+'\monster.bmp'));

  4. #14
    Tried your solution, it dosen't work...

  5. #15
    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.

  6. #16
    Quote Originally Posted by Realeg View Post
    I wonder, how could i make games in Turbo Pascal using graphics? I tried to use the "graph unit" integrated with pascal, but i can't use the keyboard in the graphic window.
    So, i'm here to ask you, what i need to start create a graphic game using Pascal language?
    I would recommend installing Lazarus for that kind of stuff. Turbo pascal is only for learning basics, starting to use graphics on it won't lead anywhere, and gives you too much information you don't need. No modern time games can be made with Turbo Pascal.

  7. #17
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    What Silverwarrior suggested :

    Tex[1]:=IMG_LoadTexture(PChar(Ren,path+'\monster.bmp'));

    should read :

    Tex[1]:=IMG_LoadTexture(Ren,PChar(path+'\monster.bmp'));
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  8. #18
    Quote Originally Posted by phibermon View Post
    What Silverwarrior suggested :

    Tex[1]:=IMG_LoadTexture(PChar(Ren,path+'\monster.bmp'));

    should read :

    Tex[1]:=IMG_LoadTexture(Ren,PChar(path+'\monster.bmp'));
    You are absolutely correct. How could I have made such trivial mistake

  9. #19
    I've tried the the second solution from the very beginning. The error is now that i got a short string instead of pChar. I've tried this solution, but it had the same result.

    Code:
    path:=pChar(ExtractFilePath('grafica.exe'));
    EDIT: The fact is that i just realise that by writing the upper instruction, the path variable is empty. Only if you write the whole path it is kept in the variable, the problem i want to avoid. In the problem with the short-string to pChar, i solved, the problem is this thing now. Getting the file path, without writing the whole path

    If i write

    Code:
    path:=pChar(ExtractFilePath('C:\Pascal\Projects\grafica.exe');
    the variable will keep C:\Pascal\Projects\, otherwise it will be empty.
    Last edited by Realeg; 13-03-2015 at 09:11 PM.

  10. #20
    When you use

    Code:
    ExtractFilePath('grafica.exe');
    your program tires to search for file named grafica.exe in your current directory also know as working directory which may not be the folder from which your application was launched and then extract its path. If the file can't be found in current directoy you will get empty path as a result.

    So extract your program path using

    Code:
    MyAppPath := ExtractFilePath(Application.ExeName);
    as I have suggested to you in the first place.

    Now you already know what ExtractFilePath method does right.
    And Application.ExeName property returns the full filename of your program executable from which you can extract path to the folder in which your executable resides.
    Last edited by SilverWarior; 13-03-2015 at 09:52 PM.

Page 2 of 4 FirstFirst 1234 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
  •