opengl纹理坐标如何工作? [英] How do opengl texture coordinates work?

查看:73
本文介绍了opengl纹理坐标如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在每次调用glVertex之前,必须先执行以下操作之一:

I know that I have to do call one of the following before each call to glVertex:

glTexCoord(0,0); 
glTexCoord(0,1); 
glTexCoord(1,1); 
glTexCoord(1,0); 

但是我不知道它们是什么意思.但是,我知道,如果我将右边(或除以?)乘以2(或全部除以?),我的纹理就会扩大,如果做相反的话,我的纹理会重复两次.我设法通过应用操作来编码纹理图集,直到它起作用为止.但是我对发生的事情有正确的认识.为什么将它们分开会影响图像,为什么将它们反转会镜像呢?纹理坐标如何工作?

But I have no idea what they mean. I know, however, that if I multiply (or is that divide?) the right side (or is it all the ones?) by two, my texture expands, and if I do the opposite, my texture repeats twice. I've managed to code a texture atlas by applying operations until it worked. But I have proper idea of what's going on. Why does dividing these affect the image, and why does reversing them mirror it? How do texture coordinates work?

推荐答案

纹理坐标指定纹理图像中的点,该点将与您为其指定顶点的点相对应.考虑一个矩形橡胶板,上面印有您的纹理图像,其中每侧的长度均标准化为0-1.现在,假设您要使用该纹理绘制一个三角形.您将用3个销钉将它们放在橡胶板中每个所需纹理坐标的位置. (说[0,0],[1,0]和[1,1]),然后将那些销钉(不取出它们)移动到所需的顶点坐标(说[0,0],[0.5,0]和[ 1,1]),以使橡胶板张开并且图像变形.基本上就是纹理坐标的工作原理.

Texture coordinates specify the point in the texture image that will correspond to the vertex you are specifying them for. Think of a rectangular rubber sheet with your texture image printed on it, where the length of each side is normalized to the range 0-1. Now let's say you wanted to draw a triangle using that texture. You'd take 3 pins and place them in the rubber sheet in the positions of each of your desired texture coordinates. (Say [0, 0], [1, 0] and [1, 1]) then move those pins (without taking them out) to your desired vertex coordinates (Say [0, 0], [0.5, 0] and [1, 1]), so that the rubber sheet is stretched out and the image is distorted. That's basically how texture coordinates work.

如果您使用大于1的纹理坐标,并且将纹理设置为重复,那么就好像橡胶板的大小是无限的,并且在其上平铺了纹理.因此,如果您的两个顶点的纹理坐标分别为0、0和4,0,则图像必须在这些顶点之间重复4次.

If you use texture coordinates greater than 1 and your texture is set to repeat, then it's as if the rubber sheet was infinite in size and the texture was tiled across it. Therefore if your texture coordinates for two vertices were 0, 0 and 4, 0, then the image would have to be repeated 4 times between those vertices.

@ b1nary.atr0phy为您所有的视觉思想家提供的图片!

@b1nary.atr0phy Image for all you visual thinkers!

这篇关于opengl纹理坐标如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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