Functions to set image UV

BlitzMax Forums/BlitzMax Module Tweaks/Functions to set image UV

TartanTangerine (was Indiepath)(Posted 2005) [#1]
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()



LeisureSuitLurie(Posted 2005) [#2]
Are u0 and v0 the bottom left point of the quad or the top left?


Red(Posted 2005) [#3]
Is it possible to rotate UV ?


TartanTangerine (was Indiepath)(Posted 2005) [#4]
Since UV are just co-ords it's possible to give them any position. Remeber UV extend from 0 to 1.


LeisureSuitLurie(Posted 2005) [#5]
Right. But the method only sets it for two points and I don't know which they are.


TartanTangerine (was Indiepath)(Posted 2005) [#6]
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.


Dreamora(Posted 2005) [#7]
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


Rambo_Bill(Posted 2005) [#8]
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.


Dreamora(Posted 2005) [#9]
see the function I added to the codearchives (DrawImageArea), its exactly your command but with a ,frame after (which has default 0 ;))


Rambo_Bill(Posted 2005) [#10]
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?


Dreamora(Posted 2005) [#11]
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 :)


Rambo_Bill(Posted 2005) [#12]
Well yours didn't work for me, so i hacked the mods.


Dreamora(Posted 2005) [#13]
???
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 ...*


Rambo_Bill(Posted 2005) [#14]
something about frame already being defined. I probably did something wrong with it. I'm thinking maybe I took out strict.


Rambo_Bill(Posted 2005) [#15]
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.


Dreamora(Posted 2005) [#16]
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)


Rambo_Bill(Posted 2005) [#17]
so will an imagewidth of 71 always have a texture width of 127 on every possible hardware configuration?