PDA

View Full Version : How to display the texture coordinate of an object?



reader1
05-28-2015, 07:53 AM
Say the object has n vertices and after a series of transf it has displayed on the screen.
then how to display their texture coordinates of these n vertices? or print out their list value?

Agent D
05-28-2015, 02:56 PM
The simplest way to visualize the texture coordiantes is to write them out as color in the fragment shader.

For 2D texture coordinates, the s component ends up in the red channel and the t component in the green
channel. More redish color means big s and rather small t, more green means small s and large t. Yellowish
colors means s and t are roughly equal with dark yellow being small values and bright yellow large values.

You can see the smooth transitions of the texture coordinates as they are interpolated over the triangle areas.



Of course, you could also use the texture coordinates to map a texture image onto the mesh. Something like a
debug texture with a regular grid on it.

reader1
05-28-2015, 05:26 PM
Thanks, I wish to get their values coordiinates, not color. ntor take account of interpolate, either at present.
could you show a couple of code examples? or where can download that?

GClements
05-29-2015, 01:46 AM
If you want to capture the output of the vertex shader, use transform feedback mode (https://www.opengl.org/wiki/Transform_Feedback).

If you want something else, you'll need to clarify your question.

reader1
05-29-2015, 04:09 AM
If you want to capture the output of the vertex shader, use transform feedback mode (https://www.opengl.org/wiki/Transform_Feedback).

If you want something else, you'll need to clarify your question.
Nor vertex shader output, either. just want to get the vertices' texture coordinate values. This likes this,
A group of vertices of an object, through project to display on scteen.
glMatrixMode(GL_PROJECT); gkPerspective(...); glLoadIdentity();
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
....then input vertices coordinate data........
ater cpu or gpu calculate, the object is projected on screen, Then how to get the its texture coordinate values?

reader1
05-29-2015, 06:01 AM
If derive individually, I can use Mm*Mp*vec4f(...)^T; but how to get it from api command?

Alfonse Reinheart
05-29-2015, 08:48 AM
Texture coordinates are not in any way affected by the projection or modelview matrices (the texture matrices can, but you didn't say if you're setting them). So the texture coordinates will simply be whatever you passed.

The vertex positions are affected by the matrices. And yes, you can transform the positions in the way you describe.

Also:


glMatrixMode(GL_PROJECT); gkPerspective(...); glLoadIdentity();

The glLoadIdentity() here undoes the perspective projection matrix setup.

reader1
05-29-2015, 06:06 PM
Texture coordinates are not in any way affected by the projection or modelview matrices (the texture matrices can, but you didn't say if you're setting them). So the texture coordinates will simply be whatever you passed.

The vertex positions are affected by the matrices. And yes, you can transform the positions in the way you describe.
.
Im aftraid, I make no sense of it. would u please show a sample?


lso:


glMatrixMode(GL_PROJECT); gkPerspective(...); glLoadIdentity();

The glLoadIdentity() here undoes the perspective projection matrix setu
Most of codes used to invoke it. it will calibrate center position.

reader1
05-29-2015, 07:04 PM
btw, don't show us how a sphere, cycline or cube map to texture coordinate. I know this mapping.

Alfonse Reinheart
05-29-2015, 10:30 PM
Im aftraid, I make no sense of it. would u please show a sample?

A sample of what? You asked how to get the texture coordinates you're using to render something. I just said that, unless you're using a texture matrix or texture coordinate generation, you already have those texture coordinates. You had to have them, because you were the one who passed them to OpenGL. And unless you're using a texture matrix or coordinate generation, those texture coordinates will be used as is.

Now, if you're concerned that what you think you're passing isn't what OpenGL's actually getting, that's one thing. But Agent D's suggestion to simply render the texture coordinate values as colors would be sufficient to determine if the values are at least approximately what they ought to be.

Now, if you are using a texture matrix or texture coordinate generation (which should have been mentioned, since these are fairly rarely used features), that's another matter entirely. Your only recourse is to read the OpenGL specification's sections on whatever generation method you're using, and mirror that mathematics in your code.


Most of codes used to invoke it. it will calibrate center position.

No, it does not. Other code call glLoadIdentity before calling gluPerspective. That's the important point. It's like doing this:



a = 5;
a = 0;


`a` isn't 5 after this code is executed.

reader1
05-30-2015, 01:55 AM
A sample of what? You asked how to get the texture coordinates you're using to render something. I just said that, unless you're using a texture matrix or texture coordinate generation, you already have those texture coordinates. You had to have them, because you were the one who passed them to OpenGL. And unless you're using a texture matrix or coordinate generation, those texture coordinates will be used as is.

Now, if you're concerned that what you think you're passing isn't what OpenGL's actually getting, that's one thing. But Agent D's suggestion to simply render the texture coordinate values as colors would be sufficient to determine if the values are at least approximately what they ought to be.

Now, if you are using a texture matrix or texture coordinate generation (which should have been mentioned, since these are fairly rarely used features), that's another matter entirely. Your only recourse is to read the OpenGL specification's sections on whatever generation method you're using, and mirror that mathematics in your code.

ecuted.

I seem to misunderstand or be misled by some articles copied from net. or may confused by these names, texture coor, d, tex map coord vertex tex coord....
now I think I make sense of them.



No, it does not. Other code call glLoadIdentity before calling gluPerspective. That's the important point. It's like doing this:



a = 5;
a = 0;


`a` isn't 5 after this code is ex
I pay no attention to their order, is that mportatnt?
identify matrix is only unit matrix, then M*E=M = E*M; they are all the same no matter left multify or right.
your code example is quit incorrect,

Agent D
05-30-2015, 07:45 AM
glLoadIdenty does not multiply with the identity matrix (that would be completely pointless), it overwrites the current matrix with the
identity matrix. If you set up a perspective projection matrix and then call glLoadIdentity, it overwrites your perspective matrix with the
identity matrix.

reader1
05-30-2015, 07:26 PM
glLoadIdenty does not multiply with the identity matrix (that would be completely pointless), it overwrites the current matrix with the
identity matrix. If you set up a perspective projection matrix and then call glLoadIdentity, it overwrites your perspective matrix with the
identity matrix.
You are right. It replaces the current matrix. but more efficient than call Identity matrix in some case.

reader1
05-30-2015, 07:29 PM
returen to our topic. if opgl uses void glTexGen{if}(GLenum coord,GLenum pname,TYPE param) to produce automatiocally the tex coord.
How to print their value on the window?

Alfonse Reinheart
05-30-2015, 10:23 PM
If you don't have access to NV_transform_feedback (which does allow for capturing fixed-function vertex processing outputs), then you will have to do what I said earlier. You have to look up exactly what the glTexGen functions are telling OpenGL to do per-vertex, then replicate that mathematics in your code.

reader1
05-31-2015, 07:10 AM
If you don't have access to NV_transform_feedback (which does allow for capturing fixed-function vertex processing outputs), then you will have to do what I said earlier. You have to look up exactly what the glTexGen functions are telling OpenGL to do per-vertex, then replicate that mathematics in your code.
That means there is no corresponding api to the situation. I have to repeat the whole process the glTexGen did? (for glTexGen() is void type.)

Yet, can we get the coordinate of the vertex at this state?(by some api)

reader1
05-31-2015, 07:27 AM
but glGetTexGen — return texture coordinate generation parameters
seem to do the trick.

Alfonse Reinheart
05-31-2015, 08:50 PM
That means there is no corresponding api to the situation. I have to repeat the whole process the glTexGen did? (for glTexGen() is void type.)

Yet, can we get the coordinate of the vertex at this state?(by some api)

No.

OpenGL is designed for processing information in one direction: from the user to the screen. OpenGL information processing is meant to flow in that direction, and all OpenGL processing is intended to support this idea.

Getting the texture coordinates used for a particular vertex is not something that fixed-function OpenGL can do.


but glGetTexGen — return texture coordinate generation parameters
seem to do the trick.

Seems to do what trick? You asked for texture coordinates. That function gets you texture coordinate generation parameters. If that "seems to do the trick", then "the trick" was poorly explained.

GClements
06-01-2015, 03:57 AM
Getting the texture coordinates used for a particular vertex is not something that fixed-function OpenGL can do.

glRenderMode(GL_FEEDBACK) will do that, sort of. However:

* It reports "processed" geometry. Culled primitives aren't reported, if quads or polygons are broken into triangles, it may report the triangles rather than the original primitives.

* I wouldn't bet heavily on it actually working on modern hardware.

If you want to do a lot of this sort of thing, you're probably better off using shaders and transform feedback mode.

reader1
06-01-2015, 06:42 AM
No.

OpenGL is designed for processing information in one direction: from the user to the screen. OpenGL information processing is meant to flow in that direction, and all OpenGL processing is intended to support this idea.

Getting the texture coordinates used for a particular vertex is not something that fixed-function OpenGL can do.
.
one or bidirection is not a problem. how that it can cope with memory, we can read out it from it.
and now that api can produce automatically texture coordinates it must be able to find the corresponding relation to a special vertex. As the object is made of a series of vertices.


Seems to do what trick? You asked for texture coordinates. That function gets you texture coordinate generation parameters. If that "seems to do the trick", then "the trick" was poorly explained

certainly seems to find the tex values.So, what is tex coord geneation params? Does it include coordinate value? or we can solve the equation to get the value?

reader1
06-01-2015, 06:50 AM
glRenderMode(GL_FEEDBACK) will do that, sort of. However:

* It reports "processed" geometry. Culled primitives aren't reported, if quads or polygons are broken into triangles, it may report the triangles rather than the original primitives.

* I wouldn't bet heavily on it actually working on modern hardware.

If you want to do a lot of this sort of thing, you're probably better off using shaders and transform feedback mode.

So it is. shader has such feedback channel which can send the vertex data back to vertex processor,

reader1
06-01-2015, 07:06 AM
Getting the texture coordinates used for a particular vertex is not something that fixed-function OpenGL can do.
Now that metioned the fixed-pipe, I want to know when this api delivers the data to the piple or shader to process?
and can this api use in vertex shader?

GClements
06-01-2015, 07:48 AM
So, what is tex coord geneation params? Does it include coordinate value?
glGetTexGen() returns one of the parameters (mode or plane) for the equations which map vertex coordinates to texture coordinates (i.e. whatever values you passed to glTexGen() in the first place).

If you want the actual texture coordinates, you need to evaluate those equations yourself, using the generation parameters, the vertex coordinates (either object-space for object-linear mode or eye-space for the other modes), and possibly the vertex normal (for the sphere map, reflection map or normal map modes).

The equations used to generate texture coordinates from vertex coordinates are given in section 12.1.3 of the OpenGL 4.5 compatibility profile specification. Most of them are also given in the glTexGen reference page (https://www.opengl.org/sdk/docs/man2/xhtml/glTexGen.xml), although the behaviour of the normal map and reflection map modes isn't given there (they use the same equations as the sphere map mode, but the generated texture coordinate is the eye-space normal or the reflection vector, respectively).

reader1
06-01-2015, 06:28 PM
glGetTexGen() returns one of the parameters (mode or plane) for the equations which map vertex coordinates to texture coordinates (i.e. whatever values you passed to glTexGen() in the first place).

If you want the actual texture coordinates, you need to evaluate those equations yourself, using the generation parameters, the vertex coordinates (either object-space for object-linear mode or eye-space for the other modes), and possibly the vertex normal (for the sphere map, reflection map or normal map modes).

The equations used to generate texture coordinates from vertex coordinates are given in section 12.1.3 of the OpenGL 4.5 compatibility profile specification. Most of them are also given in the glTexGen reference page (https://www.opengl.org/sdk/docs/man2/xhtml/glTexGen.xml), although the behaviour of the normal map and reflection map modes isn't given there (they use the same equations as the sphere map mode, but the generated texture coordinate is the eye-space normal or the reflection vector, respectively).


I skimed the function, and I wonder what is the reference plane acting? 9for either the mode of obj-linear or eye space), what role is it?

GClements
06-02-2015, 05:46 AM
I skimed the function, and I wonder what is the reference plane acting? 9for either the mode of obj-linear or eye space), what role is it?
For object-linear or eye-linear mode, each texture coordinate is the "distance" of the vertex from the plane, i.e. the dot-product of vertex position (in object space or eye space) with the plane coefficients.

From the reference page:


If the texture generation function is GL_OBJECT_LINEAR, the function

g = p1 xo + p2 yo + p3 zo + p4 wo

is used, where g is the value computed for the coordinate named in coord, p1, p2, p3 and p4 are the four values supplied in params, and xo, yo, zo and wo are the object coordinates of the vertex.


Eye-linear is similar except that both the coordinates and the plane are transformed to eye space (the plane is transformed by the model-view matrix in effect at the time of the glTexGen() call, i.e. it's specified in object space but stored in eye space).

reader1
06-02-2015, 06:14 AM
For object-linear or eye-linear mode, each texture coordinate is the "distance" of the vertex from the plane, i.e. the dot-product of vertex position (in object space or eye space) with the plane coefficients.

From the reference page:


Eye-linear is similar except that both the coordinates and the plane are transformed to eye space (the plane is transformed by the model-view matrix in effect at the time of the glTexGen() call, i.e. it's specified in object space but stored in eye space).

That's what I ask, the plane is what? will it contain texture or equal to screen position? or something?
is it arbitrary or not?

GClements
06-02-2015, 06:40 AM
That's what I ask, the plane is what?
It's a plane, i.e. a set of points satisfying the equation p1.x+p2.y+p3.z+p4.w=0. Its normal is the vector (p1,p2,p3) and p4 determines its distance from the origin. A vertex which lies on the plane (i.e. which satisfies that equation) will have the corresponding generated texture coordinate equal to zero. More generally, the generated texture coordinate for a vertex is equal to its signed "distance" to the plane (i.e. the value p1.x+p2.y+p3.z+p4.w).

Each of the 4 planes (s,t,r,q) is effectively one row of a matrix which transforms 4D vertex coordinates to 4D texture coordinates (transforming a vector by a matrix is essentially a sequence of dot products; each component of the resulting vector is the dot product between one row of the matrix and the original vector).

reader1
06-02-2015, 06:46 AM
I asked "what is the reference plane acting? 9for either the mode of obj-linear or eye space), what role is it?" seem too uncertain to make sense of it.
How to explain correctly in English? in order not to misunderstand.
The plane, it acts as what? How to define the plane? The distance is only a number, (despite it can be served as a vector in physics), but tex coord represents two values, s and t. how will the opgl derive the s,t next?

GClements
06-02-2015, 07:07 AM
The distance is only a number, (despite it can be served as a vector in physics), but tex coord represents two values, s and t. how will the opgl derive the s,t next?
Each texture coordinate (i.e. each component (s, t, r, or q) of the texture coordinates) is generated separately.

You can enable or disable generation of each component individually, you can (and usually do) specify a different plane for each component, you can even specify a different mode for each component (although I can't think of a situation where that would make sense).

This is why the first parameter to all forms of glTexGen (https://www.opengl.org/sdk/docs/man2/xhtml/glTexGen.xml) is the coordinate: either GL_S, GL_T, GL_R, or GL_Q.

If you want to generate both s and t, you need to specify one plane for the s coordinate and one plane for the t coordinate. You also need glEnable(GL_TEXTURE_GEN_S) and glEnable(GL_TEXTURE_GEN_T).

reader1
06-02-2015, 07:33 AM
Each texture coordinate (i.e. each component (s, t, r, or q) of the texture coordinates) is generated separately.

You can enable or disable generation of each component individually, you can (and usually do) specify a different plane for each component, you can even specify a different mode for each component (although I can't think of a situation where that would make sense).

This is why the first parameter to all forms of glTexGen (https://www.opengl.org/sdk/docs/man2/xhtml/glTexGen.xml) is the coordinate: either GL_S, GL_T, GL_R, or GL_Q.

If you want to generate both s and t, you need to specify one plane for the s coordinate and one plane for the t coordinate. You also need glEnable(GL_TEXTURE_GEN_S) and glEnable(GL_TEXTURE_GEN_T).
then, what is critial to specify " the plane" for either s or t?

reader1
06-02-2015, 07:44 AM
I also confuse this GL_S,T,...generally we define a coordiante by (s,t...), hardly define only one paramter for point or a vector, if there is only one variable, we can define others as constants.
;ole this, x=3, means either a line which is parallel to y axis by a 3 distance or a plane which is parallel to yoz plane by 3.... they are not a point.
howevr, what we deal with is point to point map,

reader1
06-03-2015, 07:05 PM
So the plane is a core, What does it do? How to choose it?

reader1
06-04-2015, 06:21 PM
It seems it is a problem not to answer easily? or Have I not described the issue clearly or properly? or it is an easy question, needn't to answer?

GClements
06-04-2015, 06:56 PM
I don't see how I can explain it any more clearly.

Have you tried reading the glTexGen reference page (or the specification)?

reader1
06-05-2015, 12:28 AM
I don't see how I can explain it any more clearly.

Have you tried reading the glTexGen reference page (or the specification)?

Thanks, I think I might have not expreseds clearly or positively what I ask or what I want to knpw.
I read that and I know the equation and how to resolve it. but I don't know the plane's positoin. If you donlt know the plane, you will not get the equation. How do you make up it's parameters?(a,b,c), for a fixed vertex, different plane will get differnt distance.
The reference has not illustrated where the plane is. and how to acquire its paramters.
Is the plane the relative projection plane?
What is GL_OBJECT_PLANE? where is it? is it screen coordinate?

reader1
06-05-2015, 12:46 AM
In the math reference, there is
Your code would look something like this
for(i=0; i<total; i++)
{
myTexCoord[i].s = dot4D(myVertex[i], myPlane_S);
myTexCoord[i].t = dot4D(myVertex[i], myPlane_T);
}
Where is myPlane_st? IZ It image plane(project plane)? I guess it is. right?
This is calculated on cpu, if we move it to vertex shader, will it calculate on gpu?

GClements
06-05-2015, 04:00 AM
I read that and I know the equation and how to resolve it. but I don't know the plane's positoin. If you donlt know the plane, you will not get the equation. How do you make up it's parameters?(a,b,c), for a fixed vertex, different plane will get differnt distance.
The reference has not illustrated where the plane is. and how to acquire its paramters.

The plane's parameters are specified by calling glTexGen() with pname equal to GL_OBJECT_PLANE or GL_EYE_PLANE.

In the case of GL_OBJECT_PLANE, the parameters can be retrieved via glGetTexGen() with pname equal to GL_OBJECT_PLANE.

In the case of GL_EYE_PLANE, the plane is specified in object space but transformed to eye space based upon the model-view matrix at the time of the glTexGen() call. Calling glGetTexGen() with pname equal to GL_EYE_PLANE.returns the transformed (eye-space) parameters rather than the original values passed to glTexGen().

The plane's normal is (p1,p2,p3). If you want the plane to pass through a point x,y,z,w then p4 must be set to -(p1*x+p2*y+p3*z)/w.


This is calculated on cpu, if we move it to vertex shader, will it calculate on gpu?
If texture coordinate generation is enabled, the calculation will typically be performed on the GPU. glTexGen() and glEnable(GL_TEXTURE_GEN_S) etc are part of the fixed-function pipeline; if a vertex shader is active, they have no effect.

reader1
06-05-2015, 04:56 AM
The plane's parameters are specified by calling glTexGen() with pname equal to GL_OBJECT_PLANE

In the case of GL_OBJECT_PLANE, the parameters can be retrieved via glGetTexGen() with pname equal to GL_OBJECT_PLANE.

In the case of GL_EYE_PLANE, the plane is specified n
Thanks, That's what I want to know. The plane, we aim mainly at GL_OBJECT_PLANE. ignore other issues.
I know it locates at object system. but what is its coordinate? where is it in this coord sys?

reader1
06-05-2015, 05:49 AM
for example, there is a vertex A(...); How do you define the PLANE? Is it the project screen? or something you point arbitrarily?
plane, plane, just ask the plane, not others thing.

for example, if you point it as (0, 0, 3, 0), how do you define the 3? if it were not 3, the distance would be different, then get different tex coord. this is question. How to assign the plane positoin?

reader1
06-05-2015, 07:05 PM
or Overtate speaking, if there is a vertex position is at The Empire Building, and there will be different effect of mapping, if the GL_OBJECT_PLANE is in Washington, or eiher in Moscow, or in Berlin etc. How shall we chooode the plane? if it were project surface, we may choose it in Beijing, or in Paris depend on the effect we wish?