Mojo2 SetColor Alias
Monkey Forums/Monkey Programming/Mojo2 SetColor Alias
| ||
Hi all, I understand you can do function alias' so I would like to make it so SetColor(Int,Int,Int) maps to Function MySetColor(r:Int,g:Int,b:Int) canvas.SetColor(Float(r)/255.0,Float(g)/255.0,Float(b)/255.0 End Is that doable? |
| ||
Yes But when you want to set the colour of a drawing operation involving another canvas? At this point pass this parameter. You could even do this Function SetColor:Int(gc:Canvas,r:Int,g:Int,b:Int) gc.SetColor(Float(r)/255.0,Float(g)/255.0,Float(b)/255.0) Return 0 End |
| ||
Cheers degac, I'm using a SetCanvas() function to set the relevant canvas before doing any drawing functions but I'm struggling with the alias part |
| ||
So you want to wrap mojo2 in Blitz3d-style function? The old 'SetBuffer' is back! I just tested, and you can write your own SetColor(r,g,b) function that overload everything else Function SetColor:Int(r:Int,g:Int,b:Int) _currentCanvas.SetColor(Float(r)/255.0,Float(g)/255.0,Float(b)/255.0) Return 0 End assuming _currentCanvas is the one set via SetCanvas() TBH I would like to see (I will write myself probably!) - like in BMax- some 'wrapping' function, like DrawImageRect, DrawSubImageRect... at the moment you must use DrawRect() and check what syntax use. |
| ||
Nice one thank you. I've no idea why I didn't just write an actual SetColor() function.... I think I was trying to hard to see an issue that wasn't there! I've just had some fun sorting lots of drawing commands, I'm not going mad am I? It's not possible to do Image.MidHandle with Mojo2 is it? I see DrawImageRect needs some sort of manual creation as well |
| ||
Hi It seems you need to play with the Matrix command to use rotation with DrawRect You need to use an image, the size of my image was 128x128 pixels (so -64,-64 is the 'center' from the upper-left corner of the 'rect'). Please note that I'm a beginner too, so many graphics feature in mojo2 are completely new (or unknow - like Material?) |
| ||
This is a version with an hacked DrawRect The function simulates/includes the rotation/matrix commands... of course it's no an efficient way to do things I suppose. |
| ||
@Raz: Mojo 2 has handles, like Mojo. They just aren't handled with a flag for mid-handling. Because mid-handling was so common, it is now the default. The 'Image.Load' and 'Image.LoadFrames' commands both have handle-arguments (Ratios; 0.0 to 1.0) before they take in flags. Flags now have a very different purpose; they're used for filtering, context-safety, and mip-mapping. From what I understand, the 'DrawRect' overloads that take in 'Images' are specifically set up to not use handles. So, that's why you'd need to do what Degac is doing. @degac: I'm not a complete expert, but I can at least answer some of your questions. For example, Mojo 2's 'Material' system is basically a way of grouping textures. They can have different textures depending on the shader used, allowing you to pass things like bump-maps. 'Image' objects now simply describe an area in a 'Material'. The normal "image" you load from the device is contained by the 'Material' as 'ColorTexture', and is used for things like the 'Width' and 'Height' properties. And of course, it's used to draw the main image you loaded. 'Textures' are now simply resources that reference texture handles in the OpenGL context. Previously, this was done using a private 'Surface' class. With Mojo 2, this is all available for you to manage as you see fit. So, 'Images' describe an area of a 'Material', and 'Materials' hold 'Textures', which represent textures on the graphics card. |
| ||
@ImmutableOctet: thanks for the explanation, very simple but clear. I suppose Material are usuful when using shaders. |
| ||
@Raz: Though it's probably not as useful now, I put together this experimental module. It should be an okay reference for what is equivalent in Mojo 2. I advise against actually using the module, considering how inefficient it currently is. Mojo 1's built-in fonts are especially not handled efficiently by that. Still, I can get the examples running with it, so that's something. It could be useful later on for giving existing games WebGL, or shader support. |
| ||
Oh nice one, thanks will give it a go :) |