Functions to set image UV
BlitzMax Forums/BlitzMax Module Tweaks/Functions to set image UV
| ||
Some additions to the 2D modules so that you can set image and image frame UV's nice and easy. This works with DX7 and OpenGL. driver.bmx : Line 30 Add this : Method SetUV(u0#,v0#,u1#,v1#) Abstract max2d.bmx : Line 531 Add this : Function SetUV(image:TImage,u0#,v0#,u1#,v1#,frame=0) image.Frame(frame).SetUV u0,v0,u1,v1 End Function glmax2d.bmx : Line 159 Add this : Method SetUV(u0#,v0#,u1#,v1#) self.u0 = u0 self.v0 = v0 self.u1 = u1 self.v1 = v1 End Method Now makemods. Example :- Graphics 640,480,0 SetClsColor 255,255,255 Cls Local base:Timage = LoadImage("progress_ol.png") Local u0# = 0 Local v0# = 0 Local u1# = 0.5 Local v1# = 1 Local frame:Byte = 0 SetUV(base,u0#,v0#,u1#,v1#,frame) DrawImage(base,0,0) Flip WaitKey() |
| ||
Are u0 and v0 the bottom left point of the quad or the top left? |
| ||
Is it possible to rotate UV ? |
| ||
Since UV are just co-ords it's possible to give them any position. Remeber UV extend from 0 to 1. |
| ||
Right. But the method only sets it for two points and I don't know which they are. |
| ||
ok, you are correct... This will only do rectangler UV.. if you want to set more then perhaps Mark could include this as a new function in the next release. |
| ||
Hopefully mark will add this to the official modules :-) Is a great thing and I think many "advanced" programmers already hacked the modules this way for their usage anyway ... I've created a function that works as the old DrawImageRect Just put it in its own file and import it. edit: added to code archives for simpler refinding |
| ||
I always hated the stupid 0 to 1 thing. My idea for a new command would be: DrawImagePart tImage,DestX,DestY,SourceX,SourceY,Width,Height That would be so sweet. |
| ||
see the function I added to the codearchives (DrawImageArea), its exactly your command but with a ,frame after (which has default 0 ;)) |
| ||
I got this all to work, and it's great, but just out of curiousity is there anyway to do the samething without modifying the original MODS? I ask because as I start to change all the mods, won't new ones come from BRL and overwrite my changes then I have to do them all over? |
| ||
Mine doesn't hack the mods. It just uses their internal structure as I had exactly this problem before with overwritten modified mods (and not overwriting them isn't a that good solution as well). And writing an extended type just for this little addition was a little to much of work I thought. So I created a source to import which "missuses" the actual DX / OpenGL ImageFrame structure for my needs :) |
| ||
Well yours didn't work for me, so i hacked the mods. |
| ||
??? What did not work exactly? Beside the fact that you need to put it in an own file and import or remove the imports at the top :-) *want to make it working for any case ...* |
| ||
something about frame already being defined. I probably did something wrong with it. I'm thinking maybe I took out strict. |
| ||
Another thing to note: seems the textures are stored in boundaries of 64, so if your imagewidth is 71 then the real texture width is 127.. I'm looking for a mod function that I could modify to give the texture width of the image. |
| ||
hmm? Textures need to be 2^x due to opengl 1.2 specification. EDIT: and older cards do not accept anything else than 2^x sizes as well, just to mention (older = pre GF2 or similiar technic levels like SiS etc) |
| ||
so will an imagewidth of 71 always have a texture width of 127 on every possible hardware configuration? |