How to use setRamData()?

I’ve posted a stackoverflow question regarding this. Anyone who can help, a response would be much a appreciated (here to there, doesn’t matter; I’ve posted on stackoverflow purely in the hopes of increased visiblity): … in-panda3d

I’m not sure if I understand you question. Is it about how to set data for a PTAUchar or about setRamImage - since you post that you have found a way which works?

If so your post on stackoverflow is pretty useless, since you don’t explain what PTAUchar is (PointerTo an Array of “unsigned character”). I doubt that anybody outside this forum knows about the details of the Panda3D reference counting system, and the classes it offers.

Also nobody knows what datatype the variable “rbg” has, and this variable is crucial. Since you can apply the Python method ord() on it I assume it is a ASCII-string (no unicode characters!). If so it is pretty simple:

>>> rgb = "abcdefghi"
>>> x = PTAUchar.emptyArray(len(rgb))
>>> x.setData(rgb)

Or even shorter, since you need a const-pointer anyway:

x = CPTAUchar(rgb)

All the info is on the stack overflow question, but yes, basically:

The “rgb” is an array of unsigned char * in c, which is returned as a POINTER(c_char) type.

My question is perhaps better captured by, how do you use setRamImage on an array of pixel data (of type char) from C.

My apologies for not making that clear.


Calling setData(rgb) makes the length of PTAUchar object 4, instead of 921600 (640x480x3).

I don’t know why; obviously PTAUchar is magical or has ponies in it or something.

I’ve seen a lot of little posts about how this is done, but no complete examples anywhere; so if you have any, please point me in the right direction~

Here, I stuck an example of my sucky code up on github showing exactly what I’m doing, and how its not working:

If you have been reading my post you know that PTAUchar wants to have a python string. So you have to get a string from your ar library. You never checked to type and length of rgb, right?

This is not a Panda3D question, but a ctypes question. Modify you ctypes bindings accordingly. E.g. consider using restype=c_char_p and then rgb.value.

By the way, the project files are pretty useless on Windows/VisualStudio.

c_char_p is NULL terminated, so that doesn’t work.

Actually the solution (from stackoverflow) is to convert the POINTER(c_char) into a string type using rgb[:expectedSize]

The solution is committed to the git repository which I’ll leave up there as a permanent reference for anyone who has the same issues in the future.

Incidentally, cmake supports visual studio, you just have to choose the correct build type… but my code is c99, not c89 (VS has no proper c support these days, shrug) so if you do want to use the example on windows you’ll have to use clang; I recommend the MSYS project to build native windows binaries: