Re: Help Solving SDL2 Wrapper Example
- Posted by Icy_Viking Sep 27, 2017
- 1677 views
petelomax said...
OK, I downloaded eusdl2.zip and opened sdl2.dll with dependency walker, only to find there is no SDL_BlitSurface entry.
So I downloaded the source code and a quick search revealed, in SDL_surface.h, this little gem:
#define SDL_BlitSurface SDL_UpperBlit
Hence I humbly suggest this may help:
xSDL_BlitSurface = define_c_func(sdl2,"SDL_UpperBlit",{C_POINTER,C_POINTER,C_POINTER,C_POINTER},C_INT)
Pete
PS: a comment along the lines of --NB this is NOT a typo! seems warranted.
Thanks Pete. I also noticed there was an UpperBlitScaled function as well. I think I'll wrap that as well. Probably keep BlitSurface as legacy code for now.
EDIT: Well I added in the UpperBlit functions, now I get this error.
function SDL_RWFromFile() type_check failure, fname is 42840784 fname = 42840784 mode = {114'r',98'b'} str = <no value> str2 = <no value> ret = <no value> in function SDL_LoadBMP() fname = {83'S',68'D',76'L',46'.',98'b',109'm',112'p'} str = 42840784 src (from inlined routine 'SDL_LoadBMP_RW' at 13) = <no value>
public constant xSDL_RWFromFile = define_c_func(sdl2,"SDL_RWFromFile",{C_POINTER,C_POINTER},C_POINTER) public function SDL_RWFromFile(sequence fname,sequence mode) atom str = allocate_string(fname,1) atom str2 = allocate_string(mode,1) atom ret = c_func(xSDL_RWFromFile,{str,str2}) return ret end function public constant xSDL_LoadBMP = define_c_func(sdl2,"SDL_LoadBMP",{C_POINTER},C_POINTER), xSDL_LoadBMP_RW = define_c_func(sdl2,"SDL_LoadBMP_RW",{C_POINTER,C_INT},C_POINTER) public function SDL_LoadBMP_RW(atom src,integer xfree) return c_func(xSDL_LoadBMP_RW,{src,xfree}) end function public function SDL_LoadBMP(sequence fname) atom str = allocate_string(fname,1) return SDL_LoadBMP_RW(SDL_RWFromFile(str,"rb"),1) end function
--Demo currently not working include std/machine.e include EuSDL2.ew include flags.e atom width = 800, height = 600 atom buffer,format atom x x = SDL_Init(SDL_INIT_EVERYTHING) if x = -1 then puts(1,"Failed to load initialize SDL!\n") abort(0) end if atom win = SDL_CreateWindow("Window Image",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,width,height,SDL_WINDOW_SHOWN) if win = -1 then puts(1,"Failed to create window!\n") abort(0) end if atom surf = SDL_GetWindowSurface(win) atom img = SDL_LoadBMP("SDL.bmp") if img = -1 then puts(1,"Failed to load image!\n") abort(0) end if procedure calc_rect(atom rect,integer sx,integer sy,integer tx,integer ty) poke4(rect,sx) poke4(rect+2,sy) poke4(rect+4,tx) poke4(rect+6,ty) end procedure atom srect = allocate(10) atom drect = allocate(10) calc_rect(srect,0,0,100,100) calc_rect(drect,0,0,100,100) format = peek4u(surf+4) buffer = SDL_ConvertSurface(surf,format,0) x = SDL_UpperBlit(img,srect,surf,drect) if x = 0 then puts(1,"Failed to blit image!\n") abort(0) end if SDL_UpdateWindowSurface(win) SDL_Delay(3000) SDL_FreeSurface(img) SDL_FreeSurface(surf) SDL_DestroyWindow(win) SDL_Quit()