Qbasicnews.com
May 21, 2022, 03:00:43 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SDL] Copy parts from surface to other surfaces  (Read 4313 times)
dutchtux
Member
*
Posts: 29


WWW
« on: January 09, 2005, 06:59:12 PM »

I want to copy a part from surface to antoher surface.
Can you tell me what function i must use with SDL and how it works.
A simple Example can be handy
Logged
ShadowWolf
Wandering Guru
***
Posts: 389



« Reply #1 on: January 09, 2005, 07:58:32 PM »

SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect,
                          SDL_Surface *dst, SDL_Rect *dstrect)

you use the type SDL_rect and place the cordnets in there for the surface you want to copy from then use another SDL_RECT structor for the dest

i.e.
DIM img as SDL_surface ptr      '
DIM screen as SDL_surface ptr ' surfaces

'
' some code here to load a bmp or somthing into the surface's
'
dim  dest  as SDL_RECT
dim  source  as SDL_RECT
 
  source.x= 20
  source.y = 20
  source.h = 20
  source.w = 20

  dest.x = x;
  dest.y = y;
 
  SDL_BlitSurface(img, @source, screen, @dest);
 

'  i just did this of the top of my head so i'm not sure i got it right 'but i think i did
'
Logged
dutchtux
Member
*
Posts: 29


WWW
« Reply #2 on: January 09, 2005, 08:49:30 PM »

Problem Solved

Try to get it work but in someway it doesnt display the sprite

here is my subroutine:

Code:

sub putsprite(surfsource as SDL_Surface ptr, sprx, spry, sprnum)
   dim dest as SDL_Rect
   dim source as SDL_Rect
   
   source.x = sprnum * 32
   source.y = 0
   source.w = 32
   source.h = 32
     
   dest.x = sprx
   dest.y = spry  
   
   SDL_BlitSurface(surfsource, varptr(source), video, varptr(dest))
end sub


In some way it the SDL_blitsurface returns -1 I dont get that somewhere else but there is "varptr(source)"  is "0"
Logged
Sterling Christensen
Na_th_an
*****
Posts: 1328


« Reply #3 on: January 10, 2005, 01:28:50 AM »

Does putting byval on all the parameters help?
Logged
dutchtux
Member
*
Posts: 29


WWW
« Reply #4 on: January 10, 2005, 03:39:12 AM »

Well the problem was that "video" not a public sd_interface was.
So it needed to be added in the parameters or make it public.
I did the last one cause I forgot how it was in QB Sad.
As long SDL_interface's arent public you cant access him in sub/functions

So the subroutine is now like this:
Code:

sub putsprite(surfsource as SDL_Surface ptr, video as SDL_Surface ptr, sprpos as SDL_Rect, sprnum)
   dim source as SDL_Rect
   
   source.x = int(sprnum * 32)
   source.y = 0  
   source.w = 32
   source.h = 32
 
   SDL_BlitSurface surfsource, varptr(source), video, varptr(sprpos)      
end sub


This way it will work.
Logged
ShadowWolf
Wandering Guru
***
Posts: 389



« Reply #5 on: January 10, 2005, 10:37:56 PM »

Dim shared makes what ever your diming public.
Logged
dutchtux
Member
*
Posts: 29


WWW
« Reply #6 on: January 11, 2005, 02:25:55 PM »

It 's seems that if you make SDL_surface public you can't access it in subs
I got it like this:

Code:

   drawtext video, 64, 16, "This 1337 stuff is hot! Hope it got number support :)"

sub drawtext(video as SDL_Surface ptr, x, y, text as string)
   dim txtlen as integer
   dim charint as integer
   dim charrect as SDL_Rect
   
   txtlen = len(text)  
   for e% = 1 to txtlen
      charint = asc(mid$(text,e%,1))
      charrect.x = int((x + e%) * 16)
      charrect.y = int(y)
      if charint > 97 or charint < 122 then
         putsprite16 letterspr, video, charrect, charint - 98
      end if
      if charint > 65 or charint < 90 then
         putsprite16 letterspr, video, charrect, charint - 124
      end if
   next
end sub

sub putsprite16(surfsource as SDL_Surface ptr, video as SDL_Surface ptr, sprpos as SDL_Rect, sprnum)
   dim source as SDL_Rect
   
   source.x = int(sprnum * 16)
   source.y = 0  
   source.w = 16
   source.h = 16
 
   SDL_BlitSurface surfsource, varptr(source), video, varptr(sprpos)      

end sub

I dont know if it's a bug
Logged
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #7 on: January 11, 2005, 02:34:51 PM »

If you have an argument with the same name it will be used instead - QB quirk.
Logged

dutchtux
Member
*
Posts: 29


WWW
« Reply #8 on: January 11, 2005, 02:51:07 PM »

Well strange it doesnt draw it on the screen but gives as result 0
so it happens but in someway it doesnt getting draw on the screen.

the only thing that is shared is "letterspr"
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!