6 Replies - 511 Views - Last Post: 08 October 2013 - 01:14 AM Rate Topic: -----

#1 semichaud1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 14-September 13

Can I blit a portion of a larger surface onto the screen?

Posted 07 October 2013 - 07:05 AM

Hi.

I have been trying to program a scrolling background for an rpg with SDL.

The logic is:
draw background on a large surface of size 13230 x 7350
then select a portion of that large surface which is a rectangle of size 1280 x 720
then display that portion on the screen surface of size 1280 x 720

For some reason the program just draws a blackscreen to the screen instead of copying what is on the portion of the large surface. Is it allowed with SDL to blit to the screen a portion from a surface which is larger than the screen as defined by sdl_setvideomode?

I have also tried a different scrolling technique:
define a matrix of integer
according to the value of each cell of the matrix load corresponding bmp file into a surface at corresponding coordinates
copy that surface to the corresponding portion of the screen
and that is repeated for each cell of the matrix
This process however is quite slow.

What would you suggest as a scrolling technique for an rpg? I am not talking about scrolling whereby a background just loops infinitely like in platformers.

Is This A Good Question/Topic? 0
  • +

Replies To: Can I blit a portion of a larger surface onto the screen?

#2 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,209
  • Joined: 14-February 08

Re: Can I blit a portion of a larger surface onto the screen?

Posted 07 October 2013 - 07:18 AM

Can you give more information on your setup? Do you actually just have a huge image that is your map or are you programatically creating it from some kind of map data such as a tile map?
Was This Post Helpful? 0
  • +
  • -

#3 semichaud1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 14-September 13

Re: Can I blit a portion of a larger surface onto the screen?

Posted 07 October 2013 - 07:25 AM

View Poststayscrisp, on 07 October 2013 - 07:18 AM, said:

Can you give more information on your setup? Do you actually just have a huge image that is your map or are you programatically creating it from some kind of map data such as a tile map?


I have actually tried both techniques.

The huge image gets created with the use of primitives: circle, line, box, pixel, etc. and then once the huge map is drawn, I define a rectangle and copy the portion of the huge map on the screen but I get a blackscreen.

Doing the scrolling using a tile map works but it is too slow because the surface 1280 x 720 is too large and I want to keep it this large without losing performance.
Was This Post Helpful? 0
  • +
  • -

#4 semichaud1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 14-September 13

Re: Can I blit a portion of a larger surface onto the screen?

Posted 07 October 2013 - 07:31 AM

View Postsemichaud1, on 07 October 2013 - 07:25 AM, said:

View Poststayscrisp, on 07 October 2013 - 07:18 AM, said:

Can you give more information on your setup? Do you actually just have a huge image that is your map or are you programatically creating it from some kind of map data such as a tile map?


I have actually tried both techniques.

The huge image gets created with the use of primitives: circle, line, box, pixel, etc. and then once the huge map is drawn, I define a rectangle and copy the portion of the huge map on the screen but I get a blackscreen.

Doing the scrolling using a tile map works but it is too slow because the surface 1280 x 720 is too large and I want to keep it this large without losing performance.


Below is a sample of my code:


procedure drawworld;
label drawworldlb1;
begin
 sprsurf:=sdl_creatergbsurface(sdl_swsurface,13230,7350,32,0,0,0,0);
 o[1]:=0;
 repeat
  o[1]:=o[1]+1;
  o[2]:=-1;
  repeat
   o[2]:=o[2]+1;
   o[3]:=-1;
   repeat
    o[3]:=o[3]+1;
    if (o[1]=1) and (bkgm[o[2],o[3]]=0) then goto drawworldlb1;
    if (o[1]=2) and (objm[o[2],o[3]]=0) then goto drawworldlb1;
    if o[1]=1 then sdl_setcolorkey(sprsurf,0,sdl_maprgb(screen^.format,0,0,0));
    if o[1]=2 then sdl_setcolorkey(sprsurf,sdl_srccolorkey,sdl_maprgb(screen^.format,0,0,0));
    if o[1]=1 then str(bkgm[o[2],o[3]],st[1]);
    if o[1]=2 then str(objm[o[2],o[3]],st[1]);
drawworldlb1:
   until o[3]=350;
  until o[2]=630;
 until o[1]=2;
 sdl_savebmp(sprsurf,'bkg.bmp');
end;

procedure copyworld;
begin
 source_rect^.x:=a[6]*21;
 source_rect^.y:=a[7]*21;
 source_rect^.w:=1280;
 source_rect^.h:=720;
 destination_rect^.x:=0;
 destination_rect^.y:=0;
 destination_rect^.w:=1280;
 destination_rect^.h:=720;
 sdl_blitsurface(sprsurf,source_rect,screen,destination_rect);
end;

program main;
begin
 {...}
 clearscr; {clears the screen area for drawing of bmp files}
 a[1]:=31; a[2]:=17;
 a[6]:=a[1]-30;
 a[7]:=a[2]-16;
 a[8]:=a[1]+30;
 a[9]:=a[2]+16;
 clearscr;
 drawworld;
 copyworld;
 sdl_flip(screen);
 pause;
 halt;
 {...}
end.




Don't worry about correcting the code. If you can suggest a better way to achieve a scrolling effect please let me know.
Was This Post Helpful? 0
  • +
  • -

#5 semichaud1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 14-September 13

Re: Can I blit a portion of a larger surface onto the screen?

Posted 07 October 2013 - 09:12 AM

View Postsemichaud1, on 07 October 2013 - 07:31 AM, said:

View Postsemichaud1, on 07 October 2013 - 07:25 AM, said:

View Poststayscrisp, on 07 October 2013 - 07:18 AM, said:

Can you give more information on your setup? Do you actually just have a huge image that is your map or are you programatically creating it from some kind of map data such as a tile map?


I have actually tried both techniques.

The huge image gets created with the use of primitives: circle, line, box, pixel, etc. and then once the huge map is drawn, I define a rectangle and copy the portion of the huge map on the screen but I get a blackscreen.

Doing the scrolling using a tile map works but it is too slow because the surface 1280 x 720 is too large and I want to keep it this large without losing performance.


Below is a sample of my code:


procedure drawworld;
label drawworldlb1;
begin
 sprsurf:=sdl_creatergbsurface(sdl_swsurface,13230,7350,32,0,0,0,0);
 o[1]:=0;
 repeat
  o[1]:=o[1]+1;
  o[2]:=-1;
  repeat
   o[2]:=o[2]+1;
   o[3]:=-1;
   repeat
    o[3]:=o[3]+1;
    if (o[1]=1) and (bkgm[o[2],o[3]]=0) then goto drawworldlb1;
    if (o[1]=2) and (objm[o[2],o[3]]=0) then goto drawworldlb1;
    if o[1]=1 then sdl_setcolorkey(sprsurf,0,sdl_maprgb(screen^.format,0,0,0));
    if o[1]=2 then sdl_setcolorkey(sprsurf,sdl_srccolorkey,sdl_maprgb(screen^.format,0,0,0));
    if o[1]=1 then str(bkgm[o[2],o[3]],st[1]);
    if o[1]=2 then str(objm[o[2],o[3]],st[1]);
drawworldlb1:
   until o[3]=350;
  until o[2]=630;
 until o[1]=2;
 sdl_savebmp(sprsurf,'bkg.bmp');
end;

procedure copyworld;
begin
 source_rect^.x:=a[6]*21;
 source_rect^.y:=a[7]*21;
 source_rect^.w:=1280;
 source_rect^.h:=720;
 destination_rect^.x:=0;
 destination_rect^.y:=0;
 destination_rect^.w:=1280;
 destination_rect^.h:=720;
 sdl_blitsurface(sprsurf,source_rect,screen,destination_rect);
end;

program main;
begin
 {...}
 clearscr; {clears the screen area for drawing of bmp files}
 a[1]:=31; a[2]:=17;
 a[6]:=a[1]-30;
 a[7]:=a[2]-16;
 a[8]:=a[1]+30;
 a[9]:=a[2]+16;
 clearscr;
 drawworld;
 copyworld;
 sdl_flip(screen);
 pause;
 halt;
 {...}
end.




Don't worry about correcting the code. If you can suggest a better way to achieve a scrolling effect please let me know.


I forgot to program the bit of code that loads the bmp tile into the surface and then copies to screen. No wonder it's displaying a blackscreen. I'll fix that.
Was This Post Helpful? 0
  • +
  • -

#6 semichaud1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 14-September 13

Re: Can I blit a portion of a larger surface onto the screen?

Posted 07 October 2013 - 09:32 AM

Ok. It works. Creating a large surface and then bliting portions of it to the screen eventhough the screen is smaller. My mistake having forgotten to actually program the loading of bmp tiles and copying to the surface.

I don't know how to close this thread.
Was This Post Helpful? 0
  • +
  • -

#7 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,209
  • Joined: 14-February 08

Re: Can I blit a portion of a larger surface onto the screen?

Posted 08 October 2013 - 01:14 AM

There is no need to close it. Glad you sorted your issue out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1