简体   繁体   English

如何在OpenGL中将两个不同的图像渲染为两个不同的图元? 2D纹理数组?

[英]How do I render two different images to two different primitives in OpenGL? 2D Texture arrays?

So I have a simple OpenGL viewer where you can draw any number of boxes that the user wants. 因此,我有一个简单的OpenGL查看器,您可以在其中绘制用户想要的任意数量的框。 Ive also added the ability to take a PNG or JPG image and texture map it to a primitive. Ive还添加了拍摄PNG或JPG图像并将其纹理映射到原始图像的功能。

I want to be able to have the user specify any of the cubes on the screen and apply different textures to them. 我希望能够让用户在屏幕上指定任何多维数据集并将不同的纹理应用于它们。 Im fairly new to OpenGL. 我是OpenGL的新手。 Right now I can easily map an image to a single primitive, but Im wondering whats the best way to map 2 seperate images (which may be different sizes) to 2 separate primitives. 现在,我可以轻松地将图像映射到单个图元,但是我想知道将2个单独的图像(可能大小不同)映射到2个独立图元的最佳方法是什么。

Ive done a fair amount of reading up on 2D Texture arrays and it would seem this would be the way I wanna go since I can store multiple textures in one texture unit, but I'm not sure if this is possible considering what I mentioned above. 我已经对2D Textures数组进行了大量的读取,这似乎是我想要的方式,因为我可以在一个纹理单元中存储多个纹理,但是考虑到我上面提到的内容,我不确定是否可以。 If the images are both different dimensions then I dont think I can do this (at least I dont think so). 如果图像都是不同的尺寸,那么我不认为我可以做到(至少我不这样认为)。 I know I can just store each image into separate texture units but doing it in an array seemed like the cleaner way to do it. 我知道我可以将每个图像存储到单独的纹理单元中,但是以阵列的方式进行处理似乎更清洁。

What would be the best way to do this? 最好的方法是什么? Can you in fact store different size images into a 2d texture array? 您实际上可以将不同大小的图像存储到2d纹理阵列中吗? And if so how? 如果是这样怎么办? Or am I better off just storing them on separate texture units? 还是我最好只是将它们存储在单独的纹理单元中?

Texture arrays are mainly meant if you want to draw a single primitive (or a whole mesh) with the shader being able to select between images without exhausting the number of available texture sampling units. 纹理数组主要是指您要绘制单个图元(或整个网格),并且着色器能够在图像之间进行选择而不会耗尽可用纹理采样单位的数量。 You can use them in the way you thought, but I doubt it will benefit you. 您可以按照自己的想法使用它们,但是我怀疑这样做会对您有好处。 Another approach (which is similiar to texture arrays) is using a texture atlas, ie creating a patchwork of images that constitutes a single texture and using appropriate texture coordinates to select the subimage. 另一种方法(类似于纹理阵列)是使用纹理图集,即创建组成单个纹理的图像拼凑而成,并使用适当的纹理坐标来选择子图像。

In your case, I suggest simply load each picture into a separate texture and bind the appropriate texture before drawing the cube. 对于您的情况,我建议您只需将每张图片加载到单独的纹理中,然后在绘制立方体之前绑定适当的纹理。

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

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