Re: Help Solving SDL2 Wrapper Example
- Posted by Icy_Viking Sep 27, 2017
- 1576 views
petelomax said...
That's a pretty basic error...
public function SDL_LoadBMP(sequence fname) -- atom str = allocate_string(fname,1) -- return SDL_LoadBMP_RW(SDL_RWFromFile(str,"rb"),1) return SDL_LoadBMP_RW(SDL_RWFromFile(fname,"rb"),1) end function
works fine here (on Phix) anyway.
OK I changed that. It fixed it, but I had to change some of the demo source code for it to work and show the image.
--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 --calc rect doesen't seem to affect anything. 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,0,surf,0) --had to change the srcRect and dstRect to 0 for the image to show 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()