About Monkey 2 › Forums › Monkey 2 Programming Help › Texturemapping wrap with Drawprimitives() ?
This topic contains 2 replies, has 2 voices, and was last updated by
Diffrenzy
2 years ago.
-
AuthorPosts
-
April 7, 2017 at 12:54 pm #7759
How do I set the TextureFlags on an Image?
Specifically, I want to make my texture wrap, when using DrawPrimitives()
I know it’s in there…
:
Monkey123456789101112Enum TextureFlagsWrapS= $0001 'wrap works, but hidden for now...WrapT= $0002Unmanaged= $0004DisableMipmap= $0008RenderTarget= $0010WrapST= WrapS|WrapTDynamic= Unmanaged|RenderTarget|DisableMipmapEndApril 7, 2017 at 8:31 pm #7764Monkey12345678910111213141516Function LoadImageWithFlags:Image(path:String, flags:TextureFlags, shader:Shader=Null)Local pixmap:= Pixmap.Load(path, Null, True)If Not pixmap Return NullIf Not shader shader = mojo.graphics.Shader.GetShader("sprite")Local image:= New Image(pixmap, flags, shader)image.OnDiscarded += Lambda()pixmap.Discard()EndReturn imageEndLocal myImage:= LoadImageWithFlags("myImage.png", TextureFlags.WrapST)You should be able to do something like this (slightly modified from Image.Load). Dunno why it doesn’t accept flags for wrap in the first place. Most of the other possible flags aren’t useful in the case of just dealing with the high-level Image class instead of writing your own rendering code, I suppose.
Anyway, if you make an image like that, you should be able to use it with DrawPrimitives. I didn’t test any of that though, so sorry if it throws any complex errors.
EDIT: I guess to clarify – an Image is a wrapper around an internal Texture, which is normally created when you create the Image. The flags that would make your texture wrap need to be passed in at the time when you create that Texture. Since you’re probably loading your Image from file, you unfortunately don’t have a way to pass flags like that in normally. This code handles that for you.
April 12, 2017 at 6:12 pm #7875Perfect! Thanks sicilica, works at advertised
Mark: is it possiple to add a way to just set the flag at runtime, after loading?
myimg.Textureflags(n,flags) or something…OR maybe specifying them when calling DrawPrimitives()?
Here is your sicilicas function changed to CreateImage, if someone needs it:
Monkey1234567891011121314Function CreateImageWithFlags:Image(w:Int ,h:int, flags:TextureFlags, shader:Shader=Null)Local pixmap:= New Pixmap(w,h)If Not pixmap Return NullIf Not shader shader = mojo.graphics.Shader.GetShader("sprite")Local image:= New Image(pixmap, flags, shader)image.OnDiscarded += Lambda()pixmap.Discard()EndReturn imageEnd -
AuthorPosts
You must be logged in to reply to this topic.