PDA

View Full Version : Cube and different texture per face



wh1sp3rik
10-25-2009, 09:26 AM
Hello,
I know how to render cube faces with different texture :) 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 ;-)

overlay
10-25-2009, 12:39 PM
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.

2. 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"

wh1sp3rik
10-25-2009, 02:57 PM
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 ?

overlay
10-26-2009, 07:21 AM
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?

wh1sp3rik
10-26-2009, 09:58 AM
"Or do you have to apply a different texture per face?"

of course :) different texure per face.

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

overlay
10-26-2009, 10:13 AM
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.

wh1sp3rik
10-26-2009, 10:36 AM
thank you Overlay, i will check it ;-)