0
votes

I have a 6 vertex rectangle 100x100 in size, this i covered with a 100x100 background image. now i would like to render two "sub textures" on top of it.

lets say i have two sub textures size 20x20 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)

1
Do you want the sub textures to become part of the larger texture, or are they really separate objects that lie on top of the "background" rectangle?radical7
it should become part, because actually what i need to do is use the sub textures to mask the large texture.Mads Lee Jensen

1 Answers

0
votes

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 post

glTexSubImage2D( GL_TEXTURE_2D, 0, 10, 10, 20, 20, <format>, <type>, <subimage1> );
glTexSubImage2D( GL_TEXTURE_2D, 0, 50, 50, 20, 20, <format>, <type>, <subimage2> );

where <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).