如何在openGL中使用背景图像作为纹理
我想使用带有纹理的背景图像,但纹理获取的图像的幂为 2,所以我设置了图像大小(800x480 到 512x512)。
但现在它显示的图像有一些空白。
我怎样才能在整个屏幕上显示图像。并且还想要水平滚动。
i want to use background image with texture but texture get images with power of 2 so i made image size (800x480 to 512x512).
but now it is showing image with some blank space.
how can i show image on entire screen. and also want to horizontally scrollable .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,如果这是在 Android 上,则意味着您没有
glDrawPixels
,因此“显示”图像的唯一方法是渲染带纹理的四边形。因此,只需将四边形制作成您需要的任何尺寸即可。您还可以绘制多个纹理,只需将一个纹理绘制到一个位置,然后将另一个纹理绘制到另一个位置即可。
Well, if this is on Android, that means you don't have
glDrawPixels
, so the only way you could be "showing" an image would be to render a textured quad. So just make the quad whatever size you need.You can also draw multiple textures, just by drawing one texture to one location, then drawing another texture to another location.
渲染背景时需要使用正确的纹理坐标。您需要计算纹理坐标,以便获得垂直于黑色边框的轴的偏移量。
我猜您调整了 800x480 图像的大小,使其适合 512x512 像素,从而使您最终得到的实际背景图像(在 512x512 纹理内)为 512x307?
这意味着您的 u 纹理坐标偏移量需要为 (512.0 - 307.0) / 2.0 / 512.0 ~ 0.2,因此您的纹理坐标需要为 (0.0,0.0), (0.0,0.2), (1.0,0.2) , (1.0,0.0)。
You need to use the right texture coordinates when rendering your background. You need to compute the texture coordinates so that you are having an offset for the axis perpendicular to the black borders.
I guess you resized your 800x480 image so that it fits in 512x512 pixels, making you end up with the actual background image (inside the 512x512 texture) being 512x307?
This would mean that your u texture coordinate offset would need to be (512.0 - 307.0) / 2.0 / 512.0 ~ 0.2, so your texture coordinates would need to be (0.0,0.0), (0.0,0.2), (1.0,0.2), (1.0,0.0).