Equally textured line

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
kerl
Gnoblar
Posts: 2
Joined: Thu Apr 19, 2018 8:19 am

Equally textured line

Post by kerl » Thu Apr 19, 2018 8:36 am

Hello,

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);
    
Help will be appreciated :)

Best,
Nico
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 647
Joined: Sun Mar 30, 2014 2:51 pm
x 94
Contact:

Re: Equally textured line

Post by paroj » Fri Apr 20, 2018 1:56 pm

you need to adapt your UV computation s.t. the coordinates reflect the point distance d: e.g. run the coordinate [0..d] instead of [0..1].
Also see http://www.opengl-tutorial.org/beginner ... ured-cube/ and https://ogrecave.github.io/ogre/api/1.1 ... s_005fmode
1 x

kerl
Gnoblar
Posts: 2
Joined: Thu Apr 19, 2018 8:19 am

Re: Equally textured line

Post by kerl » Fri Apr 20, 2018 3:00 pm

Thanks, that helped me a lot!

So the textureCoord sets the part of the buffer (image) and its position on the triangle? I set the u-coordinate to the current length (here std::pow(i, 2)) and the v-coordinate to 0, the line is regularly dashed as the colors iterate through the buffer. I thought the uv coordinates are used to access the colors in a 2D struct in the buffer. Is it correct that I have no v-coordinate in my example because the line is only 1D? Setting v in the texture coordinate did not do anything now.
I think what confuses me is that I used a TEX_TYPE_2D.
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 647
Joined: Sun Mar 30, 2014 2:51 pm
x 94
Contact:

Re: Equally textured line

Post by paroj » Fri Apr 20, 2018 4:15 pm

yes, your assumptions are correct. Regarding TEX_TYPE_2D: technically a Nx1 texture is still a 2d texture, altough all values for v will map to the same y-pixel.
1 x

Post Reply