I want to have a 'decal' applied to some of my objects, for example a badge
on a ferrari. I want to be able to do this using textures, so I would have
my bonnet (or hood in America) as a 3D model, and I want to place the
ferrari texture on the required place. I have made a small program which
will update the textures in real time with mouse movements. What I have
changing is (Xmin, Xmax, Ymin, Ymax) which I would like to use to move the
texture around. The problem is, that I cant seem to get them to move in any
logical order. I am using:
GLfloat lScoords[4] = {XMin, XMax, 0.0f, 0.0f};
GLfloat lTcoords[4] = {YMin, YMax, 0.0f, 0.0f};
glTexGenfv(GL_T, GL_EYE_PLANE, lTcoords);
glTexGenfv(GL_S, GL_EYE_PLANE, lScoords);
I have played about with placing the XMin etc in different locations within
the coord arrays and I have attempted to understand the formula on MSDN, but
to no luck. Is there a nice tutorial on these coords, or can somebody tell
me what I should do so that the placing of the texture is more logical?
Thanks
Allan
|
|
0
|
|
|
|
Reply
|
Allan
|
2/6/2004 3:29:43 PM |
|
Allan Bruce wrote:
>
> GLfloat lScoords[4] = {XMin, XMax, 0.0f, 0.0f};
> GLfloat lTcoords[4] = {YMin, YMax, 0.0f, 0.0f};
> glTexGenfv(GL_T, GL_EYE_PLANE, lTcoords);
> glTexGenfv(GL_S, GL_EYE_PLANE, lScoords);
>
> I have played about with placing the XMin etc in different locations within
> the coord arrays and I have attempted to understand the formula on MSDN, but
> to no luck. Is there a nice tutorial on these coords, or can somebody tell
> me what I should do so that the placing of the texture is more logical?
>
My advice: Don't use TexGen. It's slow, inflexible,
and causes more trouble than it's worth. It's also
not performing any real magic - just four multiplies
and three adds (scalar product of the vertex with
the plane equation).
T = lTcoords[0]*vertex[0] + ... + lTcoords[3]*vertex[3];
The only real reasons for using linear TexGen are
to save memory by not storing texture coordinates
or to apply texture to things where you can't modify
the source code to add texturing.
If you're not doing this then you'll be much better
off generating the S and T coordinates yourself.
--
<\___/> For email, remove my socks.
/ O O \
\_____/ FTB. Why isn't there mouse-flavored cat food?
|
|
0
|
|
|
|
Reply
|
fungus
|
2/6/2004 3:49:57 PM
|
|
>
> My advice: Don't use TexGen. It's slow, inflexible,
> and causes more trouble than it's worth. It's also
> not performing any real magic - just four multiplies
> and three adds (scalar product of the vertex with
> the plane equation).
>
> T = lTcoords[0]*vertex[0] + ... + lTcoords[3]*vertex[3];
>
> The only real reasons for using linear TexGen are
> to save memory by not storing texture coordinates
> or to apply texture to things where you can't modify
> the source code to add texturing.
>
> If you're not doing this then you'll be much better
> off generating the S and T coordinates yourself.
>
>
How do I specify my own coords? Are there any tutorials for this?
I have it all working with S&T coords but I have the rest of the surface
affected by the texture. The red book says this will happen with GL_CLAMP
and recommends using borders. I tried that but as soon as I use borders, My
lighting goes. Is this because I dont use 32 bit textures?
Anyway, I`m intersted in applying the texture coords myself, so any links
will be helpful.
Thanks
|
|
0
|
|
|
|
Reply
|
Allan
|
2/6/2004 5:19:53 PM
|
|
Allan Bruce wrote:
>>My advice: Don't use TexGen. It's slow, inflexible,
>>and causes more trouble than it's worth. It's also
>>not performing any real magic - just four multiplies
>>and three adds (scalar product of the vertex with
>>the plane equation).
>>
>>T = lTcoords[0]*vertex[0] + ... + lTcoords[3]*vertex[3];
>>
>>The only real reasons for using linear TexGen are
>>to save memory by not storing texture coordinates
>>or to apply texture to things where you can't modify
>>the source code to add texturing.
>>
>>If you're not doing this then you'll be much better
>>off generating the S and T coordinates yourself.
>>
>>
>
>
> How do I specify my own coords? Are there any tutorials for this?
>
Just like vertices:
glTexCoord2f(s,t);
Put one before each call to glVertex().
> I have it all working with S&T coords but I have the rest of the surface
> affected by the texture. The red book says this will happen with GL_CLAMP
> and recommends using borders.
Just to be clear, the "border" they refer to is the
constant border color you set with glTexParameter().
There's another kind of texture border but you don't
want that...
Set the border to a color with alpha=0 and it will
cut off nicely at the edges.
> I tried that but as soon as I use borders, My
> lighting goes. Is this because I dont use 32 bit textures?
No. It must be something else.
--
<\___/> For email, remove my socks.
/ O O \
\_____/ FTB. Why isn't there mouse-flavored cat food?
|
|
0
|
|
|
|
Reply
|
fungus
|
2/6/2004 8:12:27 PM
|
|
> >
> >
> > How do I specify my own coords? Are there any tutorials for this?
> >
>
> Just like vertices:
>
> glTexCoord2f(s,t);
>
> Put one before each call to glVertex().
>
I do this for quads, but this doesnt work for applying a large texture over
several hundred polygons, e.g. a sphere. That is why I was using S&T
coords. Is there an alternative to S&T coords for my purpose?
Thanks
Allan
|
|
0
|
|
|
|
Reply
|
Allan
|
2/6/2004 8:42:19 PM
|
|
Allan Bruce wrote:
>>>
>>>How do I specify my own coords? Are there any tutorials for this?
>>
>>Just like vertices:
>>
>>glTexCoord2f(s,t);
>>
>>Put one before each call to glVertex().
>>
> I do this for quads, but this doesnt work for applying a large texture over
> several hundred polygons, e.g. a sphere. That is why I was using S&T
> coords. Is there an alternative to S&T coords for my purpose?
> Thanks
> Allan
No, it does work. the texture coordinates are just a way to map the 2D texture
image to your 3D vertices, if you have let's say a plane that is comprised of 4
quads like this (warning, ascii diagram approaching)
v0---v1---v2
| | |
| | |
v3---v4---v5
| | |
| | |
v6---v7---v8
where the texture coordinates are as follows:
v0: (0, 1)
v1: (0.5, 1)
v2: (1, 1)
v3: (0, 0.5)
v4: (0.5, 0.5)
v5: (1, 0.5)
v6: (0, 0)
v7: (0.5, 0)
v8: (1, 0)
Then your texture will span the entire plane, no matter how many polygons you
have in there.
-- Nuclear / the Lab --
|
|
0
|
|
|
|
Reply
|
John
|
2/7/2004 12:50:12 AM
|
|
Allan Bruce wrote:
>
> I do this for quads, but this doesnt work for applying a large texture over
> several hundred polygons, e.g. a sphere. That is why I was using S&T
> coords.
>
Yes it does.
I promise you that TexGen isn't doing anything clever,
all it does is blindly multiply the vertex coordinate
by the plane equation. It doesn't know if it'a a sphere,
a quad or anything else.
--
<\___/> For email, remove my socks.
/ O O \
\_____/ FTB. Why isn't there mouse-flavored cat food?
|
|
0
|
|
|
|
Reply
|
fungus
|
2/7/2004 2:02:30 AM
|
|
yes, you can modify the texture matrix to project your decal onto your hood,
s&t coords is just a simpler method to using the texture matrix. I use it
all the time to map my terrain texture and decals in my terrain engine.
Putting it onto a car is a bit more difficult. when multiplied by the
vectors of your car you want the resulting decals position uv's to be be
between 0 and 1.
so if your hoods coords where you want the decal to be are
x(-100,50,20)-----------x(100,50,20)
| |
| |
| |
| |
| |
x(-100,50,180)-----------x(100,50,180)
width = 200
length = 160
you want to have uv's of say
x(0,0)-----------x(0,1)
| |
| |
| |
| |
| |
x(1,0)-----------x(1,1)
assume your hood is flat and perpendicular to the y coords, so you want to
map to x and z.
U= v.x * s.x + v.y*s.y + v.z*s.z + s.w
V= v.x * t.x + v.y*t.y + v.z*tz + t.w
so what you want is to divide by size your covering the decal with and
offset by position of the top vertex
GLfloat lScoords[4] = {1.0f/200, 0,0, 100/200};
GLfloat lTcoords[4] = (0, 0, 1.0f/160, -20/160};
hopefully that will give you a better idea of how to use coord generation,
remember to clamp your texture so it doesn't repeat the textue over again
and if you draw the entire model with the decal, it will apear on the cars
bottom as well as on the hood (try and isolate the diffrent parts of the car
for rendering).
The same effect can be achieved by using the texture matrix ( but you have
take the view matrix into account)
good luck
Ernest
----- Original Message -----
From: "Allan Bruce" <allanmb@TAKEAWAYf2s.com>
Newsgroups: comp.graphics.api.opengl
Sent: Friday, February 06, 2004 3:42 PM
Subject: Re: understanding S and T co-ords
> > >
> > >
> > > How do I specify my own coords? Are there any tutorials for this?
> > >
> >
> > Just like vertices:
> >
> > glTexCoord2f(s,t);
> >
> > Put one before each call to glVertex().
> >
>
> I do this for quads, but this doesnt work for applying a large texture
over
> several hundred polygons, e.g. a sphere. That is why I was using S&T
> coords. Is there an alternative to S&T coords for my purpose?
> Thanks
> Allan
>
>
|
|
0
|
|
|
|
Reply
|
Ernest
|
2/9/2004 8:09:07 PM
|
|
Thanks, I`ll give this a bash
Allan
"Ernest" <ErnestSzoka(nospam)@hotmail.com> wrote in message
news:HPRVb.2828$lK.196528@news20.bellglobal.com...
> yes, you can modify the texture matrix to project your decal onto your
hood,
> s&t coords is just a simpler method to using the texture matrix. I use it
> all the time to map my terrain texture and decals in my terrain engine.
> Putting it onto a car is a bit more difficult. when multiplied by the
> vectors of your car you want the resulting decals position uv's to be be
> between 0 and 1.
>
> so if your hoods coords where you want the decal to be are
>
> x(-100,50,20)-----------x(100,50,20)
> | |
> | |
> | |
> | |
> | |
> x(-100,50,180)-----------x(100,50,180)
>
> width = 200
> length = 160
>
> you want to have uv's of say
>
> x(0,0)-----------x(0,1)
> | |
> | |
> | |
> | |
> | |
> x(1,0)-----------x(1,1)
>
> assume your hood is flat and perpendicular to the y coords, so you want to
> map to x and z.
> U= v.x * s.x + v.y*s.y + v.z*s.z + s.w
> V= v.x * t.x + v.y*t.y + v.z*tz + t.w
>
> so what you want is to divide by size your covering the decal with and
> offset by position of the top vertex
> GLfloat lScoords[4] = {1.0f/200, 0,0, 100/200};
> GLfloat lTcoords[4] = (0, 0, 1.0f/160, -20/160};
>
> hopefully that will give you a better idea of how to use coord generation,
> remember to clamp your texture so it doesn't repeat the textue over again
> and if you draw the entire model with the decal, it will apear on the cars
> bottom as well as on the hood (try and isolate the diffrent parts of the
car
> for rendering).
>
> The same effect can be achieved by using the texture matrix ( but you have
> take the view matrix into account)
>
> good luck
>
> Ernest
>
>
>
>
>
> ----- Original Message -----
> From: "Allan Bruce" <allanmb@TAKEAWAYf2s.com>
> Newsgroups: comp.graphics.api.opengl
> Sent: Friday, February 06, 2004 3:42 PM
> Subject: Re: understanding S and T co-ords
>
>
> > > >
> > > >
> > > > How do I specify my own coords? Are there any tutorials for this?
> > > >
> > >
> > > Just like vertices:
> > >
> > > glTexCoord2f(s,t);
> > >
> > > Put one before each call to glVertex().
> > >
> >
> > I do this for quads, but this doesnt work for applying a large texture
> over
> > several hundred polygons, e.g. a sphere. That is why I was using S&T
> > coords. Is there an alternative to S&T coords for my purpose?
> > Thanks
> > Allan
> >
> >
>
>
|
|
0
|
|
|
|
Reply
|
Allan
|
2/9/2004 8:49:18 PM
|
|
|
8 Replies
102 Views
(page loaded in 0.102 seconds)
Similiar Articles: GL_POINTS & Textures - comp.graphics.api.openglJust browse the c.g.a.opengl archives, to understand why. Best thing is to put ... specification: | The following formula is used to evaluate the s and t coordinates ... Conversion from Cartesian Coordinates to Matlab Coordinates - comp ...... to know how to do the conversion to Matlab co-ord system given a set of co-ords ... > > Replies will be helpful > > Thanks I do not understand this "structuring element". Numerical solution of Laplace's equation in cylindrical ...Maybe I just didn't understand your point, but I'll be attempting to get ... Problem with 3d to 2d projection - comp.soft-sys.matlab Let's say that your (x,y,z) coordinates ... Surface Plot - comp.soft-sys.matlab... with the following attributes X(m), Y(m), x(m/s), y(m/s), z(m/s) Where X and Y are position coordinates ... I don't understand how to do this. I know this is a pretty ... screen coordinates and mouse event - comp.graphics.api.opengl ...... point, my position is expressed in pixel and I don't know > how to convert in the coordinates in ... Now i'm trying to understand if it's possible to locate the 3d coordinate ... 3D coordinate system - comp.cad.solidworksHey all I sit and try to understand a 3D coordinate ... helpless and simply cry about how you don't like SW's ... Actually, I'm trying to use polar coordinates (r, phi, t ... Projection-state of gl_Vertex in GLSL - comp.graphics.api.opengl ...I do believe that's the way NGs work. > >> I specifically don't understand the last part of the sentence ... glVertex and the GLSL gl_Vertex hold the same coordinates ... glOrtho & gluUnProject troubles... - comp.graphics.api.opengl ...Ok here's the trouble: I don't understand why panning works great in the Front view ... oP[1]; } } I guess this works because gluUnProject return object coordinates so I ... 3D Texture Constraints - comp.graphics.api.openglMy texture coordinates are all in [0,1] and I'm using GL_CLAMP_TO_EDGE, so I don't ... I'm using 3D textures in a raycasting application that uses GLSL. > I understand ... Draw major and minor axes on ellipse - comp.soft-sys.matlab ...On another issue, how do I determine the polar coordinates ... the ellipse is at an angle of rotation, it's not ... I don't understand what the difficulty is in your first ... Understanding GPS Coordinates - Captain's Blog SCUBA Blog - Dive SpotsUnderstanding GPS Coordinates Posted Mar 15, 2006 @ 09:00 PM EST by raf. Without a doubt, the most commonly asked question I get from divers has to do with reading ... Geographic coordinate system - Wikipedia, the free encyclopediaA geographic coordinate system is a coordinate system that enables every location on the Earth to be specified by a set of numbers and/or letters. The coordinates are ... 7/25/2012 9:36:24 AM
|