I have a 6 vertex rectangle 100×100 in size, this i covered with a 100×100 background image. now i would like to render two “sub textures” on top of it.
lets say i have two sub textures size 20×20 one of then i like to position at x:10 y:10 and the other x:50 and y:50
(these are actually to get used as masks on the background image.)
how should i go with this ? my first thought was to send a uniform vec2 with the position of the two sub textures info the fragment shader, but i cant really figure out how to convert those into texture2d(subtexture, coordinate) because texture2d takes 0-1 values. i cant really wrap my head around this, and i hope to get some pointers in what direction i should go.
(this is to be used on OpenGL ES 2.0)
Then I think what you’re really looking for is how to update a texture. In you case, the simplest method may be to use
glTexSubImage2D. The following will do what you ask in your original postwhere
<format>, and<type>describe the pixels in the sub-texture stored at<subimage*>. There are quite a lot of additional answers in other questions; just search for glTexSubImage2D.A more complex method (for when things aren’t as simple as your problem) is to use framebuffer objects to render to textures (have search for that one too, if you need).