1

Lets say i have a pyramid... I know how to draw it, and i know how to set a texture for the whole pyramid, but how can i set a different texture for each wall?

I set the texture by adding this GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID()); before GL11.glBegin(GL11.GL_TRIANGLES);

I tried to bind the textures by adding GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID()); after every 3 lines that sets Vertex coordinates of the pyramid, but GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID()); wont work if it is between GL11.glBegin(GL11.GL_TRIANGLES); and GL11.glEnd();

EDIT

I drawn every wall separately and it worked, but i dont like that way... That looks tricky to me... Is that a good way to do what i want?

Qualphey
  • 1,244
  • 1
  • 19
  • 44

2 Answers2

1

I think the best way is what you have done, to draw them separately. You generally want each 'batch' to refer to a single material.

If you really want to you can pack the four textures into one sheet and let each wall pick out part of it with unique texcoords, but that's probably unnecessary complexity unless your performance is suffering from too many batches.

Tim
  • 35,413
  • 11
  • 95
  • 121
1

I don't think there is a straight-forward way to do this in GL. You probably want to combine the textures into one big image, and then use the texture coordinates to select the right sub-image.

Even if you get it working for a limited number of textures, e.g. by switching the texturing unit and using a white pixel on the other one (or with advanced GLSL stuff), it probably would not scale to performance: http://origin-developer.nvidia.com/docs/IO/8230/BatchBatchBatch.pdf

Stefan Haustein
  • 18,427
  • 3
  • 36
  • 51