Jump to content
  • Advertisement
Sign in to follow this  
ic0de

multiple textures on one mesh

This topic is 2577 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've got this problem when I'm loading mesh files,

I load vertex data from a file which is then put into a vertex array and drawn with glDrawArrays(), my problem is that when I was drawing in immediate mode I could easily switch textures in the middle of drawing the scene, the result was each face had a different texture, now with vertex arrays all the faces are drawn at once and I can't change the texture while this is happening, I end up with a mesh covered in a single texture. How can I achieve the same effect I had in immediate mode but with vertex arrays and without drawing each triangle separately?

I know I can do this using one really big texture but i'd rather do it with multiple textures.

Thanks in advance smile.gif

Share this post


Link to post
Share on other sites
Advertisement
Or you could change your data containers, for this I normally have a Model which can have multiple meshes which form the entire model but every mesh holds its own material with a texture etc. This way you can push the array's in like you normally would and bind the texture for that current mesh. The best example of this is within the OBJ file format, it has groups which have a unique material if you want them too. This way you have the same data structure like I just explained, a model with meshes with each mesh having its own material.

Share this post


Link to post
Share on other sites
You understand it correctly, you can't switch textures while drawing this way (generally it is bad idea to change gl stuff in drawing state). You changed it between triangle drawing states which is correct but vertex array method is much more batch render so you wont be able to do it.
I am not sure if there is any solution for fixed pipeline but for shaders you can simply add another attribute array which will represent texture unit for your vertex.

Correct me if I am wrong but using fixed pipelines you have only two options:
- you will be forced to use texture atlases as you already write
- you will divide your mesh

Share this post


Link to post
Share on other sites

You understand it correctly, you can't switch textures while drawing this way (generally it is bad idea to change gl stuff in drawing state). You changed it between triangle drawing states which is correct but vertex array method is much more batch render so you wont be able to do it.
I am not sure if there is any solution for fixed pipeline but for shaders you can simply add another attribute array which will represent texture unit for your vertex.

Correct me if I am wrong but using fixed pipelines you have only two options:
- you will be forced to use texture atlases as you already write
- you will divide your mesh


can I use 3d textures and give each texture a different z coordinate


Share this post


Link to post
Share on other sites
[font="Arial"][font="arial, verdana, tahoma, sans-serif"][font="Arial"][font="arial, verdana, tahoma, sans-serif"][font="Arial"][font="arial, verdana, tahoma, sans-serif"][font="Arial"]Ha good idea.
Well this should work if you set glTexCoord3f() where z coordinate ( layer of 3D texture ) will represent your texture
You should determine z like this:


//desiredTexture is indexed from 0 to (numTextures-1) and represent index of texture unit
z = (0.5 + desiredTexture) / numTextures;
[/font][/font][/font][/font][/font][/font][/font]
[font="Arial"][font="arial, verdana, tahoma, sans-serif"][font="Arial"][font="arial, verdana, tahoma, sans-serif"][font="Arial"][font="arial, verdana, tahoma, sans-serif"][font="Arial"]
But don't forget to enable GL_TEXTURE3D
[/font][/font][/font][/font][/font][/font][/font]

Share this post


Link to post
Share on other sites

[quote name='SaTANO' timestamp='1321750228' post='4885743']
You understand it correctly, you can't switch textures while drawing this way (generally it is bad idea to change gl stuff in drawing state). You changed it between triangle drawing states which is correct but vertex array method is much more batch render so you wont be able to do it.
I am not sure if there is any solution for fixed pipeline but for shaders you can simply add another attribute array which will represent texture unit for your vertex.

Correct me if I am wrong but using fixed pipelines you have only two options:
- you will be forced to use texture atlases as you already write
- you will divide your mesh


can I use 3d textures and give each texture a different z coordinate



[/quote]

You could but it is better to use GL_TEXTURE_2D_ARRAY which I think is available in GL 3.3

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!