ManualObject Textures

LexManos

08-12-2010 03:21:48

This is probably a general Ogre question/really stupid.
But I can't seem to get textures to work right with Manual Objects.

ManualObject manual = mSceneManager.CreateManualObject();
manual.Begin("Ogre/Eyes", RenderOperation.OperationTypes.OT_TRIANGLE_STRIP);
manual.Position(-100.0f, -100.0f, 0.0f);
manual.Position( 100.0f, -100.0f, 0.0f);
manual.Position( 100.0f, 100.0f, 0.0f);
manual.Position(-100.0f, 100.0f, 0.0f);
manual.Index(0);//Front Side
manual.Index(1);
manual.Index(2);
manual.Index(3);
manual.Index(0);//Back Side
manual.Index(1);
manual.End();

SceneNode n1 = mSceneManager.RootSceneNode.CreateChildSceneNode();
n1.AttachObject(manual);
Fairly straight forward, I create a 2d 2 sided square out of 4 triages.
Try to have it display the Ogre Eye texture that comes with the default download. And I get a solid pink square.

I'm new, but I've tried poking around but obviously still stumped. If someone could point me in the direction that would be great, I don't want to make external meshes and texture them in other programs, I know that works. I want to be able to make textured primitives pragmatically.

smiley80

08-12-2010 04:00:28

You have to assign a texture coordinate to the each vertex:

//...
manual.Position(-100.0f, -100.0f, 0.0f);
manual.TextureCoord(0, 1);

manual.Position(100.0f, -100.0f, 0.0f);
manual.TextureCoord(1, 1);

manual.Position(100.0f, 100.0f, 0.0f);
manual.TextureCoord(1, 0);

manual.Position(-100.0f, 100.0f, 0.0f);
manual.TextureCoord(0, 0);
//...

LexManos

08-12-2010 05:47:45

Thanks, with that and a little of tinkering I now understand it.
Next question, getting the triangles to face the direction I want them to.

Edit:
Apparently, whichever side is 'counter-clockwise' for the vertices, is the visible side.

public static ManualObject Create(SceneManager sMgr, String sMaterial, String sName)
{
ManualObject obj = sMgr.CreateManualObject(sName);

if (obj == null)
return null;

if(String.IsNullOrEmpty(sMaterial))
sMaterial = "BaseWhiteNoLighting";

obj.Begin(sMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
obj.EstimateVertexCount(4);
obj.EstimateIndexCount(12);

float[] points = {
-0.5f, 0.5f, 0, 0,
0.5f, 0.5f, 1, 0,
0.5f, -0.5f, 1, 1,
-0.5f, -0.5f, 0, 1
};

for (int x = 0; x < points.Length; x += 4)
{
obj.Position(points[x], points[x + 1], 0.0f);
obj.TextureCoord(points[x + 2], points[x + 3]);
}

uint[] idxs = {
0, 2, 1,
0, 3, 2,
0, 1, 2,
0, 2, 3
};

for (int x = 0; x < idxs.Length; x++)
obj.Index(idxs[x]);

obj.End();

return obj;
}
Creates a double sided square.

Alright, got my cube made, just the texture isn't sitting right.

http://www.rozengain.com/files/blog/uvc ... coords.jpg
public static ManualObject Create(SceneManager sMgr, String sMaterial, String sName)
{
ManualObject obj;
if (String.IsNullOrEmpty(sName))
obj = sMgr.CreateManualObject();
else
obj = sMgr.CreateManualObject(sName);

if (obj == null)
return null;

if(String.IsNullOrEmpty(sMaterial))
sMaterial = "BaseWhiteNoLighting";

float third = 1 / 3;
float twothird = 2 / 3;

obj.Begin(sMaterial, RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
obj.EstimateVertexCount(8);
obj.EstimateIndexCount(36);

float[] points = {
-0.5f, 0.5f, 0.5f, 0, 0,
0.5f, 0.5f, 0.5f, 0, third,
0.5f, -0.5f, 0.5f, third, 0.5f,
-0.5f, -0.5f, 0.5f, 0, 0.5f,

-0.5f, 0.5f, -0.5f, 0, 0,
0.5f, 0.5f, -0.5f, 0, 0,
0.5f, -0.5f, -0.5f, 1, 1,
-0.5f, -0.5f, -0.5f, 1, 1

};

for (int x = 0; x < points.Length; x += 5)
{
obj.Position(points[x], points[x + 1], points[x + 2]);
obj.TextureCoord(points[x + 3], points[x + 4]);
}

uint[] idxs = {
0, 2, 1, 0, 3, 2, //Front
4, 3, 0, 4, 7, 3, //Left
5, 7, 4, 5, 6, 7, //Back
1, 6, 5, 1, 2, 6, //Right
0, 1, 5, 0, 5, 4, //Top
3, 6, 2, 3, 7, 6 //Bottom
};

for (int x = 0; x < idxs.Length; x++)
obj.Index(idxs[x]);

obj.End();

return obj;
}
Should display 'Front' on the front, but it doesnt. It also doesn't make sense that a texture like this would work on a 3d object.
Do I have to create 24 verticies (4 for each side?)