Discussion:
Off Topic / OpenGL Texture Tiling
Jeremy L. Moles
2007-06-06 19:09:48 UTC
Permalink
I've tried googling and asking this question in various other OpenGL
places with no success--so I figured I'd try here, since I know there
are some OpenGL gurus around. In fact, I was told in #opengl on Freenode
it wasn't possible, but I doubt it sense people have been doing this for
ages used fixed-function OpenGL.

I'm working on a UI toolkit using native OSG objects (no weird
"gluecode" or external library) and have come across something I can't
readily get the answer to.

Imagine an interface "window"; at the minimum you'll have about 9
regions that describe this window:

- upper left and right corners
- lower left and right corners
- top, left, bottom, and right "bars"
- center

Now imagine a texture you want to use as the window's "skin." Ideally,
you'll load an image into the texture and position the TexCoords so that
you can create the illusion of having a true, decorated and composed
window. This is fairly straightforward in concept except for one aspect.

Lets say you want to texture the "top bar" region of your window. Well,
by default, unless this portion of your image (or skin) is cleverly
positioned in the texture itself, there's really no way I know of to
"tile" it across the geometry. You can stretch it across, but this is
often quite ugly.

My question: is it possible in OpenGL to somehow manipulate the texture
matrix (or something else) to only operate on a "sub-region" of a
texture such that you can tile just that portion? CEGUI does this
somehow, but it's API is so abstracted I can't really track it's
implementation down.

I _know_ it's possible using a GLSL shader, but at this point it's
really academic for me to find out how to do it otherwise, I know game
makers have been doing this for years w/out shaders, and it's really
bugging me to find out how! :) Any advice or guidance on the issue would
be enormously appreciated...
Robert Osfield
2007-06-06 20:06:08 UTC
Permalink
Hi Jeremy,

OpenGL supports texture repeat but only for the whole texture,
osgtexture2D has an example of texture repeat so have a look at whats
possible with just standard OpenGL wrap modes.

Repeating a sub-porton of texture atlas is rather different though,
using wrap modes you'll end up repear over the whole 0.0 to 1.0 range
rather than just the portion you want. If you using a TextMat you can
get OpenGL to repeat the texture at high frequency, but it'll still be
over the whole 0.0 to 1.0 range, it won't skip things out of your
range.

The only ways I can think of repeating a subporting are to use GLSL to
manage the tex coord wrapping internally in the fragment program, or
to simply repeat your texture manually in your texture atlas, or just
ditch the use of sub regions and wash, rinse, repeat like standard
OpenGL texture wrap modes.

Robert.
Post by Jeremy L. Moles
I've tried googling and asking this question in various other OpenGL
places with no success--so I figured I'd try here, since I know there
are some OpenGL gurus around. In fact, I was told in #opengl on Freenode
it wasn't possible, but I doubt it sense people have been doing this for
ages used fixed-function OpenGL.
I'm working on a UI toolkit using native OSG objects (no weird
"gluecode" or external library) and have come across something I can't
readily get the answer to.
Imagine an interface "window"; at the minimum you'll have about 9
- upper left and right corners
- lower left and right corners
- top, left, bottom, and right "bars"
- center
Now imagine a texture you want to use as the window's "skin." Ideally,
you'll load an image into the texture and position the TexCoords so that
you can create the illusion of having a true, decorated and composed
window. This is fairly straightforward in concept except for one aspect.
Lets say you want to texture the "top bar" region of your window. Well,
by default, unless this portion of your image (or skin) is cleverly
positioned in the texture itself, there's really no way I know of to
"tile" it across the geometry. You can stretch it across, but this is
often quite ugly.
My question: is it possible in OpenGL to somehow manipulate the texture
matrix (or something else) to only operate on a "sub-region" of a
texture such that you can tile just that portion? CEGUI does this
somehow, but it's API is so abstracted I can't really track it's
implementation down.
I _know_ it's possible using a GLSL shader, but at this point it's
really academic for me to find out how to do it otherwise, I know game
makers have been doing this for years w/out shaders, and it's really
bugging me to find out how! :) Any advice or guidance on the issue would
be enormously appreciated...
_______________________________________________
osg-users mailing list
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
Jeremy L. Moles
2007-06-06 20:27:18 UTC
Permalink
Post by Robert Osfield
Hi Jeremy,
OpenGL supports texture repeat but only for the whole texture,
osgtexture2D has an example of texture repeat so have a look at whats
possible with just standard OpenGL wrap modes.
C'mon, I at least knew this much! *grin*
Post by Robert Osfield
Repeating a sub-porton of texture atlas is rather different though,
using wrap modes you'll end up repear over the whole 0.0 to 1.0 range
rather than just the portion you want. If you using a TextMat you can
get OpenGL to repeat the texture at high frequency, but it'll still be
over the whole 0.0 to 1.0 range, it won't skip things out of your
range.
The only ways I can think of repeating a subporting are to use GLSL to
manage the tex coord wrapping internally in the fragment program, or
to simply repeat your texture manually in your texture atlas, or just
ditch the use of sub regions and wash, rinse, repeat like standard
OpenGL texture wrap modes.
Yeah, this is what I suspected. It still kinda' raises the question how
other kits do it, but I bet it's something like this:

Here's my window's conceptual top bar:

+---+------------------------------+---+
| 1 | 1 | 3 |
+---+------------------------------+---+


...and I bet this is theirs:

+---+---+---+---+---+---+---+---+---+---+
| 1 | . | . | . | . | . | . | . | . | 3 |
+---+---+---+---+---+---+---+---+---+---+

...where they've created new geometry to accommodate for being unable to
tile only a portion of a texture.

I think there's a Linux OpenGL tool that will let me force anything
being rendered in OpenGL to be in wireframe... I'll snoop a bit and
confirm...
Post by Robert Osfield
Robert.
Post by Jeremy L. Moles
I've tried googling and asking this question in various other OpenGL
places with no success--so I figured I'd try here, since I know there
are some OpenGL gurus around. In fact, I was told in #opengl on Freenode
it wasn't possible, but I doubt it sense people have been doing this for
ages used fixed-function OpenGL.
I'm working on a UI toolkit using native OSG objects (no weird
"gluecode" or external library) and have come across something I can't
readily get the answer to.
Imagine an interface "window"; at the minimum you'll have about 9
- upper left and right corners
- lower left and right corners
- top, left, bottom, and right "bars"
- center
Now imagine a texture you want to use as the window's "skin." Ideally,
you'll load an image into the texture and position the TexCoords so that
you can create the illusion of having a true, decorated and composed
window. This is fairly straightforward in concept except for one aspect.
Lets say you want to texture the "top bar" region of your window. Well,
by default, unless this portion of your image (or skin) is cleverly
positioned in the texture itself, there's really no way I know of to
"tile" it across the geometry. You can stretch it across, but this is
often quite ugly.
My question: is it possible in OpenGL to somehow manipulate the texture
matrix (or something else) to only operate on a "sub-region" of a
texture such that you can tile just that portion? CEGUI does this
somehow, but it's API is so abstracted I can't really track it's
implementation down.
I _know_ it's possible using a GLSL shader, but at this point it's
really academic for me to find out how to do it otherwise, I know game
makers have been doing this for years w/out shaders, and it's really
bugging me to find out how! :) Any advice or guidance on the issue would
be enormously appreciated...
_______________________________________________
osg-users mailing list
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
Loading...