Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    InitGLImage usage?

    SDK Help
    0
    3
    305
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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;  
      }  
      
      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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;
        }
        
        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

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

          hey cool, worked
          thanks very much

          1 Reply Last reply Reply Quote 0
          • First post
            Last post