C ++ - 显示不断更新的图像

时间:2017-08-30 14:38:03

标签: c++ user-interface opencv directx

我在C ++中编写了一个pathtracer,现在我想实时显示渲染过程,所以我想知道最简单/最好的方法是什么。

基本上,渲染的图像在每次迭代后都会更新,所以我只需要检索它,在单独的窗口中显示它,然后更新它。

我正在考虑使用DirectX,似乎我可能也可以使用OpenCV,但我只是在寻找一种不需要添加大量新代码的简单方法。

我在Windows上使用C ++。

1 个答案:

答案 0 :(得分:1)

如果我理解正确,你的路径追踪器可能会输出每个发射光线的颜色?如果是这种情况,并且您正在考虑在单独的窗口中显示渲染图像,我建议使用SDL2Lazy Foo' Productions使用C ++和SDL提供了很多关于实时图形的教程。

摘自SDL_Surface的官方SDL documentation(不需要初始化窗口),您可能会使用它:

/* This is meant to show how to edit a surface's pixels on the CPU, but
   normally you should use SDL_FillRect() to wipe a surface's contents. */
void WipeSurface(SDL_Surface *surface)
{
    /* This is fast for surfaces that don't require locking. */
    /* Once locked, surface->pixels is safe to access. */
    SDL_LockSurface(surface);

    /* This assumes that color value zero is black. Use
       SDL_MapRGBA() for more robust surface color mapping! */
    /* height times pitch is the size of the surface's whole buffer. */
    SDL_memset(surface->pixels, 0, surface->h * surface->pitch);

    SDL_UnlockSurface(surface);
}