Material applies, but texture doesn't show up.

Get answers to all your basic programming questions. No Ogre questions, please!
Winston
Gnoblar
Posts: 4
Joined: Mon Nov 11, 2013 3:05 pm

Material applies, but texture doesn't show up.

Post by Winston »

Hello.

I made a model of a house in blender, assigned material to it, exported it to "house.mesh" file and loaded into my ogre application.

The material applies, but i can't see my texture. It has lightning, self-lightning and others but has no texture. If I change texture file, the house changes it's color, so if i use random grass texture the house is green, if I use sky image, the house is blue.

Then I made 2 models, first is my house that is loaded from mesh file, and second is manual object from MadMarx Tutorial 7 : Basic Material - Part 1 on ogre's Wiki, so I could compare the difference in applying a material. I apply the same material to both models, but house still has no texture, and changes it's color when I change texture image. The manual object has it's texture applied properly.

I also tried to create material script in "material.material" file, but it didn't work.

here is the code:

Code: Select all

	Ogre::MaterialManager& lMaterialManager = Ogre::MaterialManager::getSingleton();
	Ogre::String lNameOfResourceGroup = "3D Mad skills demo";
	{
		Ogre::ResourceGroupManager& lRgMgr = Ogre::ResourceGroupManager::getSingleton();
		lRgMgr.createResourceGroup(lNameOfResourceGroup);
		Ogre::String lDirectoryToLoadTextures = "D:/bin/Debug";
		bool lIsRecursive = false;
		lRgMgr.addResourceLocation(lDirectoryToLoadTextures, "FileSystem", lNameOfResourceGroup, lIsRecursive);
		lRgMgr.initialiseResourceGroup(lNameOfResourceGroup);
		lRgMgr.loadResourceGroup(lNameOfResourceGroup);

        //create material as MadMarks does it
        {
            Ogre::MaterialPtr lMaterial = lMaterialManager.create("Material",lNameOfResourceGroup);
            Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0);
            Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0);

            lFirstPass->setDiffuse(0.8f, 0.8f, 0.8f,1.0f);
            lFirstPass->setAmbient(0.3f, 0.3f, 0.3f);
            lFirstPass->setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
            lFirstPass->setShininess(64.0f);
            lFirstPass->setSelfIllumination(0.1f, 0.1f, 0.1f);

            Ogre::TextureUnitState* lTextureUnit = lFirstPass->createTextureUnitState();
            lTextureUnit->setTextureName("MakeSeamlessSampleUsage.jpeg", Ogre::TEX_TYPE_2D);
            lTextureUnit->setTextureCoordSet(0);
        }


		//manual object
 		Ogre::ManualObject * lManualObject = NULL;
		{
			Ogre::String lManualObjectName = "SomeQuad";
			lManualObject = lScene->createManualObject(lManualObjectName);
			bool lDoIWantToUpdateItLater = false;
			lManualObject->setDynamic(lDoIWantToUpdateItLater);
			float lSize = 0.7f;
			lManualObject->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
			{
				float cp = 1.0f * lSize ;
				float cm = -1.0f * lSize;
				float lDiffuseScale = 3.0f;
				float lLightmapScale = 1.0f;

				lManualObject->position(cm, cp, 0.0f);// a vertex
				lManualObject->colour(Ogre::ColourValue(0.0f,1.0f,0.0f,1.0f));
				lManualObject->normal(0.0, 0.0, 1.0f);
				lManualObject->textureCoord(0.0f, 0.0f);
				lManualObject->textureCoord(0.0f, 0.0f);

				lManualObject->position(cp, cp, 0.0f);// a vertex
				lManualObject->colour(Ogre::ColourValue(1.0f,1.0f,0.0f,1.0f));
				lManualObject->normal(0.0, 0.0, 1.0f);
				lManualObject->textureCoord(lDiffuseScale, 0.0f);
				lManualObject->textureCoord(lLightmapScale, 0.0f);

				lManualObject->position(cp, cm, 0.0f);// a vertex
				lManualObject->colour(Ogre::ColourValue(1.0f,0.0f,0.0f,1.0f));
				lManualObject->normal(0.0, 0.0, 1.0f);
				lManualObject->textureCoord(lDiffuseScale, lDiffuseScale);
				lManualObject->textureCoord(lLightmapScale, lLightmapScale);

				lManualObject->position(cm, cm, 0.0f);// a vertex
				lManualObject->colour(Ogre::ColourValue(0.0f,0.0f,0.0f,1.0f));
				lManualObject->normal(0.0, 0.0, 1.0f);
				lManualObject->textureCoord(0.0, lDiffuseScale);
				lManualObject->textureCoord(0.0, lLightmapScale);

				lManualObject->triangle(2,1,0);
				lManualObject->triangle(0,3,2);
			}
			lManualObject->end();
		}

		Ogre::String lNameOfTheMesh = "MyQuad";
		lManualObject->convertToMesh(lNameOfTheMesh);

        //installing Quad into the scene
        Ogre::Entity* lEntity = lScene->createEntity(lNameOfTheMesh);
        Ogre::SceneNode* lNode = lRootSceneNode->createChildSceneNode();
        lNode->attachObject(lEntity);
        lNode->setPosition(0.0, -1.0, 0.0);

        //loading my house mesh and installing it into the scene
        Ogre::String lNameOfTheHouseMesh = "house.mesh";
		Ogre::Entity* lHouseEntity = lScene->createEntity(lNameOfTheHouseMesh);
		Ogre::SceneNode* houseNode = lRootSceneNode->createChildSceneNode();
		houseNode->attachObject(lHouseEntity);
		houseNode->setPosition(-1.0, 1.0, -1.0);

        //setting material for both models
        lEntity->setMaterialName("Material");
        lHouseEntity->setMaterialName("Material");



	}


The LOG

Code: Select all

18:51:00: Creating resource group 3D Mad skills demo
18:51:00: Added resource location 'D:/bin/Debug' of type 'FileSystem' to resource group '3D Mad skills demo'
18:51:00: Initialising resource group 3D Mad skills demo
18:51:00: Parsing scripts for resource group 3D Mad skills demo
18:51:00: Finished parsing scripts for resource group 3D Mad skills demo
18:51:00: Creating resources for group 3D Mad skills demo
18:51:00: All done
18:51:00: Loading resource group '3D Mad skills demo' - Resources: 1 World Geometry: 1
18:51:00: Finished loading resource group 3D Mad skills demo
18:51:00: Mesh: Loading house.mesh.
18:51:00: Texture: MakeSeamlessSampleUsage.jpeg: Loading 1 faces(PF_R8G8B8,640x480x1) with 9 generated mipmaps from Image. Internal format is PF_X8R8G8B8,640x480x1.
18:51:02: Destroying resource group 3D Mad skills demo
18:51:02: Unloading resource group 3D Mad skills demo
18:51:02: Finished unloading resource group 3D Mad skills demo
You do not have the required permissions to view the files attached to this post.
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 136

Re: Material applies, but texture doesn't show up.

Post by spacegaier »

First guess: Missing or bad UV values. Did you unwrap the model in Blender? Are there UVs in the mesh.xml file after the Blender export?
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
Winston
Gnoblar
Posts: 4
Joined: Mon Nov 11, 2013 3:05 pm

Re: Material applies, but texture doesn't show up.

Post by Winston »

Thanks, It resolves the problem. Some why textures were not unwrapped (mb just forgot to save or something). Just fixed the model and everything worked.

PS Does "give a kudo" = "Thank you button"?
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 136

Re: Material applies, but texture doesn't show up.

Post by spacegaier »

Winston wrote:PS Does "give a kudo" = "Thank you button"?
Correct.
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...