Cube and different texture per face

Hello,
I know how to render cube faces with different texture :slight_smile: but how to do it with vertex arrays ?

Vertex arrays contain whole object and I am not able use glBindTexture between glBegin, glEnd.

could you show me small code snippet ?
Thank you very much :wink:

You can’t.

  1. What you can try is to build a unique texture including all of your textures. This texture is known as mosaic or atlas.

It also has the performance advantage to reduce the number of texture bindings (texture binding is an expensive operation even in the immediate mode (glBegin()/glEnd()). The drawback is to pay attention how to build this texture as it can impact linear filtering of textures. You have to make sure that your internal textures are separated by a border pixel. This is a problem also for mipmapping.

  1. or you create a vertex array per face.

google for “mosaic opengl texture” and see
the second item “Advanced graphics programming using openGL - Google Books Result”

I have idea.

Can I render all polygons/quads with TEXTURE1 and after that, i can switch to TEXTURE2.

I see, i can choose a range of rendered vertices with

glDrawArrays(GL_QUADS, 0, 24);

0 - 24. I can say . TEXTURE0 is from 0 - 256 and TEXTURE1 is from 257 - 385 for example. Of course, i will sort polygons by TEXTURE.

Is this viable ? good idea ?

Now I don’t understand what you are trying to achieve in the first place. Are you trying to apply texture0 to all the faces of the cube in the first frame and then apply texture1 to all the faces of the cube in the next frame? Or do you have to apply a different texture per face?

“Or do you have to apply a different texture per face?”

of course :slight_smile: different texure per face.

i means, i will render all polygons with texture0 and after that, i will render remaining polygons with texture1

So yes, it is good. It is called “state sorting”.

See “SIGGRAPH 2003 Half-day Course - Performance OpenGL, Platform Independent Techniques”
http://www.performanceopengl.com/

See slides 106 to 120 for “state sorting”.

slide 117 show how expensive are some operations.

thank you Overlay, i will check it :wink: