InitGLImage usage?

On 29/01/2013 at 06:05, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   13 
Platform:   Windows  ;   
Language(s) :     C++  ;

---------
Hi, anyone knows to use this function?
I want to shown my shader as texture on objects. But gives black textures
my test code:

Bool Material::InitGLImage(BaseMaterial\* mat, BaseDocument\* doc, BaseThread\* th, BaseBitmap\* bmp, LONG doccolorspace, Bool linearworkflow)  
{  

LONG w = bmp->GetBw();

    LONG h = bmp->GetBh();


  



    unsigned long \*tmp = new unsigned long[w];


    for (int x=0; x<w; x++) tmp[x]=0xffffffff;


    


    for (int y=0; y<h; y++)


    {


        Bool ok = bmp->SetPixelCnt(0, y, 4\*w,  (UCHAR \* )( tmp ),COLORBYTES_ARGB, COLORMODE_ARGB,PIXELCNT_0);


    }


  



     delete [] tmp;


  



    return true;  
}  

On 29/01/2013 at 08:06, xxxxxxxx wrote:

Hi and welcome to the Plugin Cafe!

Your code doesn't work because you don't allocate the expected number of pixel components and the cnt parameter of the call to BaseBitmap::SetPixelCnt() is wrong.
You have to allocate 4 components for each pixel if you want COLORBYTES_ARGB. And the components have to be of UCHAR type, not unsigned long. The cnt parameter of BaseBitmap::SetPixelCnt() expects the number of pixels to set; it doesn't include the total count of allocated components.

Also, please use the types and macros from CINEMA SDK whenever possible: LONG instead of int, gNew instead of new, gDelete instead of delete etc.
This is for better portability and stability of the plugins.

Here's the working code:

Bool Material::InitGLImage(BaseMaterial* mat, BaseDocument* doc, BaseThread* th, BaseBitmap* bmp, LONG doccolorspace, Bool linearworkflow)
{
    LONG w = bmp->GetBw();
    LONG h = bmp->GetBh();
  
    UCHAR *line = gNew UCHAR[w*4];
    for (LONG x=0; x<w*4; x++)
        line[x] = 0xff;
    
    for (LONG y=0; y<h; y++)
        bmp->SetPixelCnt(0, y, w, line, COLORBYTES_ARGB, COLORMODE_ARGB, PIXELCNT_0);
  
    gDelete(line);
  
    return TRUE;
}

On 29/01/2013 at 08:33, xxxxxxxx wrote:

hey cool, worked
thanks very much