平铺纹理bmp文件作为纹理到OpenGL上的矩形? [英] Tiling texture bmp file as texture onto a rectangle in OpenGL?
问题描述
我有一个pic.bmp,我试图平铺到一个3×2矩形平面上进行演示。
I have a pic.bmp that I'm attempting to tile onto a 3 x 2 rectangular flat surface for a demo I'm making.
尝试保持bmp的高宽比在tact中,但我仍然想要平铺它跨越表面。现在我有表面顶点为(0,0,0),(3,0,0),(0,2,0)和(3,2,0)。
I'm attempting to keep the aspect ratio of the bmp in tact but I still want to tile it across that surface. Right now I have the surfaces vertices as (0,0,0), (3,0,0), (0,2,0) and (3,2,0).
如何将此bmp应用于平坦表面并平铺?什么是最好的方法来做到这一点在GLUT& OpenGL?
How can I apply this bmp to the flat surface and tile it? What is the best way to do this in GLUT & OpenGL?
推荐答案
查看本NeHe课。要做平铺只需这样写:
See this NeHe lesson for a sample. To do tiling just write something like this:
glBegin(GL_QUADS);
// your surface
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.0f, 0.0f, 0.0f);
glTexCoord2f(3.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f);
glTexCoord2f(3.0f, 2.0f); glVertex3f( 3.0f, 2.0f, 0.0f);
glTexCoord2f(0.0f, 2.0f); glVertex3f( 0.0f, 2.0f, 0.0f);
glEnd();
这将设置纹理坐标以在此曲面上任意纹理贴图3x2次。
This will set texture coordinates to tile any texture 3x2 times on this surface.
这篇关于平铺纹理bmp文件作为纹理到OpenGL上的矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!