使用 OpenGL 实现 Z 缓冲区
对于一个项目,我想实现我自己的 Z 缓冲区。我知道算法以及如何实现它。因为我不想编写整个图形引擎,所以我计划使用 OpenGL,问题是,如何将我自己的算法与 openGL 结合起来?
我在某处读到,我可以自己计算所有内容,然后将每个像素的数据传递给 GLDrawPixels() ,但这似乎有点矫枉过正。重点是我不想实现三角测量算法等。
我的目标是使用openGL直到线框,然后使用我自己的z缓冲区算法,然后再次使用openGL绘制最终图片。 (对于我的项目,z 缓冲区是唯一重要的,包括光和阴影)。有没有办法可以做到这一点,或者我必须自己实现一切并让 openGL 绘制最终结果?
真挚地
For a project I want to implement my own Z-buffer. I know the algorithm and how to implement this. Because I do not want to write an entire graphics engine I was planning on using OpenGL, the problem is, how can I combine my own algorithm with openGL?
I read somewhere that I could calculate everything myself and then pass the data per pixel to GLDrawPixels() but that seems a bit overkill. The point is that I don't want to implement triangulation algorithms etc..
My goal is to use openGL up until the wireframe, then use my own z-buffer algorithm and then use openGL again to draw the final picture. (for my project, the z-buffer is the only thing that matters, including light and shadows that is). Is there a way this can be done or do I have to implement everything myself and let openGL just draw the endresult?
Sincerely
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过“手动”计算顶点距离来将要绘制的顶点的颜色设置为其 z 值。但我认为可以将 z 缓冲区绑定为纹理,然后绘制一个带有 z 缓冲区纹理的大四边形覆盖屏幕。
You could set the colour of the vertices you are drawing to their z-values by calculating their distance 'manually'. But I think it's possible to bind the z-buffer as a texture and then draw a large quad covering with screen with the z-buffer texture on it.