Draw Nuitrack RGB Frame to SDL texture


I am trying to modify the sample class in order to use SDL instead of OpenGL.

The program does not work, there is a black background (default).
I think the problem comes from the onNewRGBFrame but by using CLion, I can’t put any stopping points.

Here is the different part of the code :

  1. Initizalisation of the texture

    void SdlNuitrackRenderHandler::initTexture(int width, int height) { if(texture == nullptr){ texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, width, height); SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); } }

  2. Copy Nuitrack frame to SDL_Texture

    `void SdlNuitrackRenderHandler::onNewRGBFrame(RGBFrame::Ptr frame)
    if(_viewMode != RGB_MODE)

    std::cout << “ok”;

    const tdv::nuitrack::Color3* colorPtr = frame->getData();
    size_t bufferSize = static_cast<size_t>(_width) * static_cast<size_t>(_height) * 4;

    unsigned char *texture_data = nullptr;
    int texture_pitch = 0;

    SDL_LockTexture(texture, nullptr, (void **) &texture_data, &texture_pitch);
    memcpy(texture_data, colorPtr, bufferSize);

  3. Render Texture

    // Render prepared background texture void SdlNuitrackRenderHandler::renderTexture() { if(texture != nullptr) { SDL_RenderCopy(renderer, texture, NULL, NULL); } }

Anyone has an idea ? Maybe there is a format compatibility issue ?
Thanks you in advance.

Hi Alexandre,

We haven’t tested Nuitrack with SDL instead of OpenGL.
It seems that there’s a mistake in the following line:

size_t bufferSize = static_cast<size_t>(_width) * static_cast<size_t>(_height) * 4;

Instead of 4, you have to multiply it by 3.