C - 显示不断更新图像

C++ - Display continuously updating image

本文关键字:更新 图像 显示      更新时间:2023-10-16

我已经在C 中写了一个病理,现在我想实时显示渲染过程,所以我想知道最简单/最佳的方法是什么。p>基本上,渲染的图像更新在每次迭代后都需要检索,在单独的窗口中显示并进行更新。

我正在考虑使用DirectX,看来我也可以使用OpenCV来做,但是我只是在寻找一种简单的方法,而不需要添加很多新代码。

我在Windows上使用C 。

如果我正确理解您的路径示踪剂可能会输出每个发射射线的颜色?如果是这种情况,您正在考虑在单独的窗口中显示渲染图像,我建议使用SDL2。使用C 和SDL的实时图形有很多教程。

摘录摘自SDL_SURFACE的官方SDL文档(不需要Cruft以初始化Windows的初始化),您可能会使用:

/* 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);
}