跨顶点的 OpenGL 颜色插值
现在,我有超过 25 个顶点构成模型。我想在第一个和最后一个顶点之间线性插值颜色。问题是当我编写以下代码时,
glColor3f(1.0,0.0,0.0);
vertex3f(1.0,1.0,1.0);
vertex3f(0.9,1.0,1.0);
.
.`<more vertices>;
glColor3f(0.0,0.0,1.0);
vertex3f(0.0,0.0,0.0);
除了最后一个顶点之外的所有顶点都是红色的。现在我想知道是否有一种方法可以在这些顶点上插入颜色,而无需我在每个顶点手动插入颜色(而不是本地,就像opengl如何自动插入),因为我将在不同的位置有更多数量的颜色顶点。任何帮助将不胜感激。
谢谢你!
Right now, I have more than 25 vertices that form a model. I want to interpolate color linearly between the first and last vertex. The Problem is when I write the following code
glColor3f(1.0,0.0,0.0);
vertex3f(1.0,1.0,1.0);
vertex3f(0.9,1.0,1.0);
.
.`<more vertices>;
glColor3f(0.0,0.0,1.0);
vertex3f(0.0,0.0,0.0);
All the vertices except that last one are red. Now I am wondering if there is a way to interpolate color across these vertices without me having to manually interpolate color (instead natively, like how opengl does it automatically) at each vertex since, I will be having a lot more number of colors at various vertices. Any help would be extremely appreciated.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
OpenGL 将在一个顶点和下一个顶点之间插入像素的颜色,但我不知道有什么方法可以让它自动插入中间顶点的值。通常,这并不是特别困难 - 无论如何,您都不想为每个单独的顶点编写代码,因此添加计算非常简单:
不过有一件事:这对每个顶点进行纯线性插值。例如,它不会尝试考虑一个顶点与下一个顶点之间的距离。我猜想如何做这样的事情的问题是(至少部分)OpenGL 不自己尝试这样做的原因。
编辑:对于跨半球的渐变,我会尝试这样的操作:
目前,我已经完成了球体的外部,但制作半球并没有太大不同。
OpenGL will interpolate colors of pixels between one vertex and the next, but I don't know of any way to get it to automatically interpolate the values for intermediate vertexes. Normally, that's not particularly difficult though -- you don't want to write code for each individual vertex anyway, so adding the computation is pretty trivial:
One thing though: this does purely linear interpolation per vertex. It does not, for example, attempt to take into account the distance between one vertex and the next. I'd guess questions of how to do things like this are (at least part of) why OpenGL doesn't attempt this on its own.
Edit: for a gradient across a hemisphere, I'd try something like this:
For the moment, I've done the outside of a sphere, but doing a hemisphere isn't drastically different.
OpenGL 将在多边形内插值颜色,但不会跨多边形插值。
OpenGL will interpolate color within polygons, but not across polygons.