|
#1
|
||||
|
||||
|
I'm getting tiered with plugging and unplugging my Zen X-fi2 every time
I want to test or change a parameter. Looking for a graphic environment for 'Lua 5.1 for windows' did not go well. But i came across this: LuaSDL from http://luaforge.net/frs/?group_id=242&release_id=781 FILE: http://luaforge.net/frs/download.php...in32-0.3.4.zip With this i can now program in LUA on windows with graphic output it has different names for most of the creative custom stuff, but it's very close. And with the source code to luaSDL available, maybe it could be altered to fit. 2 examples. X-fi2 - color_black = color.new(0,0,0); win32 - color_black = SDL.SDL_MapRGB(screen.format,0,0,0); X-fi2 - screen.drawpixel(x,y,pixelcolor) win32 - SDL.SDL_PutPixel(screen,x,y,pixelcolor); So ! I'm using the sciTE editor that comes with 'Lua 5.1 for Windows' as a text editor with lua highlight and to clear up syntax error's. ![]() I save the file when done, and click and drag it over the luasdl.exe file: ![]() Graphic output, a windows at 400x240 pixels: Planets[1] ![]() Here is a template file where the create window stuff in made into a function initscreen(); and cleaned up. There is more examples in the file __init__.lua it gets run when luasdl.exe is run without parms. Code:
-- Template for demos.
-- This file is part of LuaSDL.
-- PUBLIC DOMAIN. Author: Kein-Hong Man <khman@users.sf.net> 2007
------------------------------------------------------------------------
function initscreen()
local SDL = SDL -- local ref to SDL library
-- test initialization of SDL
if SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING) < 0 then
error("Couldn't initialize SDL: "..SDL.SDL_GetError().."\n")
os.exit(1)
end
SDL.SDL_WM_SetCaption("X-Fi2 Application Programming", "demo")
screen = SDL.SDL_SetVideoMode(400, 240, 32, 0) --set window size
if not screen then
error("Couldn't set video mode: "..SDL.SDL_GetError().."\n");
end;
end;
function putpixel(x,y,pixelcolor)
local i=1;
if ( x > 399 ) then i=0; end;
if ( x < 0 ) then i=0; end;
if ( y > 239 ) then i=0; end;
if ( y < 0 ) then i=0; end;
if ( i == 1 ) then
SDL.SDL_PutPixel(screen,x,y,pixelcolor);
end;
end;
function planets(refx,refy)
color_front = SDL.SDL_MapRGB(screen.format,255,255,0);
color_shaded = SDL.SDL_MapRGB(screen.format,240,0,0);
size = 100;
sizes = size*size;
for y=-size,size do
aq=sizes-y*y;
x=math.sqrt(aq);
x2=x*2;
for i=-x,x do
if (math.random(0,x2)-x <i) then putpixel(refx+i,refy+y,color_front);
else putpixel(refx+i,refy+y,color_shaded);
end;
end;
end;
end;
initscreen();
color_black = SDL.SDL_MapRGB(screen.format,0,0,0);
color_white = SDL.SDL_MapRGB(screen.format,255,255,255);
putpixel(200,120,color_white);
planets(200,120);
SDL.SDL_UpdateRect(screen, 0, 0, 0, 0);
local event = SDL.SDL_Event_local()
while true do
while (SDL.SDL_PollEvent(event) == 0) do
SDL.SDL_Delay(10)
end
local c = event.type
if c == SDL.SDL_KEYDOWN then
local key = event.key.keysym.sym
if key == SDL.SDLK_ESCAPE then
break
end
elseif c == SDL.SDL_QUIT then
break
end
end
SDL.SDL_Quit()
-- end of script
Creative Graphics on the BBC Microcomputer by John Cownie. - good book,lol,,, i bought it around 82-83 i think. Last edited by Jan_DK; 12-22-2009 at 05:42 PM. Reason: Function putpixel in error and missing 2 limit, very importent |
|
|
|||
|
|
|
#2
|
||||
|
||||
|
In the programming language C there is this way of switching
code blocks depending on the run environment. #define RUN_ON_X-Fi2 #ifdef RUN_ON_X-Fi2 --code block for running on x-fi2 color_black = color.new(0,0,0); #else --code block for running on win32 luaSDL color_black = SDL.SDL_MapRGB(screen.format,0,0,0); #endif Do anyone knows what LUA has to offer in that area. ? Jan |
|
#3
|
||||
|
||||
|
Now I'm trying to emulate the Creative custom function.
It's starting out slow, but it works. Here is an example code of the substitute LuaSDL functions for screen.drawpixel, screen.update, color.new, os.sleep. Code:
--X-Fi2 Emulation functions "screen."
--Creating new tables with sub tables
screen = { drawpixel = self, update = self};
function screen.drawpixel(x,y,pixelcolor)
SDL.SDL_PutPixel(display,x,y,pixelcolor);
end;
function screen.update()
SDL.SDL_UpdateRect(display, 0, 0, 0, 0);
end;
--X-Fi2 Emulation functions "color."
--creating new tables with sub table
color = { new = self };
function color.new(r,g,b)
return SDL.SDL_MapRGB(display.format,r,g,b);
end;
--X-Fi2 Emulation functions "os." creating new sub tables
function os.sleep(z)
SDL.SDL_Delay(z);
end;
I've made this classic starfield screensaver into a dual X-Fi2 and LuaSDL program, dual in that regards that it take a few steps to make the switch from the current X-Fi2 state, and into LuaSDL. Steps 3 & 4 are only necessary right now be course I've not done the substitute func for control.read & control.isbutton yet. ![]() screen-shot of windows starfield screen saver. It's to hard to take real pic's of this on the X-fi2. steps for making the Starfield running on LuaSDL 1. Remove a '[' from line 7 after the --[ 2. Remove a '[' from line 72 after the --[ 3. Place a '[' at line 128 --[hold 4. Remove a '[' from line 134 --[[ 5. Remove -- to start of line 150 The Starfield Code: ready to run on the X-fi2 Code:
-- Template for demos. This file is part of LuaSDL. luaSDL code Author: Kein-Hong Man 2007
-- lua adaptation by Jan_DK of the starfield code from:
-- http://freespace.virgin.net/hugo.elias/graphics/x_stars.htm
------------------------------------------------------------------------
--[[ SDL Creative X-Fi2 Emulation function block start.
--SDL window setup
function init_SDL_screen()
local SDL = SDL -- local ref to SDL library
-- test initialization of SDL
if SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING) < 0 then
error("Couldn't initialize SDL: "..SDL.SDL_GetError().."\n")
os.exit(1);end
SDL.SDL_WM_SetCaption("X-Fi2 Application Programming", "demo")
display = SDL.SDL_SetVideoMode(400,240, 32, 0) --set window size
if not display then
error("Couldn't set video mode: "..SDL.SDL_GetError().."\n");
end;
end;
--X-Fi2 Emulation functions "screen."
--Creating new tables with sub tables
screen = { drawpixel = self, update = self};
function screen.drawpixel(x,y,pixelcolor)
SDL.SDL_PutPixel(display,x,y,pixelcolor);
end;
function screen.update()
SDL.SDL_UpdateRect(display, 0, 0, 0, 0);
end;
--X-Fi2 Emulation functions "color."
--creating new tables with sub table
color = { new = self };
function color.new(r,g,b)
return SDL.SDL_MapRGB(display.format,r,g,b);
end;
--X-Fi2 Emulation functions "os." creating new sub tables only, os. exist allready.
function os.sleep(z)
SDL.SDL_Delay(z);
end;
--X-Fi2 Emulation function block end.--]]
--Normal creative functions
function putpixel(x,y,pixelcolor)
if (x>399) or (x<0) or (y>239) or (y<0)
then return
else
screen.drawpixel(x,y,pixelcolor);
end;
end;
function clearscreen()
for y=0,239 do
for x=0,399 do
putpixel(x,y,color_black);
end;
end;
screen.update();
end;
--[[ remove remarks to run on luaSDL
init_SDL_screen();
event = SDL.SDL_Event_local();
--]]
--background & forground colors | on LuaSDL init_SDL_screen has to happen before color definition
color_black = color.new(0,0,0);
color_white = color.new(255,255,255);
starcolor = 0;
--star pos range
star_pos_x_min = -700; star_pos_x_max = 700;
star_pos_y_min = -600; star_pos_y_max = 600;
star_pos_z_min = 400; star_pos_z_max = 700;
--Starfield
numberofstars = 250;
centerofscreen_x = 200;
centerofscreen_y = 120;
--tables
starfield = {} ;
star_x={}; star_y ={} ; star_z={}; star_screenx={};star_screeny={};
clearscreen();
-- initiliase tables and populate starfield
for loop=1,numberofstars do
starfield[loop]={ star_x=math.random(star_pos_x_min,star_pos_x_max),
star_y=math.random(star_pos_y_min,star_pos_y_max),
star_z=math.random(star_pos_z_min,star_pos_z_max),
star_screenx=1,star_screeny=1 };
end;
while true do
for i=1,numberofstars do
putpixel(starfield[i].star_screenx, starfield[i].star_screeny,color_black);
starfield[i].star_z = starfield[i].star_z - 5;--speed
starfield[i].star_screenx = starfield[i].star_x / starfield[i].star_z * 50 + centerofscreen_x; --'50'FOV
starfield[i].star_screeny = starfield[i].star_y / starfield[i].star_z * 50 + centerofscreen_y; --'50'FOV
--if outside screen create new star, else draw star
if (starfield[i].star_screenx>399) or (starfield[i].star_screenx<0) or
(starfield[i].star_screeny>239) or (starfield[i].star_z < 1) then
starfield[i].star_x= math.random(star_pos_x_min,star_pos_x_max);
starfield[i].star_y= math.random(star_pos_y_min,star_pos_y_max);
starfield[i].star_z= math.random(star_pos_z_min,star_pos_z_max);
else
starcolor = 500-( starfield[i].star_z*(500/700) );--set star brightness, far=dim close=bright
if starcolor>255 then starcolor=255; end;
putpixel(starfield[i].star_screenx, starfield[i].star_screeny,color.new(starcolor,starcolor,starcolor));
end;
end;
screen.update();
os.sleep(1);
--[hold home button to exit
if (control.read() == 1) and (control.isButton() == 1) and (button.home() == 1) and (button.hold() == 1) then
break;
end;
--]]
--[[
poll=SDL.SDL_PollEvent(event);
local c = event.type
if c == SDL.SDL_KEYDOWN then
local key = event.key.keysym.sym
if key == SDL.SDLK_ESCAPE then
break
end
elseif c == SDL.SDL_QUIT then
break
end
--]]
end;
--remove remark from line below to run on LuaSDL
--SDL.SDL_Quit();
It also looks like around 200 stars in the field is maximum for the cpu power of the X-Fi, in the current environment. Jan_DK |
|
#4
|
||||
|
||||
|
I am currently trying to write a translation tool that uses LuaSDL with an input file written in Zen LUA. That means you write a LUA app like you do on your Zen and you drag it into my translator which translates it and executes the code with Lua SDL.
However, there's nothing to show off yet, sorry. I hope I can offer a download soon. |
|
#5
|
|||
|
|||
|
Can y'all come up with an Application to view "GIF" images? I know it wouldn't make any sense but watching a couple off animations while listening to music would be great.
|
|
#6
|
|||
|
|||
|
Does the Xfi2 play music you've started during applications?
|
|
#7
|
|||
|
|||
|
Yeah it music plays while using apps. Tried it with Boink, Calculator, Sudoku & the TicTacToe app which you programmed.
|
|
#9
|
|||
|
|||
|
Woops sorry! Thanks for reminding I forgot! My bad Zapx64 lol.
Yeah a "GIF" viewer would be great. |
|
#10
|
||||
|
||||
|
Well, a GIF viewer should not be to hard to code since you just need to extract each frame of a gif file and draw it over the last one.
By the way I encountered problems with the translator and I don't think it will ever be completed. But I can see a GIF loading code floating by in front of my eyes...
|
|
#11
|
|||
|
|||
|
It's not as easy as it seems. Since GIF drawing isn't supported we have to code the support for everything, header, color tables, image data, LZW data decompression, etc. The white papers for the format are annoyingly un-user-friendly and don't contain information for the animation part as that's something entirely different.
GIF White Papers http://www.w3.org/Graphics/GIF/spec-gif89a.txt Animation Information http://en.wikipedia.org/wiki/Graphic...#Animated_.gif LZW Data Compression Algorithm http://marknelson.us/1989/10/01/lzw-data-compression/ |
|
#12
|
||||
|
||||
|
Quote:
White papers often look user unfriendly but there's always a hidden source on the internet that says everything you need in a short and clear way. I even coded a Quake 3 BSP loader one year ago (which might as well be possible for the Zen although realtime rendering will not be possible...)
|
|
#13
|
|||
|
|||
|
Well if you find such a hidden source be my guess in sharing =D.
|
|
#14
|
||||
|
||||
|
Here you go: http://www.daubnet.com/en/file-format-gif
|
|
#15
|
|||
|
|||
|
=-O! Where did you find that haha. Nice one!
|
|
#16
|
||||
|
||||
|
What about all the limitations in the current environment?
Please correct me if I'm wrong. The only way right now, to write to the screen, is through the screen.pixel function. (That got to be slow vs. a framebuffer pointer) And the X-Fi2 has not enough memory in the Creative Lua environment, to even allocate a buffer the size of the screen 400x240x3 = 288k ? [1] Maybe any Gif image/animation attempts should start backwards with the memory available, and then calculate how many frames and what size that amounts to. Any thoughts ? [1] I still need to try a 2d array the size 400x240 instead off 0-32768 Jan_DK |
|
#17
|
||||
|
||||
|
I've tried to allocate a screen size buffer using a 2d table, the program stops at around, 157 in the h loop: 157*400*4= 251200
Code:
BUFFER = {} ;
for h=1,240 do
BUFFER[h] = {};
for l=1,400 do
BUFFER[h][l] = 255;
end;
end;
Jan_DK |
|
#18
|
||||
|
||||
|
what about using a lower resolution? if you had an array of 120x200 and when drawing using fillrect for each square. It might be slower but it's worth having a look at, even if its down to only something tiny like 24x40 :P Once little Gif's like that can be displayed it might be easier to work out how to scale it up..
|
|
#19
|
||||
|
||||
|
Another ting just accrued to me, what happens in this code
Code:
io.input("read.txt");
x = io.read("*all");
and what about binary files, can you eg. index x[1] to access the data hmm. some stuff to study and test. another thing if Lua variables are 4bytes floats then the buffer can be used like this maybe. ? BUFFER[h][l] = 0xFFFFFFFF; using the 0xFFFFFFFF still make the loop stop at 157, but right now I don't know if all 4 bytes is stored. Jan_DK |
|
#20
|
||||
|
||||
|
Looks like all four bytes is stored.
when I allocated a single dimension array running 0-n it stopped at 32768 32768 *4 = 128K, now with a too dimensional array it goes to maybe 256K (157*400*4) This code use of all four bytes in the Lua variable, it allocate a buffer the size 240x240*4bytes = 230400 bytes, and fills it with 0xFFFFFF00+ 1,2,3,4 so BUFFER[1][1] = 4294967041 BUFFER[1][2] = 4294967042 Code:
color_black = color.new(0,0,0);
color_white = color.new(255,255,255);
text.color(color_white);
text.size(16);
screen.fillrect(0,0,400,240,color_black);
screen.update();
BUFFER = {} ;
for h=1,240 do
BUFFER[h] = {};
for l=1,240 do
BUFFER[h][l] = 0xFFFFFF00+l;
end;
screen.fillrect(0,0,400,240,color_black);
text.draw(20,20,"BUFFER = "..h );
screen.update();
end;
text.draw(20,50,"BUFFER[1][1] = "..BUFFER[1][1]);
text.draw(20,70,"BUFFER[1][2] = "..BUFFER[1][2]);
text.draw(20,90,"BUFFER[1][3] = "..BUFFER[1][3]);
text.draw(20,110,"BUFFER[100][100] = "..BUFFER[100][100]);
screen.update();
os.sleep(1000);
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 02:14 AM.
















Linear Mode
