WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   wxImage to Texture (https://forum.worldviz.com/showthread.php?t=1960)

Penguin 04-09-2009 08:51 AM

wxImage to Texture
 
Hi,

I'm using wxPython to get a screenshot from a hidden window how it is described here.

Now I want to use the screenshot image as a texture on a Vizard object (e.g. a plane) without writing it to the harddisk and read it again with viz.addTexture() because this would be slow for repetitive image generation with short time intervals.

Is there a way to load the wxImage direct to a texture? Maybe using viz.addTextureFromBuffer() in some kind?

farshizzo 04-09-2009 03:53 PM

Yes, you can copy the image data directly into an existing Vizard texture using the texture.setImageData() command. Here is a sample script:
Code:

import viz
import wx
viz.go()

def WXIMAGE_TO_TEXTURE(image,texture):
        """Convert wxImage object to Vizard texture"""
        img = image.Mirror(False)
        tex.setImageData(img.GetData(),[img.GetWidth(),img.GetHeight()])

#Create wxImage from a bitmap
app = wx.PySimpleApp()
img = wx.Image('image.bmp')

#Create blank Vizard texture
tex = viz.addBlankTexture([1,1])

#Copy image to texture
WXIMAGE_TO_TEXTURE(img,tex)

#Create quad to display texture
quad = viz.addTexQuad(pos=(0,1.8,2),texture=tex)



All times are GMT -7. The time now is 12:31 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC