Author Topic: Why the texture don't wrap the object completely  (Read 2707 times)

Offline luozi

  • byte
  • *
  • Posts: 20
    • View Profile
Why the texture don't wrap the object completely
« on: October 29, 2011, 10:51:37 am »
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

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Why the texture don't wrap the object completely
« Reply #1 on: October 29, 2011, 05:18:33 pm »
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.

Offline luozi

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Why the texture don't wrap the object completely
« Reply #2 on: October 29, 2011, 05:46:47 pm »
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!

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Why the texture don't wrap the object completely
« Reply #3 on: October 29, 2011, 10:34:32 pm »
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.

Offline luozi

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Why the texture don't wrap the object completely
« Reply #4 on: October 30, 2011, 04:07:27 am »
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]

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Why the texture don't wrap the object completely
« Reply #5 on: October 30, 2011, 08:06:03 pm »
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.
« Last Edit: October 30, 2011, 08:57:30 pm by EgonOlsen »

Offline luozi

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Why the texture don't wrap the object completely
« Reply #6 on: October 31, 2011, 12:18:01 pm »
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?

Offline luozi

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Why the texture don't wrap the object completely
« Reply #7 on: October 31, 2011, 12:24:44 pm »
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

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Why the texture don't wrap the object completely
« Reply #8 on: October 31, 2011, 01:15:15 pm »
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.

Offline luozi

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Why the texture don't wrap the object completely
« Reply #9 on: October 31, 2011, 02:14:53 pm »
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! ;)

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Why the texture don't wrap the object completely
« Reply #10 on: October 31, 2011, 03:10:30 pm »
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.

Offline luozi

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Why the texture don't wrap the object completely
« Reply #11 on: October 31, 2011, 04:54:31 pm »
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.

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Why the texture don't wrap the object completely
« Reply #12 on: October 31, 2011, 07:53:12 pm »
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.

Offline luozi

  • byte
  • *
  • Posts: 20
    • View Profile
Re: Why the texture don't wrap the object completely
« Reply #13 on: November 01, 2011, 12:36:04 am »
Ok, now I realy get it, thank you!