PDA

View Full Version : Texture start/stop inside strips and fans



Yigal Eilam
03-21-2002, 02:13 AM
Hi,
I'm rendering a surface using strips and fans
There is a texture on it so I call glTextureCoord before
each glVertex
Now, for some of the vertices I do NOT want to draw
the texture (if it is hidden from a plane on which the
texture is defined).
What if I don't call glTextureCoord on some of the vertices? What if it is during a strip or a fan?
Any other way to stop the texture rendering (and start
again) while inside a strip or a fan?
Thanks for any help.

LangFox
03-21-2002, 02:19 AM
Do you try glDisable(GL_TEXTURE_2D) and glEnable(GL_TEXTURE_2D)?

Eric
03-21-2002, 02:25 AM
Originally posted by Yigal Eilam:
What if I don't call glTextureCoord on some of the vertices?

OpenGL is a state machine. If texturing is enabled and you don't call glTexCoord before issueing a glVertex command, the vertex will use whatever texture coord has been set before.


Originally posted by Yigal Eilam:
What if it is during a strip or a fan?
Any other way to stop the texture rendering (and start
again) while inside a strip or a fan?
Thanks for any help.

Texturing is enabled/disabled using glEnable/glDisable. You cannot call these functions between glBegin/glEnd (see the specs). Hence you cannot stop texturing in the middle of a strip or a fan.

If one primitive shouldn't be textured, then it should be rendered separately with texturing disabled.

BTW, it doesn't make sense to disable texturing for one vertex in a triangle: how is OpenGL supposed to interpolate the texture coordinate accross the triangle if you "disable" texturing for one vertex ?

Regards.

Eric

MikeC
03-22-2002, 11:10 AM
Could you post a more concrete description of what it is you're trying to draw? Like Eric, I'm having a hard time understanding why you'd want to do this. There might be ways to approximate what you want, but not without more detail.

Yigal Eilam
03-23-2002, 10:15 PM
What I have is a 3d surface and a texture on a plane. I want to draw only those parts of the surface which are visible if looking from the plane’s normal direction.
Consider the following similar example: You have a sphere representing earth and a picture of earth taken from the moon. Now you want to have the picture only on the side that is visible from the moon and keep the other half with its "native" polygonal shading.
If it's a sphere it maybe simple to draw it as two halves but in my case I do not know in advance which triangles are visible or not from the plane’s direction and they maybe even mixed up in the same strips or fans.
Hope the problem is clearer now.

Moshe Nissim
03-24-2002, 12:15 AM
You can use glTexEnv with GL_OBJECT_LINEAR or GL_EYE_LINEAR, and two texture units to acheive what you described.
One unit will do standard 2d texturing
The second texture unit will do 1d texturing with the coordinate computed with the glTexEnv to 'white out' the 2d texture unit output when needed

Yigal Eilam
03-25-2002, 10:47 PM
If I understand then glTexGen can "wipe out" texture based on a distance from a plane. Is this what you meant? In my problem the surface is not a sphere, it is more complicated and I need to wipe out texture from the hidden triangles.
What I though doing is calculate which triangles (or which vertices) are hidden and disable their texture drawing.
Do you still think I can use glTexGen, what am I missing?

Moshe Nissim
03-26-2002, 04:21 AM
Then you can use vertex program to calculate the inner product of the vertex normal and the direction from the vertex to the 'moon'
If the result is negative, then that normal forms an oblique angle to the line from the vertex to the 'moon' and should not be textured. You pass this result to the o[tex1].x , set the other components of o[tex1] to 1, and bind texture unit 1 to a 1-d texture with clamping. The texture image should be black at 0 and white elsewhere (or whatever is appropriate for your subsequent register combiner operations)

Eric
03-26-2002, 04:33 AM
What you really have to do (which may be achieved with vertex programs) is determine by yourself which triangles should be textured and which shouldn't.

You say that triangles should be textured if they are visible with respect to the plane normal. I suppose that's not exactly what you mean otherwise you'd just need a dot product between the plane normal and the triangle normal to find out which triangles should be textured. I think you meant that hidden triangles should not be textured either.

Then, you should find manually (i.e. by coding a function) which triangles will be visible and which will not (ray casting is a possibility).

Do not hesitate to correct me if my assumptions on what you are trying to achieve are wrong http://www.opengl.org/discussion_boards/ubb/wink.gif !

Regards.

Eric

Yigal Eilam
03-26-2002, 05:42 AM
I do have to find the hidden triangles and I cannot relay only on the triangle normals.
Actually, I already have a mechanism to know which vertex is hidden.
The only problem is while drawing strips and fans, some of the triangles should be textured and some not.
One option is to break the strips and fans to those textured and not.
About using 1D texture with clamping, doesn’t it mean that I have to double draw the surface? (once with the “actual” texture and once with the black/white texture?); The white texture will wipe out the ‘actual” one when needed, but wouldn’t it also wipe the lighting? (I’m now rendering the “actual” texture with alfa=0.5, GL_TEXTURE_ENV_MODE =GL_BLEND and GL_TEXTURE_ENV_COLOR=white)

Moshe Nissim
03-26-2002, 06:24 AM
Originally posted by Yigal Eilam:

About using 1D texture with clamping, doesn’t it mean that I have to double draw the surface?

Not if you are using hardware capable of multitexture. If your board costs more than $50 and less than $1000 then it probably does.

The white texture will wipe out the ‘actual” one when needed, but wouldn’t it also wipe the lighting?

Not if you are using correct glTexEnv or register combiners