Texture override

Hello people, I have one big problem,

And I have no idea how to fix it. It has to do with the textures on the objects.

Basic program info:

It is a simulation based on information I receive from another program. So I have

a controller program, and a simulation program wich

communicate with eachother over a network.

Extra info:

  • Simulation is based on simple game
  • Each (in simulation shown) class loads it's own texture
  • I use models, boxes

    The problem:

    The problem is that when I create objects in our renderer class, all objects

    are shown as they should be with the correct textures and all.

    But when I create the same objects in a different class (the class wich receives

    the network info) let's call that class "buffer". All objects will get the same texture.

    So objects created in the renderer work perfectly fine, objects created from

    the "buffer" all get the same texture.

    Few things I tried:

  • Switch lightCombinedMode
  • Delete the texture all objects get (the program just uses a different texture

      to paste on all objects)
  • Setting the Zbuffer state

    I really hope there is someone out there who can help me with this, because I am

    really stuck with this.

depends on the objects you create, but TextureStates and Textures always have to be created inside the OpenGL thread. So, in your "other" class you just enqueue the TextureState and Texture creation in the GameTaskQueue.

For a list of methods that have to be called inside the Open GL thread search the wiki and the forum.


That's a big help, didn't know that,

but would that explain the random textures (allways picks the same,

but if I delete the texture for instance, it will just use a different one)

pasted on the objects as well?

I recon that it might fix that I didn't have any textures at all before

from the "other" file, but does it explain the one texture on all objects?

if you do somthing like Textures outside the OpenGl thread, the results can be anything from nothing to OpenGlExceptions.

since OpenGL does something like:

use texture A

  draw thing with texture A

  draw thing with texture A

use texture B

  draw thing with texture B

if you load the texture B outside OpenGL the line "use texture B" is not given and the following geometries will be drawn with texture A.

This is much simplified but you'll get the idea of whats going on :wink:

Next gotcha with Textures is when people (including me) always forget do call updateRenderState() after setting TextureStates. That can also lead to random Textures on geometries.

Actually textures do not have to be loaded in the GL thread. Textures are merely data, and reading them or parsing them does not require OpenGL, which is a renderer. What does require OpenGL though, is sending the data to the video card, which is done automatically when the model with the texture is first drawn. Another concern comes with TextureManager, it is a utility class and does not really relate much to renderer. The issue with it is that it’s not thread safe. If you attempt to load textures from multiple threads you will receive a ConcurrentModificationException.

So, using TextureManager from multiple threads = crash

Loading textures or TextureStates from multiple threads without TextureManager = okay

Anyway, neither of this relates to the issue here… You say the objects loaded will have the same texture. The first thing that comes to mind is, did you call updateRenderState() on your scene after loading has finished? If you did, consider using a scene debugging tool like Scene Monitor and check if the objects really do use different textures.

Are you attaching your objects under a parent that has a texture state set? Remember that render states are inherited.