Page 1 of 1

Equally textured line

Posted: Thu Apr 19, 2018 8:36 am
by kerl

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

    Ogre::TexturePtr texptr = Ogre::TextureManager::getSingleton().createManual("_white_tex",
                                                                                3,  // width of texture
                                                                                2,  // height of texture
    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)->setAlphaRejectSettings(Ogre::CompareFunction::CMPF_GREATER_EQUAL, 128);  // 255
        Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_LINEAR);
    // 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");


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


Re: Equally textured line

Posted: Fri Apr 20, 2018 1:56 pm
by paroj
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 ... ured-cube/ and ... s_005fmode

Re: Equally textured line

Posted: Fri Apr 20, 2018 3:00 pm
by kerl
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.

Re: Equally textured line

Posted: Fri Apr 20, 2018 4:15 pm
by paroj
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.