Texture : Creating/Changing during run ?

Im trying to create a texture instead of loading it.
I first found pixelBuffer but I think this is no longer used.
Now I am looking at PNMImage.

I have tried…

a = PNMImage( 10, 10, 3, 255, <b> )

But I am stuck with what should be as its not really a file.
Ive tried looking over the PNMFileTypeRegistry but keep drawing a blank.

Any ideas greatly appreciated.

The last parameter to the PNMImage constructor is an instance of PNMFileType, which indicates what file type you want to use if you write the image to disk, e.g. TIFF file or JPEG file. Normally, you will simply omit this parameter (it’s optional), which means to infer the intended file type from the filename extension, but if you wanted to specify the file type explicitly you would use the PNMFileTypeRegistry to get an instance of the appropriate PNMFileType object to use, via e.g. PNMFileTypeRegistry.getGlobalPtr().getTypeFromExtension(“jpg”). Of course, if your only purpose of creating a PNMImage is to load it directly into a Texture, then you almost certainly just want to omit this parameter, since you won’t be writing the image to disk anyway.

You probably will also want to use an image size that is a power of 2, for instance 16, 16 instead of 10, 10, since many graphics cards require textures to be sized in powers of 2.


Thanks for the reply David.

I noticed I can then set the vals using the…
setXel( x, y, r, g, b )
and get using
getXel( x, y )

But looking at the code, it seems like a long way to do things;
Create PNMImage
Use setXel on each pixel
Convert to Texture

Any suggestions for faster pixel manipulation?
Is there a way to use Texture with access to the pixel array through python? Or would I need to mod the panda code to allow this?

In the end I will probably write it in c++, but it would be nice to see how it all works through python.

Thanks in advance.

It is a long way to do things, though when you are working in Python it probably doesn’t matter too much.

In C++ it is possible to manipulate the pixels of a Texture directly, but in Panda3D 1.0 you have to know what you are doing. For Panda3D 1.1, we have completely rewritten the API to manipulate a Texture’s pixels, and now it will be much simpler. So I would advise waiting for that new interface to come out if you are considering making the jump to C++. :slight_smile:


Thanks for the info, I am looking forward to 1.1 :slight_smile:

Is there an ETA and/or feature list available?

Even if its only a vague guestimate :wink:

Josh is working hard on getting the stuff he’s been working on ready for distribution, and ultimately he will be the one to produce the actual distribution itself–so I’m not really in a position to make an estimate on when it will be ready at this point. But if I were to guess in the dark, I’d say probably another two or three weeks.

Many of the “features” will be just significant refinements of what’s already there, such as the Texture API rewrite, but the manual already has some new pages for features that will be brand new for 1.1. Josh is busy reworking the Cg shader interface right now.


I’m eagerly waiting to see what’s in 1.1 - terrain heightmaps, for example, to see if it’s suitable for my needs. 8)

Hmmm… would be nice to see a 1.1 soon… but I guess its better to give him a bit more time to polish everything… noting is worse than some errors that occured because of time trouble that do occur only from time to time…

As for the manual… will ther be a list of changes (manual changes) somewhere except the wiki? That one isn’t very “user friendly” if you want to see changes at the first view. You can do it by looking at the title page, but that would show ALL changes (what is more than 50) - you can’t really subscribe to a particular section and let it send you a message when the page you described for is changed - at least that feature would be great…

(if its implemented already I am either blind or too dumb to use it…)

Regards, Bigfoot29

uh, forgot: of course there is a possibility to let you show the changes per section, but that means that you need to switch to the section, let you show the changes and then need to switch to the next section even if there weren’t changes… - kinda odd… (and time-consuming)

Regards, Bigfoot29