i want to draw on a textured object. The object should
be a textured polygon, and i would like to alter
( and then read back ) the applied texture. Like eg. drawing
a face on a sphere and then retrieving the texture.
An implementation could be
get cursor/object intersection position
get texture coordinate at that position
alter texture at these pixels
Is there any alternative implementation possible
without the cursor/object intersection code? Or is
there any magically simple way to get the texture
coordinate from a cursor position ( screen position )
i havent found so far?
You can check if the opposite way is feasible: move your cursor on the image, and draw the cursor position on a secondary image, then when applied on the object, you’ll see where your cursor is on the object. And for drawing, simply modify the first image.
With glTexSubImage it could work. However for complicated objects, this might not be easy to draw…
Try projective texturing, similarly to shadowmaps.
Clear a RGBA texture to vec4(0,0,0,0), draw the blotches of paint on it (do update the Alpha channel) in screen-space.
Then, start drawing the object’s triangles on the object’s texture, in 2D. (use the ST coords as gl_Position). On each vertex or fragment, project that RGBA texture and sample from it. (need alphablending enabled).
The next step would be to do custom face-culling and depthtest in the shader.
render the scene to multiple render targets, with a specific shader, that outputs texcoords, positions (in whichever space), [ and optionally “uniform int objectIdx;” and gl_PrimitiveID ] .