Archived

This topic is now archived and is closed to further replies.

Vertexs Array's and different textures

This topic is 5127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! i start learning OpenGL and i understand Vertex Array''s can speed up my applications. However, from my understanding, i can not use different texture''s. I see options for index- (color), color-, normal-, texcoord- and vertex-array''s, but how can tell OpenGL which texture to use for which vertexes? I could imagine making a huge 2048x2048 texture and putting my 256x256 textures in it, but is that the way? Should i better look for VBO''s? If so, what does VBO stand for? ;-) Currently I use somrthing like this (simplified in this example):
#define MAX_VERTEXES 1000
#define MAX_QUADS 1000

typedef struct
{
	float p[3];		// vertex or vector
} VERTEX;

typedef struct
{
	VERTEX v[4];		// 4 vertexes for the quad
	VERTEX n[4];		// normal for each vertex
	int t;			// texture object
} QUAD;

VERTEX vertexes[MAX_VERTEXES];
QUAD quads[MAX_QUADS];
[/CODE]

How could i best set this up in OpenGL for max efficiency?

Thank you in advance!   

Share this post


Link to post
Share on other sites
Firstly, a quick comment on your code, it would probably be better if you stored the U,V per vertex, not 4 UVs in one quad as you''ll find that most data comes acorss as triangles.
So you''re object would have UV per texture per vertex, then you tie the arrays of UV to the correct texture ID.

Now, the texturing issue.
For single textures its just a matter of setting the pointer to the UV coordinates array and telling it to draw. Make sure you have a texture bound before you do this

For multi-texturing you have to activate the correct texture unit and bind the array, so its basicaly the same as for single texturing you just have to make sure you have the correct texture unit active (with a bound texture) when setting the pointer;

* activate texture unit one
* bind texture
* setup UV array
* activate texture unit two
* beind texture
* setup UV array two
etc.. etc


http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_buffer_object.txt is the specs on the VBO extension

Share this post


Link to post
Share on other sites
it sounds more like he wants to change the texture in the middle of a draw call which is more or less not possible without a few tricks. yes, you can put all textures into one and use the right coords (with duplicate vertices along edges where two textures meet if they dont happen to be in the same position in the big texture).

you could also use multitexturing and blend between the different textures (if you dont have too many) or if your card supports fragment programs be real creative and do all you want.

but, with having a lot of different textures the short answer would be: not possible without a lot of texture units. changing the active texture is expensive anyway and you usually sort your stuff by texture (or put as much as you can into one big texture).

Share this post


Link to post
Share on other sites
@_the_phantom_: Yeah true, most of my stuff are triangles too. I just came up with a quick example, but you are right, i better should have choosen triangles. Thx for the link! I''ll check it out!

@Trienco: Yes, i wanted to change texture''s in between drawing my triangles/quads, so i thought it would be clever to have another array for texture-object numbers. I didn''t knew switching between texture object would be very expensive.

So if I load a model with lets say 2 different texture''s, I should store it in a way, that i first draw only all polygon''s with texture1 and then i should draw all polygon''s with texture2? Sounds a bit strange to me at first, but i am sure some clever people made some good thoughts about it ;-)

Thanks for your replies!

Share this post


Link to post
Share on other sites
Yes, that is correct. You want to draw the object as 2 parts. Otherwise, if you keep switching textures, it will kill performance . That''s just one more instruction that has to go through through memory, processed by the cpu, passed along the agp bus, and processed by the gpu, where it would have to re-load all that textures specific format information that was set when calling glTexParameteri. If the GPU had to keep reloading this information for every few triangles, it would obviuosly take precious cycles away from your GPU and add to an already saturated memory bus .

Share this post


Link to post
Share on other sites
of course, if you can fit both textures into one big texture that would be even better, as you will get away with only one call to draw (another -though not as critical- thing causing a little overhead).

Share this post


Link to post
Share on other sites