SFML community forums

Bindings - other languages => D => Topic started by: XKY on May 25, 2015, 01:42:29 pm

Title: setRepeated() is not work. :/
Post by: XKY 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. :)
Title: Re: setRepeated() is not work. :/
Post by: kitteh-warrior 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) );
Title: Re: setRepeated() is not work. :/
Post by: Equitiardead 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 (http://ohdivinehealth.com/phen375-reviews/) 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!
Title: Re: setRepeated() is not work. :/
Post by: Hapax 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.