Dynamic array and OpenGL problem

Mikko Ronkainen mikoro at iki.fi
Tue Jan 15 02:05:06 PST 2008


Ok, I'm still trying to optimize the code a little. I'm trying to code my own little
software 3D "engine" and here's a snippet from the triangle scan conversion:

int leftOffset = (y * framebufferWidth + cast(int)(leftX + 0.5)) * 3;
int rightOffset = (y * framebufferWidth + cast(int)(rightX + 0.5)) * 3;

for(int i=leftOffset; i<=rightOffset; i+=3)
{
    framebuffer[i] = color.r;
    framebuffer[i + 1] = color.g;
    framebuffer[i + 2] = color.b;
}

It draws one scan line from a triangle (setting all pixels on a line from leftOffset to
rightOffset to given color). Now it seems that in C you can go about it something like
this (pseudo code):

memset(framebuffer+left, color, (right-left+1));

This assumes color is an int so framebuffer format is RGBA. Now I did a test in D like
this:

ubyte[] framebuffer = window.getFramebuffer();
memset(framebuffer.ptr, 0xffff, 1);

I thought I would get a white and a red pixel (framebuffer format is RGB), but just got
one red pixel. I get one white, if I change last parameter to 3, so it seems memset in this case only writes bytes. My question is: what is the fastest way to set continuous block of bytes to some repeating sequence (int this case rgb[a] values)?



More information about the Digitalmars-d-learn mailing list