Results 1 to 11 of 11

Thread: Bug when I draw a set of sprites

  1. #1

    Default Bug when I draw a set of sprites

    Its hard to describe the issue i'm having. so here's a picture
    When the game launches it looks fine.
    Click image for larger version. 

Name:	Servo-normal.png 
Views:	22 
Size:	12.2 KB 
ID:	600
    when i resize the window it looks like this
    Click image for larger version. 

Name:	servo-glitch.png 
Views:	27 
Size:	23.4 KB 
ID:	601

    the blue background is shown through the tiles.

    Here's the relevant code i think.
    resource.xml
    Code:
    <sprite name="spr_maptiles">
        	<image file="resources/bricks2.png">
        		<grid pos="0,0" size="16,16" array="3,1" spacing="1,0"/>
        	</image>
        </sprite>
    Code:
    //Get window size and set scaling matrix
    CL_Mat4f m_scale = CL_Mat4f::scale( gc.get_width() / float(screen_w), gc.get_height() /float(screen_h), 1.0f);
    
    tile_images = CL_Sprite(gc, "Servo/spr_maptiles", resources);
    THis is in loop to draw every tile based on the tile coordinate
    Code:
     Tile * temptile=cur_slice->get_tile(x,y);
                 temp=temptile->get_position().get_coord();
    
                 int scr_x = temp.x - center_x;
                 int scr_y = temp.y - center_y;
    
                 int frame = temptile->get_tile_type();
    
                 tile_images.set_frame(frame);
                 tile_images.draw(gc, scr_x, scr_y);
    Heres the tilemap

    Name:  bricks2.png
Views: 20
Size:  343 Bytes
    Any help would be great.

    ButterQuark

  2. #2

    Default

    I experienced a simmilar bug when trying to scale the display using

    Code:
    CL_Mat4f matrix = CL_Mat4f::scale( 2.0f, 2.0f, 1.0f);
    gc.set_modelview(matrix);
    I don't know how to fix it thought.

    edit: I made some test and it look like it's related to openGL 1, because with SW Render I don't have the bug. I didn't test the normal opengl version thought. It look like it might be antialiasing problem or something similar.

    Here is a screenshot
    Click image for larger version. 

Name:	gl1bug.png 
Views:	24 
Size:	391.4 KB 
ID:	603
    Last edited by powerfear; 09-29-2011 at 11:38 PM.

  3. #3

    Default

    i checked that, and it worked much better. thank you.

    Is there any benefits/drawbacks to using OpenGL vs the SWRenderer?

    if not i'll just stick with SWRenderer (since I've already found a benefit.

    -Butterquark

  4. #4

    Default

    Quote Originally Posted by butterquark View Post
    Is there any benefits/drawbacks to using OpenGL vs the SWRenderer?
    Well personnaly for my game openGL rendering is quite enormously faster then SW Rendering.

    So would be pretty nice if one of the developper could have a look at this and tell us if we are doing something wrong or if there is something to fix so it work with openGL.

  5. #5
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Does it only happen with clangl1 or also with clangl?

  6. #6

    Default

    It happen with both of them.

  7. #7

    Default

    Quote Originally Posted by powerfear View Post
    It happen with both of them.
    This is consistent with my tests.
    Let me know if you need some example code that gives this error.

  8. #8
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    I don't have time to look into it, but if you provide some minimal example that demonstrates the bug, the chance someone else will is slightly larger at least.

  9. #9

    Default

    Quote Originally Posted by sphair View Post
    I don't have time to look into it, but if you provide some minimal example that demonstrates the bug, the chance someone else will is slightly larger at least.
    The Examples\Game\TileMap is a good example to show the bug. Just unquote that part in the game.cpp

    Code:
    // ** Enable these 3 lines to display the example magnified **
    //CL_Mat4f matrix = CL_Mat4f::scale( 2.0f, 2.0f, 1.0f);
    //x /= 2; y /= 2;
    //gc.set_modelview(matrix);
    And just switch arround opengl / swrenderer in the precomp.h

  10. #10
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,773

    Default

    To fix it...

    In TileMap::load()

    After: sprite_tiles = CL_Sprite(gc, resource_name, &resources);
    Add: sprite_tiles.set_linear_filter(false);

    Reason...

    OpenGL is being "clever" and filtering the pixels using the adjacent pixels.

    Now the tiles (eg A,B, C and D) are laid out in memory as follows:

    Code:
     AAABBB
     AAABBB
     AAABBB
     CCCDDD
     CCCDDD
     CCCDDD
    The adjacent pixel to the right edge of tile A is the leftmost pixel of tile B.

    For interest, the clanGUI "packed" graphics, where all gui graphics are contain in a single texture - are fixed by using the CL_PixelBufferHelp::add_border() function in the Utilities\TexturePacker

  11. #11

    Default

    Thanks rombust.

    That fixed the example, but it didn't fix my code because I am using:

    CL_Mat4f m_scale = CL_Mat4f::scale( gc.get_width() / float(screen_w), gc.get_height() /float(screen_h), 1.0f);

    Click image for larger version. 

Name:	servo-stillbug.png 
Views:	6 
Size:	67.8 KB 
ID:	605Click image for larger version. 

Name:	servo-lines2.png 
Views:	7 
Size:	31.3 KB 
ID:	606Click image for larger version. 

Name:	servo-lines.png 
Views:	4 
Size:	65.1 KB 
ID:	607
    These are with two different screen sizes and two different tilemaps.
    The green sky tiles have a transparent border between them as show in the OP. The blue sky tiles don't have any seperation between them, and the green is replaced with a transparent tile.

    In the Tilemap example, it works perfectly at 2.0x but I tried a skewed magnification:

    CL_Mat4f matrix = CL_Mat4f::scale( 1.5f, 2.0f, 1.0f);

    which gives weird lines when you have the mouse in the right place.

    CL_Mat4f matrix = CL_Mat4f::scale( 1.5f, 1.5f, 1.0f);

    This also gives the weird lines, but this:

    CL_Mat4f matrix = CL_Mat4f::scale( 3.2f, 2.0f, 1.0f);

    does not. SO as far as i can tell, there are just bad scaling factors (like 1.5f) that cause the drawing to be done in wierd ways to get these lines.

    Basically, if you coudn't tell, I'm looking for a way to draw a tilemap at different screen sizes but keeping the same amount of information on the screen.
    Last edited by butterquark; 10-03-2011 at 02:30 PM. Reason: added screenshot

Similar Threads

  1. CollisionOuline Draw ?
    By Jason Schilling in forum ClanLib: Help
    Replies: 1
    Last Post: 08-02-2011, 04:01 PM
  2. CL_Sprite draw problem
    By Aikidos in forum ClanLib: Help
    Replies: 1
    Last Post: 04-22-2011, 02:08 PM
  3. draw sprites without background
    By Koli14 in forum ClanLib: Help
    Replies: 5
    Last Post: 01-14-2010, 09:26 AM
  4. CL_Surface draw a picture
    By DavinciZhe in forum ClanLib: Help
    Replies: 2
    Last Post: 08-08-2009, 02:01 AM
  5. GDI Target Draw Problems
    By rombust in forum ClanLib: Developer Chat
    Replies: 1
    Last Post: 05-01-2009, 01:21 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
  •