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

Author Topic: Tesselations (texture issue)  (Read 2286 times)

0 Members and 1 Guest are viewing this topic.

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Tesselations (texture issue)
« on: April 06, 2014, 11:43:05 pm »
I'm trying to tile an image across an area, but instead of tiling, the image is stretching to fill the area.

The tiling function is as follows:
Code: [Select]
void tileImage(sf::RenderTarget& target, RECT area, sf::Texture& img, RECT srcRect, sf::BlendMode mode){
img.setRepeated(true);
sf::Vector2u imgSz = img.getSize();
area.left -= area.left % imgSz.x;
area.top -= area.top % imgSz.y;

sf::RectangleShape tessel(sf::Vector2f(area.width(),area.height()));
tessel.setTexture(&img);
tessel.setTextureRect(srcRect);
tessel.setPosition(area.left, area.top);
sf::RenderStates renderMode(mode);
setActiveRenderTarget(target);
glEnable(GL_SCISSOR_TEST);
glScissor(area.left, area.top, area.width(), area.height());
target.draw(tessel, renderMode);
glDisable(GL_SCISSOR_TEST);
}
The texture that's passed in contains several images of which I only want to tile one, that contained in the rectangle "srcRect". The rectangle "area" is the area in which the image should be tiled. The setActiveRenderTarget call just calls target.setActive() if target is a RenderWindow, because for some reason RenderTexture doesn't have a setActive function (which makes me wonder if this'll work on a RenderTexture, but I'll get to that later).

I'm hoping I'm just missing something obvious here. I know roughly what needs to happen (the texture should be drawn with normalized texture coordinates > 1), but I'm not sure what I've missed in trying to get SFML to do this. Will I need to copy the portion I want to repeat into a new texture?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Tesselations (texture issue)
« Reply #1 on: April 07, 2014, 07:56:52 am »
This is the expected behaviour, please read the documentation. To repeat a texture you must call texture.setRepeated(true) and use a textureRect bigger than the texture itself. Yes, it implies that you can only repeat the whole texture, not a sub-rectangle of it.

Quote
for some reason RenderTexture doesn't have a setActive function
It does.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10858
    • View Profile
    • development blog
    • Email
AW: Tesselations (texture issue)
« Reply #2 on: April 07, 2014, 08:04:46 am »
The title can be a bit misleading, given that in computer science tesselation is often used to describe the "automatic" increasing of vertices. ;)

Anyways regarding your issue, why don't you simply use SFML functions? If the whole texture should get repeated you could set texture repeat and adjust the texture rect. If it's only part you could simply generate a vertex array that uses the texture.

For the given code I can't say anything, given that I've no experience in OpenGL. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Tesselations (texture issue)
« Reply #3 on: April 07, 2014, 08:15:11 am »
This is the expected behaviour, please read the documentation. To repeat a texture you must call texture.setRepeated(true) and use a textureRect bigger than the texture itself. Yes, it implies that you can only repeat the whole texture, not a sub-rectangle of it.
Alright, thanks for that info; I was wondering if that might be an issue. I guess I'll have to copy the desired portion to a new texture and repeat that.

Quote
for some reason RenderTexture doesn't have a setActive function
It does.
Oh, it must've been that RenderTarget doesn't have one, then.

Anyways regarding your issue, why don't you simply use SFML functions? If the whole texture should get repeated you could set texture repeat and adjust the texture rect. If it's only part you could simply generate a vertex array that uses the texture.
Um, I am using SFML functions. The stuff with GL_SCISSOR isn't directly related to the tiling; it just ensures that the tessellation is clipped to the intended area (since the actual area drawn two will, in general, be larger than the area I want to fill in order to ensure that the tiling always lines up the top left of the texture with the top left of the window).