I am trying to create a headless renderer which takes 2 models with different textures and then renders them both into a single image
texture = ctx.texture(texture_image.size, 3, texture_image.tobytes())
texture.build_mipmaps()
texture1 = ctx.texture(texture_image1.size, 3, texture_image1.tobytes())
texture1.build_mipmaps()
# Vertex Buffer and Vertex Array
vbo = ctx.buffer(vertex_data)
vao = ctx.simple_vertex_array(
prog, vbo, *['in_vert', 'in_text', 'in_norm'])
for i in range(2):
# Matrices and Uniforms
# Framebuffers
fbo = ctx.framebuffer(
ctx.renderbuffer((512, 512)),
ctx.depth_renderbuffer((512, 512)),
)
# Rendering
fbo.use()
ctx.enable(ModernGL.DEPTH_TEST)
ctx.clear(0.9, 0.9, 0.9)
texture.use()
vao.render()
vbo = ctx.buffer(cylinder)
vao = ctx.simple_vertex_array(
prog, vbo, *['in_vert', 'in_text', 'in_norm'])
fbo.use()
ctx.enable(ModernGL.DEPTH_TEST)
# ctx.clear(0.9, 0.9, 0.9)
texture1.use()
vao.render()
# Loading the image using Pillow
data = fbo.read(components=3, alignment=1)
img = Image.frombytes('RGB', fbo.size, data, 'raw', 'RGB', 0, -1)
# del data
# del img
img.save(f'output{i}.png')
if __name__ == '__main__':
import time
start = time.time()
main()
end = time.time()
print(end-start)
In this only the second model is finally exported and the initial model is overwritten. I tried a lot of resources to find an answer to this but couldn't find any.
Edit- Added an image of what I am trying to create. The first model i.e. the cylinder and then the watch over it with a different texture.