android
Prev Previous Post   Next Post Next
  #1  
Old 12-22-2009, 01:35 PM
Jan_DK's Avatar
Jan_DK Jan_DK is offline
Junior Member
 
Join Date: Mar 2009
Location: Denmark
Posts: 88
Default 'Offline' Application development -Windows : LuaSDL

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
Planets[1]: The original Basic code for the function 'planets' comes from the book
Creative Graphics on the BBC Microcomputer by John Cownie.
http://members.aon.at/~musher/bbc/library.htm
- 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
Reply With Quote

Advertisement [Remove Advertisement]

 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 07:08 PM.