如何在openGL中纹理随机凸四边形 [英] How to texture a random convex quad in openGL

查看:366
本文介绍了如何在openGL中纹理随机凸四边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我开始寻找有关openGL的教程,以制作一个我的世界mod.我仍然对此不太了解,因为我认为在进行我想要的小修改时我确实不需要,但是这让我很头疼.我要做的就是能够正确地将纹理映射到不规则的凹四边形.

Alright, so I started looking up tutorials on openGL for the sake of making a minecraft mod. I still don't know too much about it because I figured that I really shouldn't have to when it comes to making the small modification that I want, but this is giving me such a headache. All I want to do is be able to properly map a texture to an irregular concave quad.

赞:

在尝试在游戏中运行代码之前,我进入了openGL以弄清楚如何做到这一点.我读过我需要做一个透视校正的变换,并且已经使它适用于梯形,但是对于我一生来说,如果两个边都不对,我就不知道该怎么做.平行线.我已经看过了: http://www.imagemagick.org/Usage/scripts/perspective_transform ,但是我真的不知道这个人正在谈论的"8个常数"是从哪里来的,或者它是否会对我有帮助.有人告诉我使用矩阵进行计算,但是我已经不知道其中有多少openGL可以照顾或不照顾.

I went into openGL to figure out how to do this before I tried running code in the game. I've read that I need to do a perspective-correct transformation, and I've gotten it to work for trapezoids, but for the life of me I can't figure out how to do it if both pairs of edges aren't parallel. I've looked at this: http://www.imagemagick.org/Usage/scripts/perspective_transform, but I really don't have a clue where the "8 constants" this guy is talking about came from or if it will even help me. I've also been told to do calculations with matrices, but I've got no idea how much of that openGL does or doesn't take care of.

我看了几篇关于此的文章,我需要的答案在那些文章的某处,但我无法做出正反两面的结论.我永远找不到可以告诉我为实现透视正确转换而应该在glTexCoord4f()方法中添加哪些参数的帖子.

I've looked at several posts regarding this, and the answer I need is somewhere in those, but I can't make heads or tails of 'em. I can never find a post that tells me what arguments I'm supposed to put in the glTexCoord4f() method in order to have the perspective-correct transform.

如果您考虑将开始了解Q坐标"页面作为我的问题的解决方案,那么恐怕我已经看过它了,但是它使我失望了.

If you're thinking of the "Getting to know the Q coordinate" page as a solution to my problem, I'm afraid I've already looked at it, and it has failed me.

有什么我想念的吗?我觉得这应该容易得多.我发现很难相信openGL及其所有功能,除了矩形之外,什么也做不了.

Is there something I'm missing? I feel like this should be a lot easier. I find it hard to believe that openGL, with all its bells and whistles, would have nothing for making something other than a rectangle.

所以,我希望我不会因为我的无知而惹恼您,并在此先感谢.

So, I hope I haven't pissed you off too much with my cluelessness, and thanks in advance.

我想我需要澄清一下,当您对四边形的视图不正交时,openGL会为您进行透视变换.我只想更改z坐标或我的视野.我希望平滑地构造非矩形四边形,而不是在一定视野中放置矩形.

I think I need to make clear that I know openGL does perspective transform for you when your view of the quad is not orthogonal. I'd know to just change the z coordinates or my fov. I'm looking to smoothly texture non-rectangular quadrilateral, not put a rectangular shape in a certain fov.

推荐答案

OpenGL将为您进行透视校正.我相信您只是面对四边形与三角形插值的问题.仿射变换和透视校正变换之间的差异与3D几何相关,其中图像空间中的插值是非线性的.考虑一下往下看:距离均匀的线在距离上显得更频繁.无论如何,回到三角形与四边形...

OpenGL will do a perspective correct transform for you. I believe you're simply facing the issue of quad vs triangle interpolation. The difference between affine and perspective-correct transforms are related to the geometry being in 3D, where the interpolation in image space is non-linear. Think of looking down a road: the evenly spaced lines appear more frequent in the distance. Anyway, back to triangles vs quads...

以下是一些相关的帖子:

Here are some related posts:

低多边形锥-平滑阴影提示

https://gamedev.stackexchange.com/questions/66312/quads-vs-三角形

将颜色应用于opengl中的一个四边形

对此的一个答案提供了一种可能的解决方案,但这并不简单:

An answer to this one provides a possible solution, but it's not simple:

解决此问题的常用方法是在片段着色器中手动"执行插值,其中考虑了目标拓扑(在您的情况下为四边形).或简而言之,您必须不基于三角形而是基于四边形执行重心插值.您可能还需要应用透视校正.

The usual approach to solve this, is by performing the interpolation "manually" in a fragment shader, that takes into account the target topology, in your case a quad. Or in short you have to perform barycentric interpolation not based on a triangle but on a quad. You might also want to apply perspective correction.

这篇关于如何在openGL中纹理随机凸四边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆