Off screen vector rendering.
  • igierardigierard January 10
    Posts: 3
    Hello

    I'm working with the PXTextureData drawDisplayObject calls for rendering my vector drawing (PXGraphics) to a texture. I've noted some issues with the system that make it a somewhat difficult to accomplish this.

    It seems that if the display object that you are drawing to hasn't been added to stage it is never rendered (or inked as it seems) and any calls to draw that display object to a PXTextureData result in an empty texture. Is there some way that we could force a render while the display object is off stage.

    Also TextureData is defined in pixels and my graphics calls are done in points. When on a retina display device when we draw the display object it comes in at double resolution and we only get the top left corner. I've been able to solve this by modifying the draw matrix with the scale data but it isn't exactly expected behavior.

    <code>
    float pixelScale = 1.0/PXGLGetContentScaleFactor();
    [texData drawDisplayObject:baseArt matrix:[[[PXMatrix alloc] initWithA:1.0*pixelScale b:0.0 c:0.0 d:1.0*pixelScale tx:-artBounds.x*pixelScale ty:-artBounds.y*pixelScale] autorelease] colorTransform:nil clipRect:nil smoothing:YES clearTexture:YES];
    </code>
    Also as some other people have noted the smoothing option doesn't seem to do anything.

    P.S. I'm working off the graphics-alpha branch right now
  • JohnJohn January 10
    Posts: 52

    To answer your first question, try pulling the latest code and use one of these two functions:

    - (BOOL) buildWithDisplayObject:(PXDisplayObject *)obj;
    - (BOOL) build:(PXGLMatrix)matrix;

    These functions may change in the future, however they will build/ink your object if it has never built before, or if something has changed.

    It unfortunately needs a matrix, which can be defined by the display object, however it doesn't have a reference to it's parent, so for now you need to give it ex:

    [self.graphics build:self];

    As for the second question, the TextureData must work in pixels, as it has a 1 and 1 understanding with gl textures which only work in pixels. You can set the content scale factor of the texture data that you are creating to PXGLGetContentScaleFactor(), this would give it whatever scale factor you are working with, and thus should have the correct quantity of pixels.

    Ex.

    float f = PXGLGetContentScaleFactor();
    float w = self.stage.stageWidth * f;
    float h = self.stage.stageHeight * f;
    PXTextureData *td = [[PXTextureData alloc] initWithWidth:w height:h transparency:YES fillColor:0x00FFFFFF contentScaleFactor:f];
    (Tried to use short variable names so it may be readable on a non 27-inch monitor.)

    Let me know if this helps,


    -John

    P.S. To get blocks around code like mine, hit the "show source" button and you can do:
    <pre lang="objc">
    myCode();
    </pre>
    around your code, and that will be the result.
    Pixelwave Team - Lead Developer
    // Clean before you build, otherwise the dust will get in.
  • igierardigierard January 10
    Posts: 3

    Thank you that was exactly what I was looking for and both suggestions worked quite well.


    Also thanks for the code formatting tip. Is there a Post somewhere that has a list of formatting help?
  • JohnJohn January 12
    Posts: 52

    Update: You no longer need to call build, it will just work now when using render to texture. It should have built for you prior to calling renderToTexture, and now it will! :-)

    Pixelwave Team - Lead Developer
    // Clean before you build, otherwise the dust will get in.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Twitter Sign In with OpenID

Sign In Apply for Membership

In this Discussion

Top Posters