Can't set colour to ManualObject

Problems building or running the engine, queries about how to use features etc.
Post Reply
raskolnikov
Gnoblar
Posts: 15
Joined: Mon Jul 16, 2007 4:06 am

Can't set colour to ManualObject

Post by raskolnikov »

Hi,

I'm creating a ManualObject but I can't set colours to it. I am just calling ManualObject::colour() before calling ManualObject::vertex(), a I would do in plain OpenGL.

I've tried setting materials to the object, which works, but I don't want to have to create a material -just use void material "". The colour() function seems to make no effect wether I set a material or not.

Any hints?

Thanks.
User avatar
PolyVox
OGRE Contributor
OGRE Contributor
Posts: 1316
Joined: Tue Nov 21, 2006 11:28 am
Location: Groningen, The Netherlands
x 18
Contact:

Post by PolyVox »

I believe you call colour once per manual object, rather than once per vertex. i.e. the whole object should be the same colour. May be wrong though...
genva
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 1603
Joined: Wed Oct 20, 2004 7:54 am
Location: Beijing, China
x 1

Post by genva »

I think you must create special material that either disabled lighting, or use vertex colour tracking, or use shaders. There are no other ways to use colour attributes of the vertex.
dmackay
Gnoblar
Posts: 3
Joined: Wed Jul 02, 2008 7:50 pm

Manual Object Colouring with Vertex Colour

Post by dmackay »

When creating the Manual object you must set the colour of each vertex of each sub entity that you want coloured. Each call to position starts a new vertex definition. The first vertex of each sub entity defines the available attributes of the following vertex in the sub entity. ie. if you want vertex colour the first vertex must have colour() called for it.


/* Example is in C# Mogre Code, but translates back to c++ Ogre */

Code: Select all

//start sub entity
manual.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

    manual.Position(Vector3);    //start vertex
    manual.Colour(colour);       //set vertex colour
    //other properties for subentity as require

   manual.Position(Vector3):    //start next vertex
   manual.Colour(colour);        //next vertex colour

   //create triangle list if using indexed geometry

manual.end();
That is all that is needed; the manual object will then be rendered using the vertex colours, it will blend between vertex colours and all colours will be displayed at full brightness ignoring lighting. use "BaseWhite" as the material if you want lighting.

I recommend downloading the xml mesh converter; you can export your manual object to a mesh file using meshserializer, then convert the .mesh to xml to view to check exactly what is happening with the mesh.

Cheers
Donald
ihateloss
Kobold
Posts: 26
Joined: Fri Jul 18, 2008 10:29 pm

Re: Manual Object Colouring with Vertex Colour

Post by ihateloss »

I have render my manual object (point list) like this, but still cann't have the white colour. I dont know why?
my code is like this

manualobject.begin('', ogre.RenderOperation.OT_POINT_LIST)
manualobject.position(...)
manualobject.colour(...)
manualobject.end()
dmackay wrote:When creating the Manual object you must set the colour of each vertex of each sub entity that you want coloured. Each call to position starts a new vertex definition. The first vertex of each sub entity defines the available attributes of the following vertex in the sub entity. ie. if you want vertex colour the first vertex must have colour() called for it.


/* Example is in C# Mogre Code, but translates back to c++ Ogre */

Code: Select all

//start sub entity
manual.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

    manual.Position(Vector3);    //start vertex
    manual.Colour(colour);       //set vertex colour
    //other properties for subentity as require

   manual.Position(Vector3):    //start next vertex
   manual.Colour(colour);        //next vertex colour

   //create triangle list if using indexed geometry

manual.end();
That is all that is needed; the manual object will then be rendered using the vertex colours, it will blend between vertex colours and all colours will be displayed at full brightness ignoring lighting. use "BaseWhite" as the material if you want lighting.

I recommend downloading the xml mesh converter; you can export your manual object to a mesh file using meshserializer, then convert the .mesh to xml to view to check exactly what is happening with the mesh.

Cheers
Donald
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 6
Contact:

Post by haffax »

In order for vertex colours to be visible, you have to activate vertexcolour tracking. This is done in your material. If you use a material script bind vertexcolours to either diffuse or ambient colour by setting it to vertexcolour. See manual section 3.1.2 for details.

When you create the material programatically use Pass::setVertexColourTracking, see API docs for details.
team-pantheon programmer
creators of Rastullahs Lockenpracht
ihateloss
Kobold
Posts: 26
Joined: Fri Jul 18, 2008 10:29 pm

Post by ihateloss »

Here is my situation. I have a point cloud file which have just x y z r g b data for each point. This file is pretty big, about 1G. I want to render it in Ogre and I have tried to use the manualobject as I have said in last post.

your answer is pretty deep for me. Could you give me an example code?
thanks a lot
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 6
Contact:

Post by haffax »

Actually it is pretty easy, just read the manual section I pointed you to, it explains it all and the general setup of a material file should be clear as it is necessary to know when using Ogre anyway. In case it is not best start with the beginning of chapter 3.1.

When you have a specific question about it afterwards, just ask here.
team-pantheon programmer
creators of Rastullahs Lockenpracht
ihateloss
Kobold
Posts: 26
Joined: Fri Jul 18, 2008 10:29 pm

Post by ihateloss »

thanks for your help.

Here is my situation. I have a point cloud file which have just x y z r g b data for each point. I want to render it in Ogre and I have tried to use the manualobject:

class Park(ogre.ManualObject):
def __init__(self, name):
ogre.ManualObject.__init__(self, name)
self.pointFile = None
def renderPark(self):
self.clear()
self.begin("", ogre.RenderOperation.OT_POINT_LIST)
self.position(23, 23, 23)
self.colour(1, 0, 0)
self.end()

Now i have created my .material script, should I call manualobject.setMaterialName() to activate vertex colour, right? or do something else? if it is like this, I want to know how to determine the first pamameter of this function? and where to add it in my program. Thanks
:oops:
dmackay
Gnoblar
Posts: 3
Joined: Wed Jul 02, 2008 7:50 pm

Manual Object Colouring with Vertex Colour

Post by dmackay »

This is what I am using to display lighted vertex colours, It will blend between vertex colours on the face, receive lighting etc. To have fullbright colouring turn lighting off. I am reading a custom format into a manual object using this as my material.

Code: Select all

material FlatVertexColour
{
	technique
	{
		pass
		{
			diffuse vertexcolour
			specular vertexcolour
			ambient vertexcolour
			lighting on
			
		}
	}
}
works well for me; if you are not using lighting or only ambient light then you would only need to set the ambient to track vertex colour.

Cheers
Donald
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 6
Contact:

Post by haffax »

The first parameter of ManualObject::begin is the material name to use for the begin/end section. So just set the material name there.
team-pantheon programmer
creators of Rastullahs Lockenpracht
ihateloss
Kobold
Posts: 26
Joined: Fri Jul 18, 2008 10:29 pm

Post by ihateloss »

Thank you all very much. Now, I have get rid of my problem and my program works well. here is indeed a good place to learn!! :wink:
ihateloss
Kobold
Posts: 26
Joined: Fri Jul 18, 2008 10:29 pm

Post by ihateloss »

Thank you all very much. Now, I have get rid of my problem and my program works well. here is indeed a good place to learn!! :wink:
johnkork
Gnoblar
Posts: 6
Joined: Sat Jan 25, 2014 10:04 am

Re: Can't set colour to ManualObject

Post by johnkork »

Hello guys, I acknowledge this subject is quite old, but I'm having troubles rendering vertex colours with a custom material.
I really do NOT see from which part of the code my mistake comes from.

I copied the custom material from this thread :

Code: Select all

material FlatVertexColour
{
   technique
   {
      pass
      {
         diffuse vertexcolour
         specular vertexcolour
         ambient vertexcolour
         lighting on

      }
   }
}
And here is the part where I set it in the code :

Code: Select all

ogreManualObject->begin("FlatVertexColour", Ogre::RenderOperation::OT_TRIANGLE_LIST);

// then, a bit latter
         	for(int v = 0 ; v < numOgreVertices ; v++)
         	{
          		pos = vertexVector[v]; 
            		ogreManualObject->position((Ogre::Real)pos.x, (Ogre::Real)pos.y, (Ogre::Real)pos.z);   // add a new vertex to ogre manualobject
            		getRGBAFromBlock(positionTempVar.getMaterial(), rgba);
            		ogreManualObject->colour(rgba[0], rgba[1], rgba[2], rgba[3]);
            }
// Later
// iteration with a int i parameter
{
ogreManualObject->index(i) // Re-arranging the order in which vertices are called
}
// Finally
ogreManualObject->end();
The Ogre logs are explicitely saying the Material has been loaded, and RGBA are float between 0 and 1 ; but everything is rendered in white.
When using BaseWhiteNoLighting, the colors actually shows up.

I am working on Ogre 1.9, maybe something has changed since ?
I'm really stuck with this one, and I can't see my mistake.

Have a good day :)
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7156
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 529

Re: Can't set colour to ManualObject

Post by Kojack »

You have lighting enabled in the material, but no normals in the manual object. Lighting doesn't work correctly without normals. That's the first thing to try.
johnkork
Gnoblar
Posts: 6
Joined: Sat Jan 25, 2014 10:04 am

Re: Can't set colour to ManualObject

Post by johnkork »

Well... thank you !
I actually tried to comment the "lighting on" step on the material, but your reply was spot on : "lighting off" was the thing to try.

Thanks a lot.
Post Reply