MonkeyPro63 now up! [MONKEY NEWS]

Monkey Forums/Monkey Programming/MonkeyPro63 now up! [MONKEY NEWS]

marksibly(Posted 2012) [#1]
Hi,

MonkeyPro63 is now up complete with new pixel read/write functions:

'create a new image...single frame only?
Function CreateImage:Image( width,height,flags )

'read from 'backbuffer'...
Function ReadPixels:Void( pixels:Int[], x:Int, y:Int, width:Int, height:Int,arrayOffset:Int=0, arrayPitch:Int=0 )

'write to image...must be a CreateImage image.
Method Image.WritePixels( pixels:Int[], x:Int, y:Int, width:Int, height:Int, arrayOffset:Int=0, arrayPitch:Int=0 )




Modules:

mojo.graphics - Added CreateImage, ReadPixels, Image.WritePixels.

android mojo.graphics - Fixed ancient 'textures doesn't render first time' bug!


Trans (V1.39)

Removed pss target.




MikeHart(Posted 2012) [#2]
Why was the pss target removed?


MikeHart(Posted 2012) [#3]
And thanks for the read/write pixel functions.


Grey Alien(Posted 2012) [#4]
Sounds cool. Is this like a manual render to texture then?


AdamRedwoods(Posted 2012) [#5]
sexy. might be time to do some ray-tracing.

pss was removed since sony renamed it to psm. same thing.


Samah(Posted 2012) [#6]
Updated monkey-ext to v63, although the only real change was removing the pss target and updating the trans version number, since Mojo is not part of monkey-ext.


impixi(Posted 2012) [#7]
Thanks. Those pixel operations seem to work well in HTML5 (IE9 and Chrome).


MikeHart(Posted 2012) [#8]
Oh, I wasn't aware that we had the PSM and PSS target already. That makes sence to remove the PSS target.


Neuro(Posted 2012) [#9]
Edit : nevermind nevermind...wow tonight is just sucking for me lol


KaaPex(Posted 2012) [#10]
Been waiting for. Thank you for this functional.


CodeGit(Posted 2012) [#11]
WOW...thanks Mark.


Rumphiz(Posted 2012) [#12]
These new functions are very handy thanks.

Not quite sure I understand how to use them though, a small example would be great.


therevills(Posted 2012) [#13]
Quick example, which draws a player and applies a mask colour (black) so it has alpha:




MikeHart(Posted 2012) [#14]
Arggghhh. Monkey is not that portable with TED anymore. Needs a certain Microsoft DLL (MSVCP100.DLL) to work which my work computer has not installed. Hopefully it will work once I copy that DLL at home into the folder were ted.exe is in.


jondecker76(Posted 2012) [#15]
Yep, same here with the MSVCR100.dll and MSVCP100.dll on my work computer - looks like I won't get to play today!


golomp(Posted 2012) [#16]
My god ! Thank you a lot Mark !


jondecker76(Posted 2012) [#17]
Perhaps we'll be seeing some dynamic image loading soon now :) Its the only thing keeping me from using monkey for my web design work!


Skn3(Posted 2012) [#18]
This is brilliant that monkey is getting the ability to manipulate some pixels but there is one major flaw with the implementation. It is not possible to use the backbuffer or any drawing operations outside of OnRender. Essentially you are going to have to be doing a game "update" inside the render method, which is a bit counter-intuitive.

So this is not currently possible:
Import mojo

Function Main()
	New Game
End

Class Game Extends App
	Field land:Image
	
	Method OnCreate()
		'create land image buffer
		land = CreateImage(320, 240)
		
		'generate new land
		GenerateLand()
	End
	
	Method OnUpdate()
		
	End
	
	Method OnRender()
		Cls(0, 0, 0)
		DrawImage(land, 0, 0)
	End
	
	Method GenerateLand()
		Local pixels:Int[320 * 240]
		land.WritePixels(pixels, 0, 0, 320, 240)
	End Method
End



vbnz(Posted 2012) [#19]
Thanks Mark for this feature and for the fast update!!!

Sincerely, vbnz.


Sub_Zero(Posted 2012) [#20]
Good Work... more power to monkey


Samah(Posted 2012) [#21]
Realtime image filtering!



Notice the FPS... ;D


Skn3(Posted 2012) [#22]
haha brilliant!


Nobuyuki(Posted 2012) [#23]
sweeet feature. Fast enough to do big pixel operations? Only one way to find out! I'm excited 8D

great job !


Pierrou(Posted 2012) [#24]
Hi,

Thanks for the update!

Sorry for being an absolute beginner but does that mean we could expect something like the SavePixmap command we had in BlitzMax in the future, or not at all?


slenkar(Posted 2012) [#25]
does this mean i can draw some images to an image?

also in the example createimage seems to have more argument than
( width:Int, height:Int, flags:Int=image.defaultflags )

img=CreateImage(w,h,1,Image.MidHandle)

what does the 1 mean?

and in the demo, does this code change the colours?
For Local i:=0 Until w*h*2
If i<w*h*2/3
buf[i]|=$ff0000
Else If i<w*h*4/3
buf[i]|=$00ff00
Else
buf[i]|=$0000ff
Endif
Next

For Local i=0 Until h
For Local j=0 Until w*2
buf[i*w*2+j]=buf[i*w*2+j] & $ffffff | (i*255/h) Shl 24
Next
Next



benmc(Posted 2012) [#26]
The 1 typically refers to frames. Does CreateImage have frames?


marksibly(Posted 2012) [#27]
Hi,

> Yep, same here with the MSVCR100.dll and MSVCP100.dll on my work computer - looks like I won't get to play today!

These made it into the new demo, just not the main release (next time). You should be able to copy these in from the demo 'bin' directory.

> Essentially you are going to have to be doing a game "update" inside the render method, which is a bit counter-intuitive.

Actually, you should be able to safely use Image.WritePixels outside OnRender(), just not ReadPixels - sort of like LoadImage. But yeah, the limitations on when you can render are a bit of a bummer. These are mainly due to android and xna, I'll have a poke around but I'm not sure there's anything I can do.

> also in the example createimage seems to have more argument than
( width:Int, height:Int, flags:Int=image.defaultflags )

Ah yes, that's 'frameCount' - set to '1' for now!


therevills(Posted 2012) [#28]
Any chance in the future could we have: image.ReadPixels?


dawlane(Posted 2012) [#29]
Any chance in the future code we have: image.ReadPixels?

I would like that too and a way to change the file outputs from the default MonkeyGame/.monkeystate please.


invaderJim(Posted 2012) [#30]
Any chance in the future could we have: image.ReadPixels?


I'm sure Mark's gonna implement this eventually, but I am just the PSM target away from having a GetImagePixels() function working.

I will post the module here as soon as I'm finished.


therevills(Posted 2012) [#31]
Pixel perfect collisions example using the new commands :)

http://www.monkeycoder.co.nz/Community/posts.php?topic=3488


invaderJim(Posted 2012) [#32]
Well, I've lost the fight against the PSM target.. for now. A nice, simple solution doesn't seem plausible, but I'm not too familiar with the API at all.

All of the other targets appear to be working.

It's usage is something like this:

[monkeycode]
Local pixels:Int[] = GetImagePixels(image, x, y, width, height)
[/monkeycode]

And I've included a test project that looks like this:

[monkeycode]
Import mojo

Import imagesextended

Class GetPixelsTest Extends App
Field firstRender:Bool = True
Field drawThing:Bool = False

Field img:Image
Field newImg:Image
Field pixels:Int[]

Method OnCreate()
SetUpdateRate(60)

img = LoadImage("numbers.png")

newImg = CreateImage(128, 128)
End

Method OnUpdate()
If KeyHit(KEY_SPACE) Or KeyHit(KEY_LMB)
drawThing = True
End
End

Method OnRender()
Cls(110, 110, 110)

If firstRender
' I've thrown it in the render cycle here to ensure that the image is loaded, for HTML5.
pixels = GetImagePixels(img, 0, 0, 24, 24)

firstRender = False
End

If drawThing

' I've wrapped Image.WritePixels to prevent nasty errors from drawing outside the image
WriteImagePixels(newImg, pixels, Rnd(128), Rnd(128), 24, 24)

drawThing = False
End

DrawImage(newImg, 200, 200)
End
End


Function Main()
New GetPixelsTest()
End
[/monkeycode]

And you can download the module here.

Enjoy!

-Jim


Anatol(Posted 2012) [#33]
Hi,

something ugly is going on with images that have an alpha channel - and only when you change the colour. SetColor(255, 255, 255) looks as it should.

Here's the code:
Strict

Import mojo

Function Main:Int()
	New TestApp
	Return 0
End

Class TestApp Extends App
	
	Field testImage:Image
	
	Method OnCreate:Int()
		SetUpdateRate(60)
		testImage = LoadImage("imageWithAlphaTest.png")
		Return 0
	End
	
	Method OnRender:Int()
		Cls(255,255,255)
		SetColor(255,0,0)
		DrawImage(testImage, 50, 100)
		
		SetColor(255,255,255)
		DrawImage(testImage, 350, 100)
		Return 0
	End
	
End


Result in Monkey v63 (HTML5):


To compare, result in Monkey v62:


Looks like a bug.


marksibly(Posted 2012) [#34]
Hi,

> something ugly is going on with images that have an alpha channel - and only when you change the colour. SetColor(255, 255, 255) looks as it should.

Just posted a v63b with a fix for this.


Anatol(Posted 2012) [#35]
Great, thanks for the quick update! It works perfectly now.


therevills(Posted 2012) [#36]
Just posted a v63b with a fix for this.

You might want to update the demo again, Mark ;)


AaronK(Posted 2012) [#37]
Hi guys. Just upgraded to 63b and am getting these errors:

2012-08-21 21:49:03.824 xcodebuild[11548:5303] DVTAssertions: Warning in /SourceCache/IDEXcode3ProjectSupport/IDEXcode3ProjectSupport-1559/Xcode3Sources/XcodeIDE/Frameworks/DevToolsBase/pbxcore/SpecificationTypes/XCGccMakefileDependencies.m:87

../glfw/lib/internal.h:58:10: fatal error: 'stdlib.h' file not found
#include <stdlib.h>


I'm using XCode 4.4.1


Samah(Posted 2012) [#38]
AaronK: Did you delete your build directory?


NoOdle(Posted 2012) [#39]
AaronK: Have you installed command line tools? I had to do this before I could compile v63. In Xcode goto XCode->Preferences->Downloads and click on this install button.


Landon(Posted 2012) [#40]
SQUEEEE!! now i can finish my html5 cardgame.


slenkar(Posted 2012) [#41]
Trans seems quite a bit faster - just my imagination?


MikeHart(Posted 2012) [#42]
Yes, much faster here too.


Samah(Posted 2012) [#43]
That's interesting given that the only change to trans since v61b is the version number...


golomp(Posted 2012) [#44]
@Samah
Maybe due to binary representation of version number ?
:)


MikeHart(Posted 2012) [#45]
Maybe the console communication between TED/Trans is faster than Monk/Trans?


Samah(Posted 2012) [#46]
@MikeHart: Maybe the console communication between TED/Trans is faster than Monk/Trans?

This is more likely. I use Jungle, so I couldn't comment. :/

golomp: Maybe due to binary representation of version number ?

Actually, the version number is stored as a string.


BlitzProg(Posted 2012) [#47]
This is going to benefit to my lastest apps. Greatly.

Before (Blocky shadows):


After (Filtered shadows):


(Made using a 22x18 image then scaling 32x)


BlitzProg(Posted 2012) [#48]
doublepost, sorry
Edit: Oh, and the 2nd was run in debug ^_^ in release, frame render is 14ms

Rendering something scaled takes a lot of time. I got to check about flash and android, tho.

Edit2: Actually, firefox is really slow at drawing scaled up images; been trying with chrome and the frame render time drops to only 8ms (from 13), and flash also gains the same speed up.

I love this update!


Shanon(Posted 2012) [#49]
BlitzProg, for some reason I think the blocky version looks cuter!


Grant(Posted 2012) [#50]
I'm having trouble with the new WritePixels method, basically I just want to draw to a blank image. but how do I go about specifying a colour as a single integer? the examples so far seem to only deal with modification of a grabbed image. and shifting bits.

I would be very grateful if someone could post a very 'simple' strict example of a flood fill with random colours in a for next loop using CreateImage instead of modifying a grabbed image. just to let me see how its done, as I'm currently pulling my hair out.

many thanks, grant.

It's cool, I sussed it out :D
/me blames old age!


NoOdle(Posted 2012) [#51]
I'm having trouble with the new WritePixels method, basically I just want to draw to a blank image. but how do I go about specifying a colour as a single integer?

[monkeycode]
Local argb : Int = ( alpha Shl 24 ) | ( red Shl 16 ) | ( green Shl 8 ) | blue
[/monkeycode]
where alpha, red, green and blue are integers in the range 0 - 255. Setting the pixels to the argb value will produce a colour of your choosing. Hope this helps


Grant(Posted 2012) [#52]
Thanks man, I just sussed that out before I noticed your speedy reply.

what a community! now to render my metaballs with pixels instead of DrawRects()!


Grant(Posted 2012) [#53]
Hmmm, Everything seems to work as its supposed to, only the android performance seems unusually slow compared to html5, usually its android being faster than html5 for me, but this time html is leaving android standing when using write pixels, not just a little slower, painfully slower to the point of being useless for anything in real time on android.

my excitement is shot down in flames for the moment :(

has anyone else experienced this?


teremochek(Posted 2012) [#54]
android on my game does not work.

The application Electromon 
(process com.terem.electromon) 
has stopped unexpectrdly.
Please try again.