# 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();

padr4 = Vector(rect.x1, rect.y1, 0);
padr4 = Vector(rect.x2, rect.y1, 0);
padr4 = Vector(rect.x2, rect.y2, 0);
padr4 = Vector(rect.x1, rect.y2, 0);

Vector cadr = { Vector(0.5) };
Vector vnadr = { Vector(0, 0, 1) };
uvadr = Vector(0, 0, 0);
uvadr = Vector(1, 0, 0);
uvadr = Vector(1, 1, 0);
uvadr = Vector(0, 1, 0);

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 = Vector(f['cl'], f['ct'], 0)
padr4 = Vector(f['cr'], f['ct'], 0)
padr4 = Vector(f['cr'], f['cb'], 0)
padr4 = Vector(f['cl'], f['cb'], 0)

cadr = times(4, Vector)
vnadr = times(4, lambda: Vector(0, 0, 1))
uvadr = [None] * 4
uvadr = Vector(0, 0, 0)
uvadr = Vector(1, 0, 0)
uvadr = Vector(1, 1, 0)
uvadr = Vector(0, 1, 0)

bd.SetMatrix_Screen()
``````

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)
``````

Looks quite funny: -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();

padr4 = Vector(rect.x1, rect.y1, 0);
padr4 = Vector(rect.x2, rect.y1, 0);
padr4 = Vector(rect.x2, rect.y2, 0);
padr4 = Vector(rect.x1, rect.y2, 0);

uvadr = Vector(0, 0, 0);
uvadr = Vector(1, 0, 0);
uvadr = Vector(1, 1, 0);
uvadr = Vector(0, 1, 0);

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