Textures get stretched several pixels when rendered to a RenderTexture (WebGL)

Textures get stretched several pixels when rendered to a RenderTexture (WebGL)
0.0 0


EDIT: After thinking it through a little more I recalled the projection type which is 3D by default. Changing it to 2D seems to have solved my original problem.

When a sprite is rendered to a RenderTexture and the context is WebGL, the resultant image is always stretched out several pixels more than the original. If I do a visit with a 512x512 sprite (from a loaded image), it ends up rendering 514x514 on the texture. If I render a 1024x1024 image, it becomes 1028x1028. The larger the image the more stretched it will be. In Canvas-only mode, it is drawn correctly.

Is there some magical parameter or option that can be altered to ensure the visited textures are identical to the original sprites and not enlarged? I’ve tried disabling subpixels in the config as well as setAliasTexParameters to no affect. You can see the problem even on the rendertexture test by substituting the brush texture with s_atlasTest (512x512) and drawing it to the canvas. It ends up being 514x514.

Here’s a screenshot:

Is there any logical solution or explanation?


Hi Victor,

I have tested this question, but it works correct.
Here is a screenshot:

I have added a flag to ensure the brush only drawn once. Here is the codes:
add a flag at onEnter:
this.*isDrawed = false;
drawInLocation:function {
var distance = cc.pDistance;
if {
var locBrush = this.*brush, locLastLocation = this.*lastLocation;
for (var i = 0; i < distance; i++) {
var diffX = locLastLocation.x - location.x;
var diffY = locLastLocation.y - location.y;

var delta = i / distance;

locBrush.setPosition(location.x + diffX * delta, location.y + diffY * delta);
//locBrush.setRotation(Math.random() * 360);
//locBrush.setScale(Math.random() * 2);
//locBrush.setColor(cc.c3b(Math.random() * 255, 255, 255));
locBrush.setColor(cc.c3b(255, 255, 255));
this.*isDrawed = true;
this._lastLocation = location;

Thanks for your feedback.