Re: Phix 0.8.1 uploaded

new topic     » goto parent     » topic index » view thread      » older message » newer message

I've also got some errors with files missing and some directory related issues. However this can usually be easily resolved. Also, I did a quick test using the new struct feature using my EuSDL2 wrapper.

Phix Version

--include machine.e 
include EuSDL2.ew 
include flags.e 
 
include structs.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 
 
--Use SDL_UpperBlit to draw to screen 
--As this replaces SDL_BlitSurface 
 
struct _RECT 
  integer x  
  integer y  
  integer w  
  integer h  
end struct 
 
_RECT Rect = new() 
 
Rect.x = 10 
Rect.y = 10 
Rect.w = 100 
Rect.h = 100 
 
x = SDL_UpperBlit(img,0,surf,Rect) 
 
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() 
 

Eu Version

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() 
 

Thanks to structs, the Phix version is easier to read and is less lines of code.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu