0

I have loaded textures in memory and I want to draw them one draw call. I can put all texture coords to buffer but how I create one texture from small texture parts ? is that possible ?

or I must download images and combine them then I create textrute from combined big picture ?

H. Akkaya
  • 161
  • 3
  • 11

1 Answers1

1

In general combining images into a texture atlas is something you'd do off line either manually like in an image editing program or using custom or specialized tools. That's the most common and recommended way.

If you have to do it at runtime for some reason then the easiest way to combine images into a single texture is to first load all your images, then use the canvas 2D api to draw them into a 2D canvas, then use that canvas as a source for texImage2D in WebGL. The only issue with using a 2D canvas is if you need data other than images because 2D canvas only supports pre-multiplied alpha.

Otherwise doing it in WebGL is just a matter of rendering your smaller textures into a larger texture. Rendering to a texture requires creating the texture, attaching to a framebuffer, and then rendering like you would anything else. See this for rendering to a texture and this for rendering any part of an image to any place in the canvas or another texture.

gman
  • 100,619
  • 31
  • 269
  • 393
  • those examples above are good. I use texture atas or draw images to 2d canvas and get bigger texture before. But this are expensive processes. I already have 2dtextures in memory I just put them one big texture. May be there is a way whihc is I dont know. But I think its not possible. Thanks for answer. – H. Akkaya Apr 11 '20 at 18:15