I am starting out using Ogre and trying some different visualization types. I was able to create a line using different methods (BillboardChain, rviz::BillboardLine which uses Ogre, ManualObject) and also add a texture to it. My problem now is that the display of the texture always depends on the points used for the e.g. ManualObject. I already found out that the UV coordinates are always mapped to the positions and I am calling the textureCoords for each point.
My problem with this is that I want to create an evenly textured line using more or less random points which vary in their distance to each other. So my current line would be e.g. irregular striped more like morse code. My goal would be a regularly striped/dotted line over the random points.
I found that using a texture seems logical to me since it can easily be modified to have different kinds of dots and colors.
My question would be if it is also possible to apply a texture/material to my points or do I have to take a completely different approach?
I also tried to find a method which changes the display style to my desired type but not coming from game development (more from the C side), it is hard for me to find the correct terms for my searches.
Here is my test code:
Code: Select all
// CREATE STRIPED MATERIAL
Ogre::TexturePtr texptr = Ogre::TextureManager::getSingleton().createManual("_white_tex",
"General",
Ogre::TextureType::TEX_TYPE_2D,
3, // width of texture
2, // height of texture
1,
0,
Ogre::PixelFormat::PF_A8R8G8B8);
unsigned int* data =
(unsigned int*)texptr->getBuffer(0, 0)->lock(0, 6 * 4, Ogre::HardwareBuffer::LockOptions::HBL_DISCARD);
const unsigned int white = 0xffffffff;
const unsigned int transparent = 0x00000000;
data[0] = white;
data[1] = transparent;
data[2] = white;
data[3] = transparent;
data[4] = white;
data[5] = transparent;
texptr->getBuffer(0, 0)->unlock();
Ogre::MaterialPtr matptr = Ogre::MaterialManager::getSingleton().create("_white_mat", "General");
matptr->getTechnique(0)->getPass(0)->createTextureUnitState("_white_tex");
matptr->getTechnique(0)->getPass(0)->setLightingEnabled(false);
matptr->getTechnique(0)->getPass(0)->setAlphaRejectSettings(Ogre::CompareFunction::CMPF_GREATER_EQUAL, 128); // 255
matptr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureFiltering(
Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_LINEAR);
matptr->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
matptr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureAddressingMode(
Ogre::TextureUnitState::TextureAddressingMode::TAM_WRAP);
// Repeat texture for n times over whole length, maybe check length and do dependingly 1/length:10
matptr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureScale(1, 1);
Code: Select all
Ogre::ManualObject* manual = scene_manager->createManualObject("L1");
manual->begin(matptr->getName(),
Ogre::RenderOperation::OT_TRIANGLE_STRIP);
// Make a line with iterating colors
const int width = 5;
const int gap = 1;
for (int i = 0; i < 10; ++i)
{
manual->position(std::pow(i, 2), 0 - gap, 0);
manual->textureCoord(i, 0);
manual->position(std::pow(i, 2), 0 - width / 2 - gap, 0); // -width
}
manual->end();
scene_manager->getRootSceneNode()->createChildSceneNode("LevelBorders")->attachObject(manual);

Best,
Nico