简体   繁体   English

opengl es 1.1:如何将多个材质应用于单个对象?

[英]opengl es 1.1 : how to apply several materials to one single object?

I've a simple cube which i have imported from Blender 3D; 我有一个从Blender 3D导入的简单多维数据集; this cube has 3 different materials for its face; 这个立方体的表面有3种不同的材料; yellow, pink and blue. 黄色,粉红色和蓝色。

So far i have managed to apply one material on an opengl es cube. 到目前为止,我已经设法在opengl es多维数据集上应用了一种材料。 However i am wondering how to apply several materials to the same cube. 但是我想知道如何将几种材料应用于同一个立方体。 As you will see from the OBJ file; 正如您将从OBJ文件中看到的那样; the materials share the same vertices; 材质共享相同的顶点; only their indices change. 只有它们的索引改变。 First thought has been to use a drawelement for each of this material; 首先想到的是对每种材料都使用抽拉元件。 but is it first really working ? 但是首先真的有用吗? and how performance costly is it and is there a better approach in Openg GL ES 1.1 ? 以及性能如何昂贵?Openg GL ES 1.1是否有更好的方法?

Many thanks for any pointer you can provide me. 非常感谢您可以为我提供的任何指导。

Cheers, Stéphane 干杯,斯特凡

# Blender v2.61 (sub 0) OBJ File: ''
# www.blender.org
mtllib MultiColorCube.mtl
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 1.000000 1.000000
v 0.999999 1.000000 1.000001
v -1.000000 -1.000000 1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 1.000000 1.000000
v 1.000000 1.000000 -0.999999
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v 1.000000 -1.000000 1.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn -1.000000 -0.000000 -0.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 0.999969
vn 1.000000 0.000000 0.000000
usemtl bleu
s off
f 1//1 2//1 3//1 4//1
f 5//2 8//2 7//2 6//2
f 17//3 20//3 19//3 16//3
f 21//4 14//4 15//4 18//4
usemtl Jaune
s 1
f 10//5 9//5 11//6
f 12//5 10//5 11//6
usemtl Pink
s off
f 13//7 22//7 23//7 24//7

Yes, it is possible to change material state settings in between the glDrawElements calls. 是的,可以在glDrawElements调用之间更改材质状态设置。 You can just set color for first chunk of indices, then call glDrawElements with these indices, then set next color and so on. 您可以只为第一个索引块设置颜色,然后使用这些索引调用glDrawElements,然后设置下一个颜色,依此类推。 Performancewise it is usually best to draw geometry in as large chunks as possible and change material settings as rarely as possible. 在性能方面,通常最好以尽可能大的块绘制几何图形,并尽可能少地更改材质设置。 So, assuming all you change is the color, then having colors as vertex attributes may be better, eventhough it uses up more memory for the vertex buffer. 因此,假设您所更改的只是颜色,那么将颜色用作顶点属性可能会更好,即使它为顶点缓冲区占用了更多的内存。 But as long as your material change is nothing more than a glColor call, you should be fine. 但是,只要您进行实质性更改仅是调用glColor,就可以了。 For more detailed performance advices you need to describe in more detail what you're actually rendering. 有关更详细的性能建议,您需要更详细地描述实际渲染的内容。

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

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