line rendering in performer (conclusion; happy ending)

New Message Reply Date view Thread view Subject view Author view

Rudy Darken (darken++at++enews.nrl.navy.mil)
Wed, 8 Jun 94 16:26:13 -0400


Below is Michael Jones' code to create a grid of lines.
I added it as is to smallfly as I had done for my LoadGrid
function which was included in an earlier post. The same
results were observed. The grid was red only when the other
geometry (esprit.flt in my case) was not in view. However,
as suggested by Jim Helman, adding the line noted by **
in the code below which disables lighting for the lines
does eliminate the problem. Thanks very much for your assistance
and patience. This problem has been hanging on for months.
I finally got stubborn enough to fix it.

rudy

*** Begin Michael Jones' code ***

What's your experience with the code below? It's my attempt to draw
lines, and seems to work. I added it to Perfly and all seems well.

/*
 * Make a "grid of lines" graphic object
 */

pfNode *
MakeGrid (void)
{
    void *arena = NULL;
    pfMaterial *material = NULL;
    pfGeoState *geostate = NULL;
    pfGeoSet *geoset = NULL;
    pfGeode *geode = NULL;

    pfVec3 *v = NULL;
    pfVec3 *vp = NULL;
    pfVec4 *c = NULL;

    int nx = 30;
    int ny = 30;
    float x0 = -10.0f;
    float y0 = -10.0f;
    float z0 = 5.0f;
    float x1 = 10.0f;
    float y1 = 10.0f;
    float dx = x1 - x0;
    float dy = y1 - y0;

    int x;
    int y;

    /* access the global shared-memory arena */
    arena = pfGetSharedArena();

    /* make a material that specifies LMC_AD mode */
    material = pfNewMtl(arena);
    pfMtlColor(material, PFMTL_AMBIENT, 0.1, 0.1, 0.1);
    pfMtlColor(material, PFMTL_SPECULAR, 0.8, 0.8, 0.8);
    pfMtlColorMode(material, PFMTL_FRONT, LMC_AD);

    /* specify material but inherit all other geostate attributes */
    geostate = pfNewGState(arena);
    pfGStateAttr(geostate, PFSTATE_FRONTMTL, material);
** pfGStateAttr(geostate, PFSTATE_ENLIGHTING, PF_OFF);

    /* create geoset at attach geostate to it */
    geoset = pfNewGSet(arena);
    pfGSetPrimType(geoset, PFGS_LINES);
    pfGSetGState(geoset, geostate);

    /* build and attach vertex array */
    vp = v = (pfVec3 *)pfMalloc((2*nx + 2*ny)*sizeof(pfVec3), arena);
    for (x = 0; x < nx; x++)
    {
        pfSetVec3(vp++, x0 + x*dx/(nx-1), y0, z0);
        pfSetVec3(vp++, x0 + x*dx/(nx-1), y1, z0);
    }
    for (y = 0; y < ny; y++)
    {
        pfSetVec3(vp++, x0, y0 + y*dy/(ny-1), z0);
        pfSetVec3(vp++, x1, y0 + y*dy/(ny-1), z0);
    }
    pfGSetAttr(geoset, PFGS_COORD3, PFGS_PER_VERTEX, v, NULL);
    pfGSetNumPrims(geoset, nx + ny);

    /* build and attach color array */
    c = (pfVec4 *)pfMalloc(sizeof(pfVec4), arena);
    pfSetVec4(c, 1.0f, 0.0f, 0.0f, 1.0f);
    pfGSetAttr(geoset, PFGS_COLOR4, PFGS_OVERALL, c, NULL);

    /* create geode and attach geoset to it */
    geode = pfNewGeode();
    pfAddGSet(geode, geoset);

    /* return address of geode to caller */
    return (pfNode *)geode;
}

_______________________________________________________________
Rudy Darken <202> 767-6814
darken++at++enews.nrl.navy.mil The U.S. Naval Research Laboratory
darken++at++seas.gwu.edu The George Washington University
_______________________________________________________________


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:50:19 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.