Re: Help Solving SDL2 Wrapper Example [SOLVED]
- Posted by Icy_Viking Sep 28, 2017
- 1609 views
My bad, I'd been fixing things for Phix and forgot those you'd need, in particular points 5 and 6, and probably point 2.
1) enclose all "include std/*" with --/* and --*/, eg
--/* include std/machine.e --*/
2) both BasicEvent.exw and ColorWinDemo.exw contain "free(key)" which needs to be deleted.
3) insert "{} = " or similar before calls to SDL_UpdateWindowSurface, SDL_SetRenderDrawColor, SDL_RenderFillRect, and SDL_RenderClear
4) "format" is reserved in Phix, change atom format and all uses of it in WinImage.exw to (eg) atom fmt
5) also in WinImage.exw, change
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) poke4(rect+4,sy) poke4(rect+8,tx) poke4(rect+12,ty) end procedure
6) and after x = SDL_BlitSurface(img,srect,surf,drect), change
--if x = 0 then if x != 0 then
Pete
Thanks Pete, it works. Here is the new code. Note, I didn't use the srect(source rectangle) on purpose, since this is just a simple example.
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+4,sy) poke4(rect+8,tx) poke4(rect+12,ty) end procedure --atom srect = allocate(10) atom drect = allocate(10) --calc_rect(srect,10,10,100,100) calc_rect(drect,width / 2,height / 2,100,100) --Use SDL_UpperBlit to draw to screen --As this replaces SDL_BlitSurface x = SDL_UpperBlit(img,0,surf,drect) if x = -1 then puts(1,"Failed to blit image!\n") abort(0) end if integer running = 1 atom key = 0 while running = 1 do SDL_PumpEvents() key = SDL_GetKeyboardState(key) if peek(key+SDL_SCANCODE_ESCAPE) > 0 then running = 0 end if SDL_UpdateWindowSurface(win) end while SDL_FreeSurface(img) SDL_FreeSurface(surf) SDL_DestroyWindow(win) SDL_Quit()