Solid White When Creating Nodes with Different Textures

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Serayen
Posts: 3
Joined: Sun Dec 02, 2012 2:49 pm

Solid White When Creating Nodes with Different Textures

Post by Serayen »

I'm trying to use a single mesh for multiple objects, with different textures per group. The mesh is working fine, and the textures work OK when I create one group. But if I try to create other groups with a different texture, only one texture works. it's usually only the first defined group that works, but it does seem to change sometimes.

Here's an image to help explain:

Image

The bars are one group, and the squares should have a circle texture. As you can see, it's not working. There's nothing wrong with the texture; I've tried disabling the creation of the bar objects, and the circles display fine.

I'm using IrrlichtLime 1.2 and C#. This is the code for the mesh:

Code: Select all

      MeshBuffer meshBuffer = MeshBuffer.Create( VertexType.Standard, IndexType._16Bit );
      Vertex3D[] vertices = new Vertex3D[4];
      vertices[0] = new Vertex3D( 0, 0, 1, 0, 0, 0, Color.OpaqueWhite, 1, 1 );
      vertices[1] = new Vertex3D( 0, 0, 0, 0, 0, 0, Color.OpaqueWhite, 0, 1 );
      vertices[2] = new Vertex3D( 1, 0, 0, 0, 0, 0, Color.OpaqueWhite, 0, 0 );
      vertices[3] = new Vertex3D( 1, 0, 1, 0, 0, 0, Color.OpaqueWhite, 1, 0 );
      ushort[] indices = new ushort[] { 0, 1, 2, 0, 2, 3 };
 
      meshBuffer.Append( vertices, indices );
      
      Mesh mesh = Mesh.Create();
      mesh.AddMeshBuffer( meshBuffer );
      mesh.RecalculateBoundingBox();
It's being re-used for all objects. This is creating the material for the bars:

Code: Select all

      Material mat = new Material();
      mat.SetTexture( 0, m_textures["asteroid"] );
      mat.SetFlag( MaterialFlag.Lighting, false );
      mat.SetFlag( MaterialFlag.TrilinearFilter, true );
      mat.SetFlag( MaterialFlag.AnisotropicFilter, true );
      mat.SetFlag( MaterialFlag.BlendOperation, true );
The m_textures variable is just a dictionary containing the Texture objects, which are created with the VideoDriver.GetTexture() method.

The bar objects are created with this code:

Code: Select all

      MeshSceneNode m;
      foreach( AsteroidField ast in m_map.Asteroids )
      {
        m = m_sceneManager.AddMeshSceneNode( mesh );
 
        m.Position = new Vector3Df( ast.Y, 0, ast.X );
        m.SetMaterial( 0, mat );
      }
The material code for the circles is this:

Code: Select all

      mat = new Material();
      mat.SetTexture( 0, m_textures["star"] );
      mat.SetFlag( MaterialFlag.Lighting, false );
      mat.SetFlag( MaterialFlag.TrilinearFilter, true );
      mat.SetFlag( MaterialFlag.AnisotropicFilter, true );
      mat.SetFlag( MaterialFlag.BlendOperation, true );
And the circles objects are created like so:

Code: Select all

      foreach( Star star in m_map.Stars )
      {
        m = m_sceneManager.AddMeshSceneNode( mesh );
 
        m.Position = new Vector3Df( star.Y, 0, star.X );
        m.SetMaterial( 0, mat );
      }
For drawing the objects, I'm just doing SceneManager.DrawAll(). I've tried creating a new mesh and mesh buffer for the circles, but that had no effect. I also tried creating a new material for every object, also with no effect.

I've tried searching but all I could find was people not having textures working at all, whereas this seems to be something else.
jaworekplay
Posts: 36
Joined: Mon Jan 23, 2012 11:14 pm
Location: Lancs, UK

Re: Solid White When Creating Nodes with Different Textures

Post by jaworekplay »

One question do you set the material flags after or before you create the scene nodes? If before try:

Code: Select all

mat = new Material();
foreach( Star star in m_map.Stars )
      {
        m = m_sceneManager.AddMeshSceneNode( mesh );
 
        m.Position = new Vector3Df( star.Y, 0, star.X );
        m.SetMaterial( 0, mat );
      }
mat.SetTexture( 0, m_textures["star"] );
mat.SetFlag( MaterialFlag.Lighting, false );
mat.SetFlag( MaterialFlag.TrilinearFilter, true );
mat.SetFlag( MaterialFlag.AnisotropicFilter, true );
mat.SetFlag( MaterialFlag.BlendOperation, true );
Hope it helps.
Good luck.
Serayen
Posts: 3
Joined: Sun Dec 02, 2012 2:49 pm

Re: Solid White When Creating Nodes with Different Textures

Post by Serayen »

I was setting it before. When I tried setting it after, the flags seemed to have no effect. In fact, it also broke the grid rendering. I added grid rendering after the original post, and the only effect it had was that it causes the problem in all nodes. The grid is drawn using 3D lines after SceneManager.DrawAll().

This is with the flags and texture set before node creation:
Image

and this is flags after node creation:
Image

In case it's important, the grid is drawn by resetting the world matrix using this:

Code: Select all

Driver.SetTransform( TransformationState.World, new Matrix() );
This it's just this in a couple loops:

Code: Select all

Driver.Draw3DLine( pos1, pos2, new Color( 41, 46, 49 ) );
jaworekplay
Posts: 36
Joined: Mon Jan 23, 2012 11:14 pm
Location: Lancs, UK

Re: Solid White When Creating Nodes with Different Textures

Post by jaworekplay »

Do you create new material or do you re-assign existing one ?
Serayen
Posts: 3
Joined: Sun Dec 02, 2012 2:49 pm

Re: Solid White When Creating Nodes with Different Textures

Post by Serayen »

I create a new material.
Post Reply