Tiling texture bmp file as texture onto a rectangle in OpenGL?

旧街凉风 提交于 2019-12-08 04:42:55

问题


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.

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).

How can I apply this bmp to the flat surface and tile it? What is the best way to do this in GLUT & OpenGL?


回答1:


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();

This will set texture coordinates to tile any texture 3x2 times on this surface.



来源:https://stackoverflow.com/questions/743097/tiling-texture-bmp-file-as-texture-onto-a-rectangle-in-opengl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!