Forum Replies Created
-
AuthorPosts
-
My work here is done…
Excellent, the shaders are looking really great too!
I have long wanted to add some kind of ‘full screen 2d shader effect’ API to the mojo view system, but have been reluctant to do this as I’d be more or less ‘guessing’ how people wanted to use it (like 90% of what I do I guess) and it would likely end up cumbersome and nasty.
But seeing what people are actually wanting to do with shaders and how they want to use them is enormously useful and will hopefully make for some interesting mojo additions one of these days!
What can I run/test that’s crashing?
Recent shader changes shouldn’t be affecting existing code.
That’s the web site I linked!
That’ll teach me to skim read before coffee at 7.00 am…
And the wchar stuff isn’t all that complex to implement, you just need to be really careful of 2 huge C bogey-men – buffer over-runs and memory leaks!
“just convert to/from WCHAR” only at the point where the Win32 API requires it
This is the basic idea but it’s not trivial!
I should have it mostly done now though – just pushed to develop branch so feel free to check it out.
There is also a minor chance that I’ve borked something in the process, as this stuff is used in lots of places. Ted2go is a pretty good test of libc/filesystem stuff and that seems to be going OK but still…use with caution.
Also found this in the process:
A pretty good read on all the issues, and I agree with about 97% of it I think…
What is String type under the hood? Is it utf-8 string?
No, it’s an internal custom 16 bit per char format.
Is it ok that LoadString/SaveString using CString instead of WString?
CString means ‘utf-8’ encoded null terminated string, so yes. WString is not really technically supported yet.
I tried to use russian letters for window title and I got abrakadabra when app started.
But if I load the same letters from file – everything is OK.
Not really sure what you mean here. Please post some sample code if you want me to look at something! This is especially important if international characters are involved as randomly copying and pasting stuff from google in an attempt to try to duplicate problems like this can only get me so far.
To clarify a bit on the whole windows+utf mess: The problem is typically with API calls where you have to pass a filename or something ‘visible’ (eg: window title) to an OS function.
All OS’s except windows accept utf-8 cstrings (ie: monkey2 CStrings) for filenames etc which are (conveniently, by design) backward compatible with plain ascii, and are fully handled by monkey2. When a monkey2 string is converted to a CString all information retained as its in utf-8 encoding.
However, windows requires you to use entirely different APIS if you want to use filenames etc that aren’t plain 7 bit ascii. Monkey2 doesn’t use such APIs yet, so non-ascii chars in filenames etc will cause problems, as monkey2 will still convert to utf-8 cstrings (which are still valid c strings, windows just doesn’t know how to deal with them properly).
These different APIs uses yet another string type – a WSTRING – which is very close to what monkey2 currently uses internally (although that could change) but needs to be null terminated etc. Note that there is also a c++ std::wstring which is similar to WSTRING but only on some targets. Fun stuff.
I already include Assets the whole directory?
You need to prefix file name with “asset::” when you load it, eg: Image.Load( “asset::32x32sheet.png” ).
For texture flags, always use TextureFlags.Dynamic for an image you’re updating frequently (I added some of these I think).
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105Namespace Myapp#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"#Import "assets/"Using std..Using mojo..Const w:=800, h:=600Class Myapp Extends WindowField canvas:CanvasField icanvas:CanvasField scanvas:CanvasField image:ImageField sourceImage:ImageField targetImage:ImageField size:Int=16 ' try 8 16 32 64Field cx:IntField wx:IntField wy:IntField tilemap:=New Int[512*512]Field s:Int = 4Method New()Super.New("Myapp", w, h, WindowFlags.Resizable)For Local y:=0 To 511For Local x:=0 To 511tilemap[x + y * 512] = Int(Rnd(127))NextNextsourceImage=Image.Load( "asset::32x32sheet.png",Null,Null )targetImage=New Image( sourceImage.Width,sourceImage.Height,PixelFormat.RGBA8,TextureFlags.Dynamic )image=New Image( 512,512,PixelFormat.RGBA8,TextureFlags.Dynamic )icanvas=New Canvas(image)scanvas=New Canvas(targetImage)' canvas=New Canvas() NOT NEEDED IN MONKEY2 ' image.Texture.Flags &=~ TextureFlags.FilterMipmapEnd' ---------------------------------------------------------------------------------------Method OnRender( canvas:Canvas ) OverrideApp.RequestRender()' canvas.Alpha=1.0scanvas.Clear(Color.Black) ' INSTEAD OF SHADER (just copies sourceImage to targetImage)scanvas.DrawImage(sourceImage,0,0) ' INSTEAD OF SHADER (just copies sourceImage to targetImage)scanvas.Flush() ' INSTEAD OF SHADER (just copies sourceImage to targetImage)' Init canvas & image'canvas.Viewport(0,0,w,h)'canvas.Scissor(0,0,w,h)'canvas.Projection2d(0,w,0,h)canvas.Clear(Color.None)'icanvas.Viewport(0,0,w,h)'icanvas.Scissor(0,0,w,h)'icanvas.Projection2d(0,w,0,h)icanvas.Clear(Color.None)' Draw to image' Scroll (by drawing onto itself)icanvas.Clear(Color.Black)icanvas.DrawImage(sourceImage,0,0)icanvas.DrawImage(targetImage,256,256)cx=(cx+2) Mod 512For Local temp:=0 To 127icanvas.DrawRect(64+temp,0,1,64,targetImage,0+temp+cx,0,1,64)Next' Plots something in the tiles (shows how to draw something to an image *after* shader have been applied)For Local temp:=1 To 16If Int(Rnd(1)) Then icanvas.Color = Color.Black Else icanvas.Color = Color.WhiteLocal xx:= Int(Rnd(7))Local yy:= Int(Rnd(7))icanvas.DrawRect(xx*4,yy*4,2*4,2*4)Nexticanvas.Flush() ' Finished drawing' Draw to canvas' Cookiecut 32x32 tiles from a 512x512 tilesheet and draw as tiles of any sizeLocal scrx:=wx Mod sizeLocal scry:=wy Mod sizeLocal mapx:=wx / sizeLocal mapy:=wy / sizeLocal cnty:= -scryFor Local y:=mapy To mapy+((h/size)+1)Local cntx:=-scrxFor Local x:=mapx To mapx+((w/size)+1)Local char:= tilemap[x + y * 512]Local tilex:= char & 15Local tiley:= char Shr 4canvas.DrawRect(cntx,cnty,size,size,image,tilex Shl 5,tiley Shl 5,32,32)cntx=cntx+sizeNextcnty=cnty+sizeNextcanvas.Flush() ' Finished drawingIf Keyboard.KeyReleased(Key.Escape) Then App.Terminate()End MethodEndFunction Main()New AppInstanceNew MyappApp.Run()End FunctionTry building with debug on. You’re missing a ‘=New Int[512,512]’ and an “asset::blah.png”.
With these fixed I get a smooth scrolling sort of parallax charmap, with random chars all over the place, some sort of animated! Both monkey2 and monkeyx versions look the same to me.
It could be anything – it could be the fact that monkey2 really uses direct3d, whereas monkey-x uses ‘pure’ opengl, it could be the way I uploaded textures to the driver, the order of API operations I use, whatever…the point is it’s invalid so don’t do it.
Drawing an image that you’ve just draw an image to is expansive in Monkey2.
If you have some runnable sample code, please post it, but nothing that uses undefined or invalid behaviour please!
[edit]You may be right, there may be some sort of issue here, but testing with invalid code is not the right way to find it.
Ok, that’s pretty hard to follow, but as far as I can tell you’re trying to draw a texture onto itself, ie: you’re drawing ‘image’ to an ‘icanvas’, where icanvas has the same image as a render target. Please correct me if I’m wrong here…
Anyway, you can’t do this – it’s technically ‘undefined behaviour’ in opengl/gles/webgl and I’m surprised it works at all!
If you want to do stuff like this, you need to double buffer, ie: have 2 images/icanvses, and draw image0->icanvas1 and image1->icanvas0 etc and flip between them.
Still not quite sure what you mean here…could you try and explain the problem a bit more clearly.
I assume it’s speed related as there’s mention of snails in there, and that it’s something to do with drawing images to images but beyond that…?
Ideally, some nice simple runnable monkey2 code with a clear description of the ‘symptoms’ would be ideal!
Here’s a little demo of manually drawing letterbox borders yourself.
This allows you to turn of windows clearing so there is 0 overdraw, I’m not sure it’ll be significantly faster, or even any faster at all as window clearing should be pretty fast. But it’s still nice to be able to customize letterbox borders…
If it is significantly faster, it’s probably worth adding an option similar to Window.ClearEnabled to automate it.
It uses the currently undocumented View.RenderBounds property, but it should be pretty obvious what this does, ie: it’s the view ‘bounds’ in windows coordinates. View bounds is view rect + padding + border + margin.
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class GameView Extends ViewMethod New()Layout="letterbox"EndMethod OnRender( canvas:Canvas ) OverrideRequestRender()canvas.Clear( Color.Blue )canvas.DrawText( "Hello World!",Width/2,Height/2,.5,.5 )EndMethod OnMeasure:Vec2i() OverrideReturn New Vec2i( 320,200 )EndEndClass MyWindow Extends WindowMethod New()Super.New( "VRES test",640,480,WindowFlags.Resizable )Local gameView:=New GameViewContentView=gameViewClearEnabled=FalseEndMethod OnRender( canvas:Canvas ) OverrideLocal rect:=ContentView.RenderBoundscanvas.Color=Color.Red'left border?If rect.Left canvas.DrawRect( 0,0,rect.Left,Height )'right border?If rect.Right<Width canvas.DrawRect( rect.Right,0,Width-rect.Right,Height )'top border?If rect.Top canvas.DrawRect( 0,0,Width,rect.Top )'bottom border?If rect.Bottom<Height canvas.DrawRect( 0,rect.Bottom,Width,Height-rect.Bottom )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndBasically, the libc module (and more…) needs to be rewritten for Windows to use the ‘wide char’ versions of various OS filesystem APIs.
This is not a problem on any other OSes because they all very sensibly use utf-8 c strings for all APIs, which is backwardly compatible with old school ascii and means I can use ‘standard c’ APIs everywhere – except Windows!
It’ll happen eventually…
that well-decorated site
Ha! You mean the xmas lights? They were the painstaking result of a 2 minute google image search!
I’ll see if I can’t knock something together for here…
Meh, each to their own…locking this now as it’s not really achieving anything.
-
AuthorPosts