Archived

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

VA with texture

This topic is 5800 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 want to use VA in my 3D engine and I''ve a question. I want to specify a texture for each polygon, how can I do that ? Ex : Here''s 2 polygons : // Vertex Vertex3 Vertex[] = { { -2.0f, 2.0f, -2.0f, }, // Face gauche { -2.0f, -2.0f, -2.0f, }, { -2.0f, -2.0f, 2.0f, }, { -2.0f, 2.0f, 2.0f, }, { 2.0, 2.0f, 2.0f, }, // Face droite { 2.0, -2.0f, 2.0f, }, { 2.0, -2.0f, -2.0f, }, { 2.0, 2.0f, -2.0f, } }; // Texture coord. Vertex2 Text_Coord[] = { { 0.0f, 1.0f, }, { 0.0f, 0.0f, }, { 1.0f, 0.0f, }, { 1.0f, 1.0f, }, { 0.0f, 1.0f, }, { 0.0f, 0.0f, }, { 1.0f, 0.0f, }, { 1.0f, 1.0f, }, }; Here''s the function for displaying the 2 polygons : ... etc glDrawArrays(GL_QUADS, 0, 8); ... etc I''d like that each polygon has a different texture. How ? ======================== Leyder Dylan http://ibelgique.ifrance.com/Slug-Production/

Share this post


Link to post
Share on other sites
If you want two different textures, you have to break your vertex array draw call.
(unless you use multitexturing, but i do not recommend that because it''s slower, it uses more memory, and more difficult to develop)

glBindTexture(my_texture_no1);
glDrawArrays(GL_QUADS, 0, 4);
glBindTexture(my_texture_no2);
glDrawArrays(GL_QUADS, 4, 8);


otherwise, there exists another technique that consists of remodeling your texture so that it combines more than one texture, but in different areas. For instance in games like Quake, playable characters are modeled with one texture although in the same model there are things like skin, clothes, metal...
it only has one limitation : you can not make the texture repeat (in fact you can, but it''s a bit difficult to organize).
would you like to know more about this second technique ?

Share this post


Link to post
Share on other sites
Imagine you want sand and grass.



First solution

The textures :
  
texture_sand :
<---16 pixels--->
+---------------+ ^
| | |
| | |
| SAND | 16 pixels
| | |
| | |
+---------------+ V

texture_grass :
<---16 pixels--->
+---------------+ ^
| | |
| | |
| GRASS | 16 pixels
| | |
| | |
+---------------+ V


The code :
  
glBindTexture(texture_sand);
glDrawArrays(GL_QUADS, 0, 4);
glBindTexture(texture_grass);
glDrawArrays(GL_QUADS, 4, 8);





Second solution

The texture :
  
texture_sand_and_grass :
<-----------32 pixels----------->
+---------------+---------------+ ^
| | | |
| | | |
| SAND | GRASS | 16 pixels
| | | |
| | | |
+---------------+---------------+ V


The code :
  
// Texture coord.

Vertex2 Text_Coord[] = {

{ 0.0f, 1.0f, },
{ 0.0f, 0.0f, },
{ 0.5f, 0.0f, },
{ 0.5f, 1.0f, },

{ 0.5f, 1.0f, },
{ 0.5f, 0.0f, },
{ 1.0f, 0.0f, },
{ 1.0f, 1.0f, },
};
...
glBindTexture(texture_sand_and_grass);
glDrawArrays(GL_QUADS, 0, 8);


Is it clear enough ?

Share this post


Link to post
Share on other sites