Thanks to Leo for fixing up the struct PMCs, I've code that can create a
new SDL window and blit a blue rectangle onto it. Animation's not far
off now!
There are a couple of bugs, however. First, I had to add some C-type
conversion code to classes/unmanagedstruct.pmc. It's almost certainly
wrong, but without it, I wouldn't have gone as far. This may be related
to why it requires r 255, g 0, b 255 to draw a blue rectangle.
I'm not sure UnManagedStruct understands UINT8.
Second, my PIR is undoubtedly funky. Still, the results speak for
themselves.
I've attached my patch to classes/unmanagedstruct.pmc and
src/call_list.txt as well as the library files and my demo PIR.
Enhancements and bug fixes welcome.
Be sure to run this in a directory containing "datatypes.pasm" or else
fix it to find the copy with Parrot (I tried).
-- c
> There are a couple of bugs, however. First, I had to add some C-type
> conversion code to classes/unmanagedstruct.pmc. It's almost certainly
> wrong, but without it, I wouldn't have gone as far.
enum_type_char was already there, uint8 is the same case. Fixed.
> ... This may be related
> to why it requires r 255, g 0, b 255 to draw a blue rectangle.
/Me thinks, that setting colors with the struct doesn't work. I've
change your sample to:
# blue_color = _new_SDL_Color( 255, 255, 255 )
.local int blue
.local int red
.local int green
blue = 255 << 0
red = 255 << 16
green = 255 << 8
Passing one of these colors works fine (SDL_FillRect takes an UInt32
color value, not a pointer to a struct). But it probably should use
SDL_MapRGB() to be endian safe.
> Second, my PIR is undoubtedly funky. Still, the results speak for
> themselves.
Some typos and returning from _init was missing - not too bad :)
> I've attached my patch to classes/unmanagedstruct.pmc and
> src/call_list.txt as well as the library files and my demo PIR.
> Enhancements and bug fixes welcome.
Applied with little fuzz.
> Be sure to run this in a directory containing "datatypes.pasm" or else
> fix it to find the copy with Parrot (I tried).
Such include files are searched in the current dir and in
runtime/parrot/include. If you aren't working inside parrot root,
setting a link helps (on OS that know, what a symlink is ;)
Below is the diff of the sample code (should that get checked in?)
leo
--- /home/lt/blue_rectangle.imc Sat Jan 31 15:18:02 2004
+++ blue_rectangle.imc Sat Jan 31 15:17:36 2004
@@ -10,6 +10,8 @@
.pcc_sub _init prototyped
.include "library/sdl.pasm"
_init_SDL_types()
+ .pcc_begin_return
+ .pcc_end_return
.end
.sub _MAIN
@@ -29,7 +31,6 @@
new_SDL_Rect = global "new_SDL_Rect"
.pcc_begin prototyped
- .arg 255
.arg 65535
.nci_call SDL_Init
.pcc_end
@@ -37,20 +38,26 @@
.pcc_begin prototyped
.arg 640
.arg 480
- .arg 16
+ .arg 0
.arg 0
.nci_call SetVideoMode
.result screen
.pcc_end
.local object blue_rect
- .local object blue_color
- .local Sub new_rect
- .local Sub new_color
- .local Sub update_rect
+ #.local object blue_color
blue_rect = _new_SDL_Rect()
- blue_color = _new_SDL_Color( 255, 0, 255 )
+ # blue_color = _new_SDL_Color( 255, 255, 255 )
+ .local int blue
+ .local int red
+ .local int green
+ blue = 255 << 0
+ red = 255 << 16
+ green = 255 << 8
+ print "blue = "
+ print blue
+ print "\n"
set blue_rect['w'], 100
set blue_rect['h'], 100
@@ -60,10 +67,13 @@
.pcc_begin prototyped
.arg screen
.arg blue_rect
- .arg blue_color
+ .arg blue
.nci_call SDL_FillRect
+ .local int ok
+ .result ok
.pcc_end
+ # update full screen (all 0 arguments)
.pcc_begin prototyped
.arg screen
.arg 0
@@ -73,8 +83,7 @@
.nci_call SDL_UpdateRect
.pcc_end
- set $I0, 2
- sleep $I0
+ sleep 2
.pcc_begin prototyped
.nci_call SDL_Quit
> /Me thinks, that setting colors with the struct doesn't work. I've
> change your sample to:
>
> # blue_color = _new_SDL_Color( 255, 255, 255 )
> .local int blue
> .local int red
> .local int green
> blue = 255 << 0
> red = 255 << 16
> green = 255 << 8
>
> Passing one of these colors works fine (SDL_FillRect takes an UInt32
> color value, not a pointer to a struct). But it probably should use
> SDL_MapRGB() to be endian safe.
Oh right, that was from my previous attempt. I've fixed _new_SDL_Color
to handle this appropriately.
> Below is the diff of the sample code (should that get checked in?)
How about examples/pni/sdl_blue_rectangle.imc? I'm about five minutes
from having animated rectangles. Then it's on to keypresses.
-- c
Thanks
Alb
chromatic wrote:
> On Mon, 2004-02-02 at 07:57, Leopold Toetsch wrote:
>
>
>>>How about examples/pni/sdl_blue_rectangle.imc?
>>
>>Done.
>
>
> I have a couple of other examples now; should I check them in here? In
> particular, I have image animation and will shortly have examples of
> reading input with SDL.
>
> -- c
>
Alberto
Dan Sugalski wrote:
> At 5:13 PM +0000 2/2/04, Alberto Manuel Brandão Simões wrote:
>
>> I have been shooted with spam, and didn't notice this thread :-)
>> Does this means that parrot already binds/links to external libraries?
>
>
> Yup, has for quite a while. Take a look at the library/ncurses.pasm and
> library/postgres.pasm files for a couple of examples.
Yup, has for quite a while. Take a look at the
library/ncurses.pasm and library/postgres.pasm
files for a couple of examples.
>chromatic wrote:
>>On Mon, 2004-02-02 at 07:57, Leopold Toetsch wrote:
>>
>>>>How about examples/pni/sdl_blue_rectangle.imc?
>>>
>>>Done.
>>
>>
>>I have a couple of other examples now; should I check them in here? In
>>particular, I have image animation and will shortly have examples of
>>reading input with SDL.
>>
>>-- c
--
Dan
--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk
> > How about examples/pni/sdl_blue_rectangle.imc?
> Done.
I have a couple of other examples now; should I check them in here? In
>> > How about examples/pni/sdl_blue_rectangle.imc?
>> Done.
If you got more examples (good) I'd suggest to put these in a distinct
subdirectory.
> -- c
leo
> If you got more examples (good) I'd suggest to put these in a distinct
> subdirectory.
Do you prefer examples/pni/sdl/ or examples/sdl/ or something else?
Also, I have one 6k binary file for one example. Is that okay to check
in?
-- c
examples/sdl would probably be best. We can get more hierarchical at
some point later if we need to.
>Also, I have one 6k binary file for one example. Is that okay to check
>in?
Yeah, go ahead.
> examples/sdl would probably be best. We can get more hierarchical at
> some point later if we need to.
>
> Yeah, go ahead.
Okay, done. We can now load and animate simple images with SDL.
(Actually, anyone can, as there's documentation and example code.) I'll
add input events next.
-- c