Recent

Author Topic: SDL 2 Unit -x position  (Read 4747 times)

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
SDL 2 Unit -x position
« on: August 26, 2016, 12:10:24 am »
Hi guys, why if i set render viewport with x = -1, the image i want to show is not shown?
Bad english.
If i write an image (width:100px) to x = 1, it is normal written, but not written if x was under 0 (ex -1).
How can i solve this? Please help
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: SDL 2 Unit -x position
« Reply #1 on: August 26, 2016, 12:39:21 am »
That's probably clipping at work for you.

Instead of 'blitting' to position -1, you could consider blitting to position 0, but subtract the absolute minus value from the width that your are blitting.

Carver413

  • Full Member
  • ***
  • Posts: 119
Re: SDL 2 Unit -x position
« Reply #2 on: August 26, 2016, 12:56:19 am »
the viewport is used to define a drawing area within surface boundary's   not to move images, try SDL_BlitSurface

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Re: SDL 2 Unit -x position
« Reply #3 on: August 26, 2016, 07:00:46 pm »
That's probably clipping at work for you.

Instead of 'blitting' to position -1, you could consider blitting to position 0, but subtract the absolute minus value from the width that your are blitting.
I'm italian so i dont know the meaning of blitting and in the sdl2 tutorial i didn't found any example of PSDL_Surface. The only things there are in my gamealgoryrhm: SDL_RenderClear, SDL_RenderSetViewport, SDL_RenderCopy, SDL_RenderPresent.. nothing other (of sdl istructions)
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

Carver413

  • Full Member
  • ***
  • Posts: 119
Re: SDL 2 Unit -x position
« Reply #4 on: August 26, 2016, 08:23:39 pm »

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Re: SDL 2 Unit -x position
« Reply #5 on: August 26, 2016, 09:52:47 pm »
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

Carver413

  • Full Member
  • ***
  • Posts: 119
Re: SDL 2 Unit -x position
« Reply #6 on: August 27, 2016, 09:34:37 am »
I managed to get it working, I usually don't work with surfaces just opengl the texture I'm using is here
http://www.aaroncox.net/tutorials/2dtutorials/bat.bmp
Code: Pascal  [Select][+][-]
  1. program Example1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes,SDL2
  10.   { you can add units after this };
  11. Var
  12.   Window:PSDL_Window;
  13.   Renderer:PSDL_Renderer;
  14.   Bat:PSDL_Surface;
  15.   TexBat:PSDL_Texture;
  16.   ImageRect:TSDL_Rect;
  17.   Position:TSDL_Rect;
  18. begin
  19.   SDL_CreateWindowAndRenderer(640,480,0, @Window, @Renderer);
  20.   SDL_RenderClear(Renderer);
  21.   Bat:=SDL_LoadBMP('bat.bmp');
  22.   SDL_SetColorKey( Bat, 1,SDL_MapRGB(Bat^.format, 255, 0, 255));
  23.   TexBat:=SDL_CreateTextureFromSurface(Renderer,Bat);
  24.   with ImageRect do begin
  25.     x:=0;
  26.     y:=0;
  27.     w:=100;
  28.     h:=200;
  29.   end;
  30.   with Position do begin
  31.     x:=-30;
  32.     y:=0;
  33.     w:=100;
  34.     h:=200;
  35.   end;
  36.   SDL_RenderCopy(Renderer,TexBat,@ImageRect,@Position);
  37.   SDL_RenderPresent(Renderer);          
  38.   SDL_Delay(3000);
  39.   SDL_FreeSurface(Bat);
  40.   SDL_DestroyTexture(TexBat);
  41.   SDL_DestroyRenderer(Renderer);
  42.   SDL_DestroyWindow(Window);
  43.   SDL_Quit();
  44.  
  45. end.

 

TinyPortal © 2005-2018