Results 1 to 5 of 5

Thread: Drawing a rotated texture?

  1. #1

    Default Drawing a rotated texture?

    How can I use something like "CL_Draw::texture" but have the texture at an angle? And if possible the same for things like CL_Draw::fill.

    Thanks.

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

    Default

    As you sure CL_Draw::texture is what you need?

    You may find it easier to use CL_Sprite or CL_Image.
    (Think of CL_Image as a faster version of CL_Sprite, but with less options)

    Code:
    gc.set_texture(0, texture_image);
    src_rect = CL_Rect( ... ); <-- In pixels
    texture_coords = CL_Rectf(0.25f, 0.25f, 0.75f, 0.75f); <-- 0.0f to 1.0f
    color = CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f); <-- RGBA colour
    CL_Draw::texture(gc, src_rect, color, texture_coords);
    gc.reset_texture(0);
    I only use CL_Draw::texture in test code. Also it will be slower than CL_Image (CL_Image uses batch drawing).

    If you are drawing 1000's of textures every frame (using OpenGL), then use a vertex buffer. There is an example to demonstrate this.

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

    Default

    Ah, I may have misread your question.

    If you meant "rotating the source texture, and drawing in the same location"

    Use the "texture_coords" in the above code

    For CL_Draw::fill(), you can use gc.set_modelview(...) to rotate the fill region.

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

    Default

    For example:
    Code:
    		angle+=0.5f;
    		gc.push_modelview();
    
    		CL_Rectf dest_position(240.0f, 140.0f, 440.0f, 340.0f);
    
    		gc.mult_translate(dest_position.get_center().x, dest_position.get_center().y);
    		gc.mult_rotate(CL_Angle(angle, cl_degrees),0.0f, 0.0f, 1.0f);
    		gc.mult_translate(-dest_position.get_center().x, -dest_position.get_center().y);
    
    		CL_Draw::fill(gc, dest_position, CL_Colorf(1.0f, 1.0f, 1.0f));
    		gc.pop_modelview();
    (There are other ways of achieving the same effect)

  5. #5

    Default

    Thanks for your help

Similar Threads

  1. Texture instead of gradient
    By Ockonal in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 12-25-2010, 08:18 AM
  2. New Texture 3D example
    By rombust in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 11-24-2009, 02:12 PM
  3. texture drawing method questions
    By ppheathead in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 06-10-2009, 07:19 AM
  4. relationship between GC and Texture?
    By logixoul in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 07-07-2008, 07:17 AM
  5. Green border around rotated sprite on ATI cards - Solved!
    By pTymN in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 11-06-2006, 08:44 PM

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
  •