DrawTexture Example

On 01/05/2013 at 13:39, xxxxxxxx wrote:

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

---------
Hi!

Can someone provide a working example of BaseDraw::DrawTexture()? It just doesn't do what I
want so I'm doing something wrong and I can not figure it out.

Some C++ Code:

    Rect_t rect;
    bd->GetSafeFrame(&rect.x1, &rect.y1, &rect.x2, &rect.y2);
  
    // ...
  
    bd->SetMatrix_Screen();
  
    Vector padr4[4];
    padr4[0] = Vector(rect.x1, rect.y1, 0);
    padr4[1] = Vector(rect.x2, rect.y1, 0);
    padr4[2] = Vector(rect.x2, rect.y2, 0);
    padr4[3] = Vector(rect.x1, rect.y2, 0);
  
    Vector cadr[4] = { Vector(0.5) };
    Vector vnadr[4] = { Vector(0, 0, 1) };
    Vector uvadr[4];
    uvadr[0] = Vector(0, 0, 0);
    uvadr[1] = Vector(1, 0, 0);
    uvadr[2] = Vector(1, 1, 0);
    uvadr[3] = Vector(0, 1, 0);
  
    bd->DrawTexture(bmp, padr4, cadr, vnadr, uvadr, 4,
                    DRAW_ALPHA_NORMAL, DRAW_TEXTUREFLAGS_INTERPOLATION_LINEAR);

A Python Version:

    f = bd.GetSafeFrame()
    w = f['cr'] - f['cl']
    h = f['cb'] - f['ct']
  
    # ...
  
    bmp = BaseBitmap()
    bmp.Init(w, h, 24)
    for x in xrange(w) :
        for y in xrange(h) :
            bmp[x, y] = (x, y, 50)
  
    padr4 = [None] * 4
    padr4[0] = Vector(f['cl'], f['ct'], 0)
    padr4[1] = Vector(f['cr'], f['ct'], 0)
    padr4[2] = Vector(f['cr'], f['cb'], 0)
    padr4[3] = Vector(f['cl'], f['cb'], 0)
  
    cadr = times(4, Vector)
    vnadr = times(4, lambda: Vector(0, 0, 1))
    uvadr = [None] * 4
    uvadr[0] = Vector(0, 0, 0)
    uvadr[1] = Vector(1, 0, 0)
    uvadr[2] = Vector(1, 1, 0)
    uvadr[3] = Vector(0, 1, 0)
  
    bd.SetMatrix_Screen()
    bd.DrawTexture(bmp, padr4, cadr, vnadr, uvadr, 4, c4d.DRAW_ALPHA_NONE, c4d.DRAW_TEXTUREFLAGS_INTERPOLATION_NEAREST)

For the Python Version, all I get is a black screen:

I can't really describe the behavior as the behavior seems rather random to me. For example,
changing the cadr array a little:

    cadr = times(4, Vector)
    cadr[0].x = 255
    cadr[1].y = 255

Looks quite funny:

Thanks in advance!
-Niklas

On 01/05/2013 at 14:03, xxxxxxxx wrote:

Okay, nevermind. Seems like the colors from the cadr array are drawn in "over" the texture (in
some strange way). So, this basically works arleady really good!

    Rect_t rect;
    bd->GetSafeFrame(&rect.x1, &rect.y1, &rect.x2, &rect.y2);
  
    // Draw the overlay image on the screen.
    BaseBitmap* bmp = image->GetBitmap();
    if (!bmp) return TRUE;
  
    bd->SetMatrix_Screen();
  
    Vector padr4[4];
    padr4[0] = Vector(rect.x1, rect.y1, 0);
    padr4[1] = Vector(rect.x2, rect.y1, 0);
    padr4[2] = Vector(rect.x2, rect.y2, 0);
    padr4[3] = Vector(rect.x1, rect.y2, 0);
  
    Vector uvadr[4];
    uvadr[0] = Vector(0, 0, 0);
    uvadr[1] = Vector(1, 0, 0);
    uvadr[2] = Vector(1, 1, 0);
    uvadr[3] = Vector(0, 1, 0);
  
    bd->DrawTexture(bmp, padr4, NULL, NULL, uvadr, 4,
                    DRAW_ALPHA_FROM_IMAGE, DRAW_TEXTUREFLAGS_0);

But the alpha display is not really satisfieng:

I am drawing Noise on the GeClipMap using this algorithm:

    image->BeginDraw();
    for (LONG x=0; x < width; x++) {
        for (LONG y=0; y < height; y++) {
            Real v = (SNoise(Vector(x / 50.0, y / 50.0, frame)) + 1) / 2;
            v *= (Real) x / width;
            LONG g = (LONG) (v * 255);
  
            image->SetPixelRGBA(x, y, 255, 255, 255, g);
        }
    }
    image->EndDraw();

Is there anything wrong or is it a limitation of the DrawTexture() method?

Thanks,
-Niklas