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

Author Topic: Texture rotation  (Read 5546 times)

0 Members and 1 Guest are viewing this topic.

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Texture rotation
« on: December 08, 2012, 08:47:41 pm »
Just as the title literally describes, it is something possible to do with openGL (like almost anything), but not with sfml as far as I know. It's when you want to rotate the texture (change how the texture is mapped). It makes little sense to use it that way when the texture isn't repeated, but when it is you can get nice effects.

I know the idea sounds a bit wacky since it's not really used often, but it may be useful in some cases.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Texture rotation
« Reply #1 on: December 08, 2012, 08:51:09 pm »
Quote
but it may be useful in some cases
Which cases?

And are you talking about the texture matrice? If so, then you probably mean "texture coordinates rotation". If not, then I don't know what "texture roration" means in OpenGL terms.

And can't you do that by changing texture coordinates directly?
Laurent Gomila - SFML developer

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Texture rotation
« Reply #2 on: December 08, 2012, 09:07:47 pm »
To "rotate" the texture without rotating the vertexes, the quad, triangle or anything else remains untouched while the texture rotates in a flexible manner (not in the typical 0 ,90, 180, 270 which are nearly trivial, that would also be flipping which is already possible).

Say I want to use a 256x256 (or any not too big resolution in the end) repeated texture as a background and I want to create the illusion of movement, so you "transform" the texture mapping coordinates according to what you need (in this case a rotation).

Something like:

Spr.rotateTexture(1);
/**So in each loop it changes how the texture is mapped by one degree.
   *Like the transformations of any transformable.
   *Just that instead of it's vertices it's the texture mapping that changes */

 


If it was not enough then I'll try to illustrate it some other way.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Texture rotation
« Reply #3 on: December 08, 2012, 10:27:03 pm »
So you're talking about the texture matrix? Since you were talking about it being possible with OpenGL, I assume that you have a clear idea of what it is.

What's the difference with rotating the geometry (vertices)? And with manually changing the texture coordinates of the vertices?
Laurent Gomila - SFML developer

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Texture rotation
« Reply #4 on: December 09, 2012, 12:25:35 am »
http://tinypic.com/view.php?pic=2rnh0n9&s=6

Black is a quad, Red is the texture, imagine red rotating around a point in black.

Quote
What's the difference with rotating the geometry (vertices)? And with manually changing the texture coordinates of the vertices?

It gives you a slight amount of flexibility I guess, I failed to think everything through before making the thread, since in order to get this kind of functionality you need a repeated texture it doesn't make that much of a difference visually. I don't know however if a repeated texture is still shown even after the quad is no longer in the window limits.

For some reason the forum didn't allow me to upload the image, even when it's smaller than the individual maximum.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Texture rotation
« Reply #5 on: December 09, 2012, 08:51:42 am »
Quote
It gives you a slight amount of flexibility I guess
The texture matrix is just a convenient and efficient way to apply a uniform transformation to the texture coordinates of all the vertices. Just like the model-view matrix is a convenient and efficient way to apply a uniform transformation to the vertices position. So what you can do with a texture matrix, you can do it too by directly changing the vertices texture coordinates. It will just be less elegant and efficient (but you will probably not notice the loss of efficiency), but not less flexible.

You can also create a bigger background and rotate the vertices position directly, it doesn't matter if parts of it are outside the visible area.

And I'm still waiting for a real use case that requires this feature ;)

Quote
For some reason the forum didn't allow me to upload the image, even when it's smaller than the individual maximum.
Strange. It has always worked so far.
Laurent Gomila - SFML developer

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Texture rotation
« Reply #6 on: December 09, 2012, 08:06:51 pm »
Quote
And I'm still waiting for a real use case that requires this feature ;)

I am working on it. Its real uses aren't that big, but you can certainly reach good results with little resources, rather than using a large texture and a view for the job (as well as making it compatible with low end GPU's). To explain it further I'll post a sample video once I have finished at least half of my background management. I have texture translation already implemented, but not rotation, or at least not working they way it should.

I could also post an already working example of it (not mine of course), but I need to find one that makes a better example than the ones I know. As soon as I find it I'll post it.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!