Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: setRepeated() is not work. :/  (Read 12663 times)

0 Members and 1 Guest are viewing this topic.

XKY

  • Newbie
  • *
  • Posts: 3
    • View Profile
setRepeated() is not work. :/
« on: May 25, 2015, 01:42:29 pm »
Hello. ;D
I just got a problem when i copied a example code of  'SFML Essentials(38 page)' like this:

import derelict.sfml2.window;
import derelict.sfml2.graphics;
import derelict.sfml2.system;

void main(){
        DerelictSFML2Window.load();
        DerelictSFML2Graphics.load();
        DerelictSFML2System.load();
       
        sfVideoMode videoMode = {640, 480, 32};
        sfRenderWindow* window = sfRenderWindow_create( videoMode, "The title", sfClose, null );
       
        sfTexture* texture = sfTexture_createFromFile( "tile.png", null );
        //Set the texture in repeat mode
        sfTexture_setRepeated( texture, sfTrue );
       
        sfRectangleShape* rectShape = sfRectangleShape_create();
        sfRectangleShape_setSize( rectShape, sfVector2f( 128*3, 221*2 ) );
        //Bigger texture rectangle than the size of the texture
        sfRectangleShape_setTextureRect( rectShape, sfIntRect(0, 0, 128*3, 221*2) );
       
        sfRectangleShape_setTexture( rectShape, texture, sfTrue );
       
        while( sfRenderWindow_isOpen(window) ){
                sfEvent event;
                while( sfRenderWindow_pollEvent(window, &event) ){
                        if( event.type == sfEvtClosed ){ sfRenderWindow_close( window ); }
                        sfRenderWindow_clear( window, sfWhite );
                        sfRenderWindow_drawRectangleShape( window, rectShape, null );
                        sfRenderWindow_display( window );
                }
        }
}

yes. it's used Derelict-SFML. Execute is well, but not work tile repeated.
I don't know why. Is any problem with my code? reply please..
thanks. :)
« Last Edit: May 25, 2015, 03:42:11 pm by XKY »

kitteh-warrior

  • Guest
Re: setRepeated() is not work. :/
« Reply #1 on: June 20, 2015, 10:41:45 pm »
I'm not sure about the D binding, but I believe the window clearing, drawing and updating shouldn't be in the event loop like it is in your example.


... [omitted] ...
sfRectangleShape_setTextureRect( rectShape, sfIntRect(0, 0, 128*3, 221*2) );
... [omitted] ...

Also, this sets the texture rectangle to 3 times the width and 2 times the height of the actual texture. It should be:
sfRectangleShape_setTextureRect( rectShape, sfIntRect(0, 0, 128, 221) );

Equitiardead

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: setRepeated() is not work. :/
« Reply #2 on: August 28, 2016, 03:42:17 am »
I'm not sure about the D binding, but I believe the window clearing, drawing and updating shouldn't be in the event loop like it is in your example.
Best website to buy phen375 here.

... [omitted] ...
sfRectangleShape_setTextureRect( rectShape, sfIntRect(0, 0, 128*3, 221*2) );
... [omitted] ...

Also, this sets the texture rectangle to 3 times the width and 2 times the height of the actual texture. It should be:
sfRectangleShape_setTextureRect( rectShape, sfIntRect(0, 0, 128, 221) );

we have the same issue. but what you post is an eye opening. hoping to resolve mine on your conclusion. thank you!
« Last Edit: October 31, 2016, 08:17:54 pm by Equitiardead »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: setRepeated() is not work. :/
« Reply #3 on: August 28, 2016, 08:04:26 pm »
... [omitted] ...
sfRectangleShape_setTextureRect( rectShape, sfIntRect(0, 0, 128*3, 221*2) );
... [omitted] ...

Also, this sets the texture rectangle to 3 times the width and 2 times the height of the actual texture. It should be:
sfRectangleShape_setTextureRect( rectShape, sfIntRect(0, 0, 128, 221) );
That's actually how you use a repeating texture. You specified texture coordinates past the boundaries of the image and the image is repeated in the boundaries. Using your line would only that part once.

That said, XKY, are you sure that the image is smaller than your texture rectangle? Note that you can't repeat a section of a texture; only the full texture can be repeated.

Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*