drawIndexedTriangleList not showing texture

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
WizardofChaos
Posts: 17
Joined: Tue Jan 11, 2022 8:43 pm

drawIndexedTriangleList not showing texture

Post by WizardofChaos »

Hi there,

I'm working with an axial billboard implementation and trying to apply a texture to said billboard, but it doesn't appear to be rendering a texture onto the list of triangles that get rendered. The positioning on the billboard seems fine, just... not getting any textures. It's using a custom scene node, and the render code for the material looks like this:

Code: Select all

			
			driver->setTransform(video::ETS_WORLD, mat);
			driver->setMaterial(getMaterial(0));
			// finally I draw it 
			driver->drawIndexedTriangleList(vertices, 4, indices, 2);
The code for setting the material textures looks like this:

Code: Select all

	node->setMaterialTexture(0, driver->getTexture("assets/effects/laser.png"));
	node->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
	node->setMaterialFlag(EMF_LIGHTING, false);
	node->setMaterialFlag(EMF_BACK_FACE_CULLING, false);
...and finally in the constructor the coordinates are set like this:

Code: Select all

			video::SColor color = video::SColor(255, 255, 255, 255);
			vertices[0].TCoords.set(0.0f, 0.0f);
			vertices[0].Color = color;
			vertices[1].TCoords.set(1.0f, 0.0f);
			vertices[1].Color = color;
			vertices[2].TCoords.set(1.0f, 1.0f);
			vertices[2].Color = color;
			vertices[3].TCoords.set(0.0f, 1.0f);
			vertices[3].Color = color;
The end result of all this being:

Image

What's going wrong is that it's just using the color given in the vertices, but I'm at a loss as to how to make it use the texture coordinates instead. This seems to be the same as how a billboard scene node renders a texture. Any advice on what I'm screwing up here?
Local man gets so irritated with modern space sims that he starts writing his own
CuteAlien
Admin
Posts: 9644
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: drawIndexedTriangleList not showing texture

Post by CuteAlien »

I don't see a problem in the posted code. drawIndexedTriangleList is just short-form for drawVertexPrimitiveList with EVT_STANDARD and scene::EPT_TRIANGLES. Which is the one used by nearly all nodes.

Maybe set a breakpoint at driver->setMaterial(getMaterial(0)); and check if it really has a valid texture at that point?

Other possibility would be that your texture doesn't work well with EMT_TRANSPARENT_ADD_COLOR. Does it show anything if you just use EMT_SOLID?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
WizardofChaos
Posts: 17
Joined: Tue Jan 11, 2022 8:43 pm

Re: drawIndexedTriangleList not showing texture

Post by WizardofChaos »

I found the problem; it was a pretty silly fix.

The lack-of-texture was just the material not being set up properly and referencing a different material in the "getMaterial" call. D'oh. That got fixed. Then I ran into an error with the transparency, but that was another simple fix.

The render register call was using auto-detection instead of making sure it was transparent. The code in question got changed to this:

Code: Select all

            if (IsVisible)
            {
                SceneManager->registerNodeForRendering(this, irr::scene::ESNRP_TRANSPARENT);
                ISceneNode::OnRegisterSceneNode();
            }
And it worked perfectly. Turns out it was idiot programmer error. As are most things.
Local man gets so irritated with modern space sims that he starts writing his own
Post Reply