Re: texgen

New Message Reply Date view Thread view Subject view Author view

Chris Tanner (cct++at++faith)
Wed, 17 Aug 1994 16:19:43 -0700


On Aug 17, 11:17pm, Fernando D. Mato Mira wrote:
> Subject: texgen
>
> Hello,
>
> The man page for pfTexture says:
>
> >>
> For geometry to be textured, the following must be true:
>
> 1. Texturing must be enabled: pfEnable(PFEN_TEXTURE)
>
> 2. A pfTexEnv must be applied: pfApplyTEnv
>
> 3. A pfTexture must be applied: pfApplyTex
>
> 4. Geometry must have texture coordinates: pfGSetAttr,
> PFGS_TEXCOORD2
> >>
>
> Doesn't texgen work also for point 4. ?
> And then, I guess TG_ON and TG_OFF is my own responsibility (so
> that I can override the coords in the pfGeoSet)..
>
> Thanks,
>
> Fernando D. Mato Mira
> Computer Graphics Lab
> Swiss Federal Institute of Technology (EPFL) Phone : +41 (21) 693 - 5248
> CH-1015 Lausanne FAX : +41 (21) 693 - 5328
> Switzerland E-mail : matomira++at++di.epfl.ch
>
>
>-- End of excerpt from Fernando D. Mato Mira

Its very easy to use texgen with Performer. You simply insert callbacks on
nodes that you want to be textured via texgen. That way since you specify that
these callbacks should happen in the "DRAW" traversal, you can turn on and off
texgen as appropriate before and after drawing the geometry in question.

For instance if you had a node named "geodeRefl" on which you wanted to use
texgen to create pseudo environment mapping, then you would make the following
call on the node in order to setup a "draw callback" where "pfuPreDrawReflMap"
is a function that turns texgen for sphere maps on and "pfuPostDrawReflMap"
turns it off.

        pfNodeTravFuncs(geodeRefl, PFTRAV_DRAW, pfuPreDrawReflMap,
pfuPostDrawReflMap);

These functions are even already defined in the libpfutil library in
"callbacks.c" in /usr/src/Performer/src/lib/libpfutil/.
However, if you would like to use other types of texgen (ie linear or contour
mapping), then replace
that file with this one that defines Pre and Post draw callbacks for
Linear,Contour, and Environment mapping...

callbacks.c:

/*
 * Copyright (c) 1994 Silicon Graphics, Inc.
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without
 * fee, provided that (i) the above copyright notices and this
 * permission notice appear in all copies of the software and related
 * documentation, and (ii) the name of Si MERCHANTABILITY OR FITNESS FOR A
PARTICULAR PURPOSE.
 *
 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL,
 * INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY
 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY
 * THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE
 * OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include <stdlib.h>
#include <strings.h>
#include <gl.h>
#include "pf.h"
#include "pfutil.h"
#include "image.h"

static char CallBacks[] = "CallbacksDPool";

static pfMatrix IdentMat =
{ {1.0f,0.0f,0.0f,0.0f},
        {0.0f,1.0f,0.0f,0.0f},
        {0.0f,0.0f,1.0f,0.0f},
        {0.0f,0.0f,0.0f,1.0f}
};

void pfuPrintTexgenParams(void)
{
    pfDataPool *dp;
    float *paramsX, *paramsY;

    dp = pfAttachDPool(CallBacks);
    if (dp == NULL)
        pfuTexgenParams(NULL, NULL);
    paramsX = (float *)pfDPoolFind(dp, 1);
    paramsY = (float *)pfDPoolFind(dp, 2);

    fprintf(stderr,"ParamsX: %f\t%f\t%f\t%f\n",
                paramsX[0],paramsX[1],paramsX[2],paramsX[3]);
    fprintf(stderr,"ParamsY: %f\t%f\t%f\t%f\n",
                paramsY[0],paramsY[1],paramsY[2],paramsY[3]);
}

void pfuGetTexgenParams(float *newParamsX, float *newParamsY)
{
    pfDataPool *dp;
    float *paramsX, *paramsY;
    int i;

    dp = pfAttachDPool(CallBacks);
    if (dp == NULL)
        pfuTexgenParams(NULL, NULL);
    paramsX = (float *)pfDPoolFind(dp, 1);
    paramsY = (float *)pfDPoolFind(dp, 2);
    for (i=0;i<4;i++)
        newParamsX[i] = paramsX[i];
    for (i=0;i<4;i++)
        newParamsY[i] = paramsY[i];
}

void pfuTexgenParams(float *newParamsX, float *newParamsY)
{
    pfDataPool *dp;
    float *paramsX, *paramsY;

    dp = pfAttachDPool(CallBacks);
    if (dp == NULL)
    {
        dp = pfNewDPool(sizeof(float) * 8, CallBacks);
        paramsX = (float *)pfDPoolAlloc(dp, sizeof(float) * 4, 1);
        paramsY = (float *)pfDPoolAlloc(dp, sizeof(float) * 4, 2);
    }
    else
    {
        paramsX = (float *)pfDPoolFind(dp, 1);
        paramsY = (float *)pfDPoolFind(dp, 2);
    }
    if (!newParamsX)
    {
        paramsX[0] = 0.0;
        paramsX[1] = 1.0;
        paramsX[2] = 0.0;
        paramsX[3] = 1.0;
    }
    else
    {
        paramsX[0] = newParamsX[0];
        paramsX[1] = newParamsX[1];
        paramsX[2] = newParamsX[2];
        paramsX[3] = newParamsX[3];
    }
    if (!newParamsY)
    {
        paramsY[0] = 0.0;
        paramsY[1] = 1.0;
        paramsY[2] = 0.0;
        paramsY[3] = 1.0;
    }
    else
    {
        paramsY[0] = newParamsX[0];
        paramsY[1] = newParamsX[1];
        paramsY[2] = newParamsX[2];
        paramsY[3] = newParamsX[3];
    }
}

long pfuPreDrawContourMap(pfTraverser *trav, void *data)
{
    pfDataPool *dp;
    float *paramsX, *paramsY;

    dp = pfAttachDPool(CallBacks);
    if (dp == NULL)
        pfuTexgenParams(NULL, NULL);
    paramsX = (float *)pfDPoolFind(dp, 1);
    paramsY = (float *)pfDPoolFind(dp, 2);

    (trav, trav);
    (data, data);

    mmode(MVIEWING);
    pushmatrix();
    loadmatrix(IdentMat);
    texgen(TX_S, TG_CONTOUR, paramsX);
    texgen(TX_T, TG_CONTOUR, paramsY);
    texgen(TX_S, TG_ON, NULL);
    texgen(TX_T, TG_ON, NULL);
    popmatrix();
    return NULL;
}

long pfuPostDrawContourMap(pfTraverser *trav, void *data)
{
    (trav, trav);
    (data, data);

    texgen(TX_S, TG_OFF, NULL);
    texgen(TX_T, TG_OFF, NULL);

    return NULL;
}

long pfuPreDrawLinearMap(pfTraverser *trav, void *data)
{
    pfDataPool *dp;
    float *paramsX, *paramsY;

    dp = pfAttachDPool(CallBacks);
    if (dp == NULL)
        pfuTexgenParams(NULL, NULL);
    paramsX = (float *)pfDPoolFind(dp, 1);
    paramsY = (float *)pfDPoolFind(dp, 2);
    (trav, trav);
    (data, data);

    texgen(TX_S, TG_SPHEREMAP, paramsX);
    texgen(TX_T, TG_SPHEREMAP, paramsY);
    texgen(TX_S, TG_ON, NULL);
    texgen(TX_T, TG_ON, NULL);

    return NULL;
}

long pfuPostDrawLinearMap(pfTraverser *trav, void *data)
{
    (trav, trav);
    (data, data);

    texgen(TX_S, TG_OFF, NULL);
    texgen(TX_T, TG_OFF, NULL);

    return NULL;
}
long pfuPreDrawReflMap(pfTraverser *trav, void *data)
{
    (trav, trav);
    (data, data);

    texgen(TX_S, TG_SPHEREMAP, 0);
    texgen(TX_T, TG_SPHEREMAP, 0);
    texgen(TX_S, TG_ON, NULL);
    texgen(TX_T, TG_ON, NULL);

    return NULL;
}

long pfuPostDrawReflMap(pfTraverser *trav, void *data)
{
    (trav, trav);
    (data, data);

    texgen(TX_S, TG_OFF, NULL);
    texgen(TX_T, TG_OFF, NULL);

    return NULL;
}

-- 

_____________________________________________________________ Chris Tanner (cct++at++faith.asd.sgi.com) Silicon Graphics - Advanced Graphics Division _____________________________________________________________


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:29 PDT

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