Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beginTextureFills being scaled incorrectly sometimes #121

Open
mikhailkuts opened this issue Oct 22, 2014 · 6 comments
Open

beginTextureFills being scaled incorrectly sometimes #121

mikhailkuts opened this issue Oct 22, 2014 · 6 comments

Comments

@mikhailkuts
Copy link

Hi, I reopening issue #82 (comment) .
Problem still exist. Example for reproduce:

var renderTxt:RenderTexture = new RenderTexture(200, 200);

var shape:Shape = new Shape();

shape.graphics.beginFill(0xFF02F1);
shape.graphics.drawCircle(100, 100, 100);
shape.graphics.endFill();

renderTxt.draw(shape);

shape.graphics.clear();

view.addChild(shape);

shape.graphics.beginTextureFill(renderTxt);

shape.graphics.moveTo(0, 0);
shape.graphics.lineTo(200, 0);
shape.graphics.lineTo(200, 200);
shape.graphics.lineTo(0, 200);

shape.graphics.endFill();

Filled circle is smaller than it should be.

@IonSwitz
Copy link
Member

Hi.

I've been looking at this for a little bit, but I dont see anything at all within the drawn square here. I cant get the renderTexture to work at all?

Could you provide a screen shot of what you see?

I can absolutely agree that "nothing" doesn't seem right :)

@IonSwitz
Copy link
Member

The feature works as can be expected with a regular texture for me, but not with a RenderTexture

Edit: Well, maybe not. When I do beginTextureFill and then draw a circle, things get weird. So ok, this is broken.I'm wondering how the fill stuff is supposed to work, and I really don't understand the "scale(1/256, 1/256)" call mentioned in the other thread, in the Fill class constructor

@mikhailkuts
Copy link
Author

Hi! Thanks for quick respond )
When I used texture from bitmap data (Texture.fromBitmapData) - I have same result: circle dimensions are less than they should be.
Example code above drawing fill of a circle texture with 100 radius, but I see next:
screen shot 2014-10-22 at 8 39 59 pm

Circle should have radius 100.

@IonSwitz
Copy link
Member

The problem here is that your texture is "officially" 200x200, but in "reality" it is 256x256, and the texture coordinates gets mapped out between 0.0-1.0 , ie , all the way to 256 of the rect.

So, unfortunately, the scaling has to be done by a UV-matrix. Basically this:

var rectWidth:Number = 200;
var rectHeight:Number = 200;

var uvMatrix:Matrix = new Matrix();
uvMatrix.scale(getNextPowerOfTwo(texture.width) / texture.width ,       getNextPowerOfTwo(texture.height) / texture.height );
uvMatrix.scale(rectWidth / texture.width , rectHeight / texture.height );

shape.graphics.beginTextureFill(texture, uvMatrix);
shape.graphics.drawRect(0, 0, rectWidth, rectHeight);

I am most likely doing the math wrong, I have no real time to devote to this at the moment. But the uvMatrix has to be scaled to compensate for the ratio of the power of two width and height of the texture.

And, yes, this is a severe limitation on the usability of the graphics API.

@mikhailkuts
Copy link
Author

Thanks a lot for your help, I'll try this solution :)

@hardcoremore
Copy link

hardcoremore commented Oct 23, 2019

Hi @IonSwitz ,

I am using latest Starling 2 and beginTextureFill does not work at all. When I am drawing with line to nothing is visible.

Do you maybe know to reason?

Normal color fill with beginFill(0xFF0000, 1) is working great?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants