简体   繁体   English

Opengl-使用纹理图集绘制圆柱体

[英]Opengl - Draw Cylinder using texture atlas

//component
    glRotatef((GLfloat)-90, 1, 0, 0);
    gluCylinder(qObj,t_width/2,t_width/2,t_height+2*UDwall, 20, 20);
    glRotatef((GLfloat)90, 1, 0, 0);

I want to draw a Cylinder attaching the part of texture. 我想绘制一个附着纹理部分的圆柱体。

        glBindTexture(GL_TEXTURE_2D, texName[1]);//+

But not like glVertex3f, when I bind a texture that can not do by using TexCoord. 但是不像glVertex3f,当我绑定使用TexCoord无法完成的纹理时。 (so just whole texture printed ;ㅅ;) (所以只打印了整个纹理;ㅅ;)

First is What can I do for adjusting the part of texture. 首先是我该如何调整纹理部分。

Second is (someone suggested using texture atlas)can I change the texture's Max coord(0.0~1.0) to other number? 第二个是(有人建议使用纹理图集)我可以将纹理的最大坐标(0.0〜1.0)更改为其他数字吗?

You could use a TextureMatrix to transform the coordinates of the texture so the desired rectangle shape (from texture altas) is in the right position. 您可以使用TextureMatrix来变换纹理的坐标,以便所需的矩形形状(从纹理高度开始)处于正确的位置。

So lets say you want to texture a rect that has coordinates (x,y) and dimensions (a,b) . 因此,假设您要纹理具有坐标(x,y)和尺寸(a,b)的矩形。 What we want to achieve here is to have the texture be at (0,0) for (x,y) and (1,1) for (x+a, y+b) . 我们要在此处实现的是将(x,y)的纹理设为(0,0) ,将(x+a, y+b)的纹理设为(1,1) (x+a, y+b)

Solution

use Texture Matrix 使用纹理矩阵
translate by (-x, -y) (-x, -y)
scale by (1.0 / a, 1.0 / b) (1.0 / a, 1.0 / b)缩放

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM