Why the texture don't wrap the object completely

Started by luozi, October 29, 2011, 10:51:37 AM

Previous topic - Next topic

luozi

I compile the example of the helloworld_ae, but when the cube display on the screen, there is some place that is entirely transparent as if there is no texture on it. I thought it was beacuse the cube.caltexturewrapsherical(), then I change it to cube.caltexturewrap(), but this time it was like that the texture is changed to default

EgonOlsen

What do you mean with "transparent"? That you can see through the cube? Both texture wrap methods are not meant to deliver 100% perfect results. They are just quick and dirty helper methods to assign at least some texture coordinates.

luozi

Yes, I set gl.enable(blend), and gl.blenfuc(ALPHA....). There is a hole in the upper and nether face. When I touch the screen , the cube totate. And  then I can see the upper face.  In the center of the upper face there is not any texture, maybe because the effect of the blend, I can see the background color. How can I make everywhere have the texture, thank you very much!

EgonOlsen

That's because jPCT creates an alpha channel by default masking out (almost) black pixels. If you don't want this behaviour, just load your texture with new Texture(..., true); instead and it will use the alpha channel from the file. If it doesn't have one, everything will be opaque.

luozi

I don't think I express myself clearly. Now I attach the picture, the picture1 is the example's result. The picture2 is the result ,   when I change cube.calctextwrapspherical(),to cube.calctexturewrap(),  I set new texture(...,ture) and I don't set the gl.enable(blend). And when I change the cube to a sphere, there are also two black places, which confuse me a lot.

[attachment deleted by admin]

EgonOlsen

#5
That's just because the texture has black areas and the wrap-methods don't seem to create the results that you expect them to. As said, they are not meant to create 100% perfect uv-coordinates. They can't, because they don't have the second sight and know nothing about your model. They are just a way to assign at least some coordinates so that one can verify that the texture is there.

And please don't use any gl related commands like gl.enable(...) or gl.blendfunc(...) in combination with jPCT-AE. It's not needed and destroys the state management of the engine. Use the means that the engine offers instead.

luozi

Thank you, I think I have know what you mean. And now I want to give every face a texture, so I call cube.getPolygonManager().setPolygonTexture(ID,TextureManager.getInstance().getTextureID("texture")); . But nothing happened except for there is one triangle become black. How can I set the texture of every face?

luozi

oh, I think  maybe this is because I did't set the Texture coordinates. I learn that opengl can calculate the Texture coordinates automatically, and in JPCT how to implement that? Thank you

EgonOlsen

OpenGL can't calculate texture coordinates automatically. How should it? It would have to be an artist to do this. It can generate coordinates (but that's not supported by ES!), but that's not better than what this methods do.

luozi

yes,I see, now how can I set the texture of every face, and how to set the texture coordinates of the vertex?  Thank you! ;)

EgonOlsen

Either when adding triangles to object via one of the addTriangle-methods or, if the object is already there, via the PolygonManager. However, you should do this before calling build() on/rendering the object.
The object compiler will split your object into several subobjects (you won't notice this API wise) to render them per texture. Giving each side of a cube its own texture results in 8 render calls where actually 1 would be sufficient if they were all using the same texture. So if possible, merge textures into one and modify texture coordinates instead.

luozi

Yes, you are right. But I find the only way to change the texture coordinate is via setpolygontexture(int polyID, TextureInfo tinf), am I right? And I'm not sure the "merge textures to one and modify the coordinates", is that by call TextureManager.compress() and setpolygontexture()? I know I am boresome but I just want to know clealy about your engine so that I can tell my classmates right thing.

EgonOlsen

Yes. If you want to change u/v-coordinates on an existing model, setPolygonTexture() is your friend. But as said: This should have been done before using/building the object, i.e. right after loading it. Doing it at runtime is possible, but requires the model to be compiled in a specific mode and even then, it's limited. That "merge textures"-hint is nothing that the engine does for you. It's rather something that you have to do in your editor. It basically means, that you shouldn't use three different textures for the head, the body and the legs of a character (for example...) but one texture with all parts included (if possible), because it can be rendered faster that way.

luozi