Results 1 to 4 of 4

Thread: Get a Sprite PixelData?

  1. #1
    Lesser Wizard
    Join Date
    Jun 2007
    Posts
    109

    Default Get a Sprite PixelData?

    Basically, I want to get a texture from my current sprite's frame.

    Hopefully, after I make yaw/pitch adjustments.

    Since I need to be doing more low level-ish things that requires a texture, is there any easy way to get that from a sprite?

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Not easy...

    OpenGL performs the pixel scaling/rotation, so if you want to obtain the result after rotation:

    1) Create a new CL_Texture (texture_a), with the required size (usually this is: maximum_sprite_scale * largest_sprite_edge_size)
    2) Create a CL_FrameBuffer, selecting the texture_a as the color buffer (attach_color_buffer)
    3) Use gc.set_frame_buffer(); to set the frame buffer
    4) Call gc.clear(); to clear it
    5) Draw the sprite - this will draw onto the CL_Texture (A)
    6) Call gc.reset_frame_buffer();
    7) Use: CL_PixelBuffer pixels = texture_a.get_pixeldata()

    Note, steps 1 and 2 can be performed outside the main loop

    (Note, if using the GL1 target, ensure the Canvas example runs)

  3. #3
    Lesser Wizard
    Join Date
    Jun 2007
    Posts
    109

    Default

    Nice, thank you Rombust. I will give this a try and see where I end up =)

  4. #4
    Lesser Wizard
    Join Date
    Jun 2007
    Posts
    109

    Default

    Actually worked out better than I thought. What I was trying to do is draw to the "canvas" with a sprite like the old API. But I forget the new one is just using the GC so whatever I do on that GC will happen to it (including sprites). So that's awesome, it worked itself out. Thanks for pointing out the obvious to me, sometimes it's not so obvious I guess.

    I'll probably be adding to the AdvancedCanvas example here pretty soon, this is a fun trick

Similar Threads

  1. Enhancing the Sprite Batcher to 3D
    By rombust in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 05-31-2009, 09:28 AM
  2. sprite question?
    By Mahdi in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 09-07-2008, 12:18 PM
  3. Speed of Sprite
    By Nikitto46 in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 01-09-2008, 06:33 PM
  4. sprite constructor
    By Krux in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 09-21-2007, 06:52 AM
  5. Sprite patch for 0.8
    By Trigve in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 07-19-2007, 12:41 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •