StarlingGraphics / Starling-Extension-Graphics

flash.display.Graphics style extension for the Starling Flash GPU rendering framework
https://github.com/StarlingGraphics/Starling-Extension-Graphics/wiki
MIT License
282 stars 89 forks source link

Having problems with BeginTextureFill when the bitmap is big #105

Closed lukiyori closed 10 years ago

lukiyori commented 10 years ago

I have a bitmap which has a size of 1280x720, when I try to draw the bitmap to the shape using graphics it scales down the bitmap to 802x506 pixels.

Here is my code: var _width:int = 1280; var _height:int = 720; var texture:Texture = Texture.fromBitmap(bitmap);
graphics.clear(); graphics.beginTextureFill(texture); graphics.drawRect(0,0,_width,_height); graphics.endFill();

I found another example describing using uvMatrix during beginTextureFill, var uvMatrix:Matrix = new Matrix(); var texture:Texture = Texture.fromBitmap(bitmap);
uvMatrix.scale(1.6,1.44);

graphics.clear(); graphics.beginTextureFill(texture,uvMatrix); graphics.drawRect(0,0,_width,_height); graphics.endFill();

This works fine, but ofcourse that ratio does not works with my other bitmap which has 1700x720 size, I wonder what is the maximum texture size, or how am I going to use big bitmaps with beginTextureFill..

Thank you

IonSwitz commented 10 years ago

The explanation is that the texture becomes a power of 2, so the 1280x720 bitmap becomes 2048x1024 when you do Texture.fromBitmap().

So, what you need to do is to set:

uvMatrix.scale(texture.width/_width, texture.height/_height);

lukiyori commented 10 years ago

Hi IonSwitz.. I get the width of the texture 1280 and height of the texture 720. so that when I try to scale it , I get the same result, what is more interesting is this:

When I debug the code I found out that there is a clipping property where the width and height has the scale values I need..

I can only get this working when I cast the texture object to "*" instead of "Texture".

Here is the code you can try: var texture:Texture = Texture.fromBitmap(bitmap); trace(texture.clipping.width); // Does not compiles

but :

var texture:* = Texture.fromBitmap(bitmap); trace(texture.clipping.width);

gives me the scale values that I need.

So I changed my code to this, and its working:

var uvMatrix:Matrix = new Matrix(); var texture:* = Texture.fromBitmap(bitmap);
var w:Number = texture.clipping.width; var h:Number = texture.clipping.height; uvMatrix.scale(1/w,1/h);

IonSwitz commented 10 years ago

Wow, ok I was sure there was a "width" property on Texture that gives you the power of two width. Apparently not.

Yes, if you cast the texture to "SubTexture" rather than the base class "Texture", you can access the clipping rectangle without compilation errors and use that for this purpose.

lukiyori commented 10 years ago

Thank you