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
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
'
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"
Does putting byval on all the parameters help?
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
.
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.
Dim shared makes what ever your diming public.
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
If you have an argument with the same name it will be used instead - QB quirk.
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"