Re: Material colors and multiple pfPipeWindows

New Message Reply Date view Thread view Subject view Author view

Brian Furtaw (brian++at++dingbat.clubfed.sgi.com)
Mon, 25 Aug 1997 16:19:28 -0400


Daniela,

I tried two different approaches to solve your problem the first which ran much
faster then the second, I created a seconf matrl state->mtl1 and applied it in
the first channel then created and applied state->mtl in the second channel.

The second way I tired was using one matrl definition state->mtl I created it
in the first channel and apply'd it to both but this ran considerably slower.

Please see the changes I made in OpenWindow() and to shared state in the
attached code.

I think you are having this problem because each channel has its own global
GeoState and when you tried to recreate the state->mtl in the second call to
OpenWindow() it was changing the value of the pointer in the sharedState and
Performer ignored the new matrl in the second channels global GeoState. You do
have to enable lighting in both channels because of the separate global
GeoStates.

Brian

On Aug 22, 6:08pm, Daniela Rainer (RUS) wrote:
> Subject: Material colors and multiple pfPipeWindows
>
> Hello,
>
> I have a state problem with in an application with multiple windows and I
> attached a small test example that shows the problem:
>
> Both windows have the same view of an object. The object geoset contains
colors
> and normals.
>
> I defined a global material with all components set to grey or white and
> pfMtlColorMode(state->mtl, PFMTL_BOTH, PFMTL_CMODE_OFF) which should prohibit
> that the object is drawn with the geometry colors.
>
> Of course this is only a test program that should show the inconsistency
> between the two windows, normally I would not define geometry colors and then
> doesn't use them.
>
> In the first window this looks like it was defined (an uncolored cube but
> shaded cube) but in the second window the object is always drawn ambient with
> the geometry color.
>
> Does anybody have experience with multiple windows and state problems?
>
> I compiled this program on an Indy 24-bit with IRIX 6.2 and Performer2.0.1.
>
> Thanks for any help.
>
> Best Regards
> Daniela
>
>
>
> --
> -------------------------------------------------------------------------
> Daniela Rainer | email: rainer++at++rus.uni-stuttgart.de
> Rechenzentrum Uni Stuttgart (RUS) | Tel: +49 (0) 711 685 5790
> Allmandring 30a, 70550 Stuttgart | Fax: +49 (0) 711 682 357
>
> [ Text ] :
>
> /****************************************************************************************/
> /*
                                                                                */
> /* Test for multiple windowsmaterial
                                                   */
> /* Spotlight seem to have a problem on RealityEngine with Performer 2.01
        */
> /*
                                                                                */
> /* OpenGL based Performer 2.0(1)
                                                */
> /*
                                                                                */
> /* cc -o state_multiwin state_multiwin.c -lGLU -lGL -lpf_ogl -lpfdu_ogl
                */
> /* -lpfutil_ogl -lmpc -limage -lfm -lXirisw -lXm -lXt -lfpe -lXmu -lX11
        */
> /* -lm -lmalloc -lC -lXext
                                                        */
> /*
                                                                                */
> /****************************************************************************************/
>
> #include <stdlib.h>
> #include <stdio.h>
> #include <math.h>
>
>
> #define PF_CPLUSPLUS_API 0
> #include <Performer/pf.h>
> #include <Performer/pr.h>
> #include <Performer/pfutil.h>
> #include <Performer/pfdu.h>
> #include <Performer/pfui.h>
>
>
> void OpenWindow(pfPipeWindow *pw);
> void DrawFunc(pfChannel *chan, void *data);
> void PreDraw(pfChannel *chan, void *data);
> void PostDraw(pfChannel *chan, void *data);
>
> pfGeode *loadCube(float size);
>
> typedef struct
> {
> pfLightModel *lm;
> pfLight *lt;
> pfMaterial *mtl;
>
> } sharedState;
>
> sharedState *state;
>
> int
> main(int argc, char *argv[])
> {
> pfChannel *chan1, *chan2;
> pfScene *scene;
> pfDCS *rotateDCS;
> pfGeode *cubeGeode;
> pfGeode *testObject;
> pfMatrix DCSMat, mat;
> pfPipeWindow *pw1, *pw2;
> pfCoord view;
> pfVec3 axis;
>
> pfInit();
>
> state = (sharedState *) pfCalloc(1, sizeof(sharedState),
pfGetSharedArena());
>
> pfMultiprocess(PFMP_APPCULL_DRAW);
>
> pfConfig();
>
> scene = pfNewScene();
> rotateDCS = pfNewDCS();
> cubeGeode = loadCube(5.0f);
> pfAddChild(scene, rotateDCS);
> pfAddChild(rotateDCS, cubeGeode);
>
> pw1 = pfNewPWin(pfGetPipe(0));
> pfPWinOriginSize(pw1, 100, 100, 400, 400);
> pfPWinConfigFunc(pw1, OpenWindow);
> pfConfigPWin(pw1);
> pfFrame();
>
> pw2 = pfNewPWin(pfGetPipe(0));
> pfPWinOriginSize(pw2, 500, 100, 400, 400);
> pfPWinConfigFunc(pw2, OpenWindow);
> pfConfigPWin(pw2);
> pfFrame();
>
> chan1 = pfNewChan(pfGetPipe(0));
> pfChanTravFunc(chan1, PFTRAV_DRAW, DrawFunc);
> pfChanScene(chan1,scene);
> pfChanNearFar(chan1, 8.0, 20.0);
> pfMakePerspChan(chan1,-3.0f, 3.0f, -3.0f, 3.0f);
> pfSetVec3(view.xyz, 0.0f, -14.0f, 0.0f);
> pfSetVec3(view.hpr, 0.0f, 0.0f, 0.0f);
> pfChanView(chan1, view.xyz, view.hpr);
> pfAddChan(pw1, chan1);
>
> chan2 = pfNewChan(pfGetPipe(0));
> pfChanTravFunc(chan2, PFTRAV_DRAW, DrawFunc);
> pfChanScene(chan2,scene);
> pfChanNearFar(chan2, 8.0, 20.0);
> pfMakePerspChan(chan2,-3.0f, 3.0f, -3.0f, 3.0f);
> pfSetVec3(view.xyz, 0.0f, -14.0f, 0.0f);
> pfSetVec3(view.hpr, 0.0f, 0.0f, 0.0f);
> pfChanView(chan2, view.xyz, view.hpr);
> pfAddChan(pw2, chan2);
>
> pfSetVec3(axis,1.0f, 0.0f, 0.0f);
> pfNormalizeVec3(axis);
> pfMakeRotMat(mat, 0.9f,axis[0], axis[1], axis[3]);
>
> while (1)
> {
> pfSync();
>
> pfGetDCSMat(rotateDCS, DCSMat);
> pfPostMultMat(DCSMat, mat);
> pfDCSMat(rotateDCS, DCSMat);
>
> pfFrame();
>
>
> }
> }
>
>
> void
> OpenWindow(pfPipeWindow *pw)
> {
>
>
> pfOpenPWin(pw);
>
> pfPWinIndex(pw, PFWIN_GFX_WIN);
> pfSelectPWin(pw);
>
> /* global state */
> pfCullFace(PFCF_OFF);
> pfShadeModel(PFSM_GOURAUD);
> pfEnable(PFEN_LIGHTING);
>
> /* twosided lighting */
> state->lm = pfNewLModel(pfGetSharedArena());
> pfLModelTwoSide(state->lm, PF_ON);
> pfLModelLocal(state->lm, PF_ON);
> pfApplyLModel(state->lm);
>
> /* finite light */
> state->lt = pfNewLight(pfGetSharedArena());
> pfLightPos(state->lt, 0.0f, 0.0f, 10.0f, 1.0f);
> pfLightColor(state->lt, PFLT_DIFFUSE, 1.0f, 1.0f, 1.0f);
> pfLightColor(state->lt, PFLT_AMBIENT, 0.1f, 0.1f, 0.1f);
> pfLightColor(state->lt, PFLT_SPECULAR, 1.0f, 1.0f, 1.0f);
>
> /* two sided material that ignores all geometry colors*/
> state->mtl = pfNewMtl(pfGetSharedArena());
> pfMtlSide(state->mtl, PFMTL_BOTH);
> pfMtlColorMode(state->mtl, PFMTL_BOTH, PFMTL_CMODE_OFF);
> pfMtlColor(state->mtl, PFMTL_AMBIENT, 0.2, 0.2, 0.2);
> pfMtlColor(state->mtl, PFMTL_DIFFUSE, 0.9, 0.9, 0.9);
> pfMtlColor(state->mtl, PFMTL_SPECULAR, 0.8, 0.8, 0.8);
> pfMtlColor(state->mtl, PFMTL_EMISSION, 0.0f, 0.0f, 0.0f);
> pfMtlShininess(state->mtl, 16.0f);
> pfApplyMtl(state->mtl);
>
>
> }
>
> void
> DrawFunc(pfChannel *chan, void *data)
> {
> PreDraw(chan,data);
> pfDraw();
> PostDraw(chan,data);
> }
>
> void
> PreDraw(pfChannel *chan, void *data)
> {
>
> pfLightOn(state->lt);
> pfClearChan(chan);
>
>
> }
>
> void
> PostDraw(pfChannel *leftChan, void *data)
> {
>
> }
>
>
> pfGeode
> *loadCube(float size)
> {
> pfGeoSet *cubeGeoSet;
> pfGeode *cubeGeode;
> pfGeoState *cubeGeoState;
> pfMatrix scaleMat, rotMat;
> static pfVec4 *cubeColor;
> pfMaterial *cubemtl;
>
> cubeGeode = pfNewGeode();
> cubeGeoSet = pfdNewCube(pfGetSharedArena());
>
> cubeColor = (pfVec4 *)pfCalloc(1, sizeof(pfVec4), pfGetSharedArena());
> pfSetVec4(cubeColor[0], 0.0f, 1.0f, 1.0f, 1.0f);
> pfGSetAttr(cubeGeoSet, PFGS_COLOR4, PFGS_OVERALL, cubeColor, NULL);
>
> pfMakeScaleMat(scaleMat, size, size, size);
> pfdXformGSet(cubeGeoSet, scaleMat);
>
> pfMakeRotMat(rotMat, 45.0f, 1.0f, 0.0f, 0.0f);
> pfdXformGSet(cubeGeoSet, rotMat);
>
> pfAddGSet(cubeGeode, cubeGeoSet);
>
> return(cubeGeode);
>
> }
>
>
>-- End of excerpt from Daniela Rainer (RUS)

-- 
    ----oOOo----    ----oOOo----    ----oOOo----    ----oOOo----

Brian Furtaw (brian++at++sgi.com) VisSim Technical Consultant 12200-G Plum Orchard Drive Office:(301)572-3293 Fax: (301)872-3293 Silver Spring, Maryland 20904 OpenGL/ImageVision/OpenInventor/Performer

/****************************************************************************************/ /* */ /* Test for multiple windowsmaterial */ /* Spotlight seem to have a problem on RealityEngine with Performer 2.01 */ /* */ /* OpenGL based Performer 2.0(1) */ /* */ /* cc -o state_multiwin state_multiwin.c -lGLU -lGL -lpf_ogl -lpfdu_ogl */ /* -lpfutil_ogl -lmpc -limage -lfm -lXirisw -lXm -lXt -lfpe -lXmu -lX11 */ /* -lm -lmalloc -lC -lXext */ /* */ /****************************************************************************************/

#include <stdlib.h> #include <stdio.h> #include <math.h>

#define PF_CPLUSPLUS_API 0 #include <Performer/pf.h> #include <Performer/pr.h> #include <Performer/pfutil.h> #include <Performer/pfdu.h> #include <Performer/pfui.h>

void OpenWindow(pfPipeWindow *pw); void DrawFunc(pfChannel *chan, void *data); void PreDraw(pfChannel *chan, void *data); void PostDraw(pfChannel *chan, void *data);

pfGeode *loadCube(float size);

typedef struct { pfLightModel *lm; pfLight *lt; pfMaterial *mtl, *mtl1;

} sharedState;

sharedState *state;

int main(int argc, char *argv[]) { pfChannel *chan1, *chan2; pfScene *scene; pfDCS *rotateDCS; pfGeode *cubeGeode; pfGeode *testObject; pfMatrix DCSMat, mat; pfPipeWindow *pw1, *pw2; pfCoord view; pfVec3 axis;

pfInit();

state = (sharedState *) pfCalloc(1, sizeof(sharedState), pfGetSharedArena());

pfMultiprocess(PFMP_DEFAULT /*APPCULL_DRAW*/);

pfConfig();

scene = pfNewScene(); rotateDCS = pfNewDCS(); cubeGeode = loadCube(5.0f); pfAddChild(scene, rotateDCS); pfAddChild(rotateDCS, cubeGeode);

pw1 = pfNewPWin(pfGetPipe(0)); pfPWinOriginSize(pw1, 100, 100, 400, 400); pfPWinConfigFunc(pw1, OpenWindow); pfConfigPWin(pw1); pfFrame();

pw2 = pfNewPWin(pfGetPipe(0)); pfPWinOriginSize(pw2, 500, 100, 400, 400); pfPWinConfigFunc(pw2, OpenWindow); pfConfigPWin(pw2); pfFrame();

chan1 = pfNewChan(pfGetPipe(0)); pfChanTravFunc(chan1, PFTRAV_DRAW, DrawFunc); pfChanScene(chan1,scene); pfChanNearFar(chan1, 8.0, 20.0); pfMakePerspChan(chan1,-3.0f, 3.0f, -3.0f, 3.0f); pfSetVec3(view.xyz, 0.0f, -14.0f, 0.0f); pfSetVec3(view.hpr, 0.0f, 0.0f, 0.0f); pfChanView(chan1, view.xyz, view.hpr); pfAddChan(pw1, chan1);

chan2 = pfNewChan(pfGetPipe(0)); pfChanTravFunc(chan2, PFTRAV_DRAW, DrawFunc); pfChanScene(chan2,scene); pfChanNearFar(chan2, 8.0, 20.0); pfMakePerspChan(chan2,-3.0f, 3.0f, -3.0f, 3.0f); pfSetVec3(view.xyz, 0.0f, -14.0f, 0.0f); pfSetVec3(view.hpr, 0.0f, 0.0f, 0.0f); pfChanView(chan2, view.xyz, view.hpr); pfAddChan(pw2, chan2);

pfSetVec3(axis,1.0f, 0.0f, 0.0f); pfNormalizeVec3(axis); pfMakeRotMat(mat, 0.9f,axis[0], axis[1], axis[3]); while (1) { pfSync();

pfGetDCSMat(rotateDCS, DCSMat); pfPostMultMat(DCSMat, mat); pfDCSMat(rotateDCS, DCSMat);

pfFrame(); } }

void OpenWindow(pfPipeWindow *pw) { static int doIt = 1; pfGeoState *gstate;

pfOpenPWin(pw);

pfPWinIndex(pw, PFWIN_GFX_WIN); pfSelectPWin(pw);

/* global state */ pfCullFace(PFCF_OFF); pfShadeModel(PFSM_GOURAUD); pfEnable(PFEN_LIGHTING); /* This call must be made in both windows to * get lighting. */ if(doIt) { doIt = 0; /* two sided material that ignores all geometry colors*/ state->mtl1 = pfNewMtl(pfGetSharedArena()); pfMtlSide(state->mtl1, PFMTL_BOTH); pfMtlColorMode(state->mtl1, PFMTL_BOTH, PFMTL_CMODE_OFF); pfMtlColor(state->mtl1, PFMTL_AMBIENT, 0.2, 0.2, 0.2); pfMtlColor(state->mtl1, PFMTL_DIFFUSE, 0.9, 0.9, 0.9); pfMtlColor(state->mtl1, PFMTL_SPECULAR, 0.8, 0.8, 0.8); pfMtlColor(state->mtl1, PFMTL_EMISSION, 0.0f, 0.0f, 0.0f); pfMtlShininess(state->mtl1, 16.0f); pfApplyMtl(state->mtl1); } else { /* twosided lighting */ state->lm = pfNewLModel(pfGetSharedArena()); pfLModelTwoSide(state->lm, PF_ON); pfLModelLocal(state->lm, PF_ON); pfApplyLModel(state->lm);

/* finite light */ state->lt = pfNewLight(pfGetSharedArena()); pfLightPos(state->lt, 0.0f, 0.0f, 10.0f, 1.0f); pfLightColor(state->lt, PFLT_DIFFUSE, 1.0f, 1.0f, 1.0f); pfLightColor(state->lt, PFLT_AMBIENT, 0.1f, 0.1f, 0.1f); pfLightColor(state->lt, PFLT_SPECULAR, 1.0f, 1.0f, 1.0f); /* two sided material that ignores all geometry colors*/ state->mtl = pfNewMtl(pfGetSharedArena()); pfMtlSide(state->mtl, PFMTL_BOTH); pfMtlColorMode(state->mtl, PFMTL_BOTH, PFMTL_CMODE_OFF); pfMtlColor(state->mtl, PFMTL_AMBIENT, 0.2, 0.2, 0.2); pfMtlColor(state->mtl, PFMTL_DIFFUSE, 0.9, 0.9, 0.9); pfMtlColor(state->mtl, PFMTL_SPECULAR, 0.8, 0.8, 0.8); pfMtlColor(state->mtl, PFMTL_EMISSION, 0.0f, 0.0f, 0.0f); pfMtlShininess(state->mtl, 16.0f); pfApplyMtl(state->mtl); }

}

void DrawFunc(pfChannel *chan, void *data) { PreDraw(chan,data); pfDraw(); PostDraw(chan,data); }

void PreDraw(pfChannel *chan, void *data) { pfLightOn(state->lt); pfClearChan(chan); }

void PostDraw(pfChannel *leftChan, void *data) { }

pfGeode *loadCube(float size) { pfGeoSet *cubeGeoSet; pfGeode *cubeGeode; pfGeoState *cubeGeoState; pfMatrix scaleMat, rotMat; static pfVec4 *cubeColor; pfMaterial *cubemtl; cubeGeode = pfNewGeode(); cubeGeoSet = pfdNewCube(pfGetSharedArena()); cubeColor = (pfVec4 *)pfCalloc(1, sizeof(pfVec4), pfGetSharedArena()); pfSetVec4(cubeColor[0], 0.0f, 1.0f, 1.0f, 1.0f); pfGSetAttr(cubeGeoSet, PFGS_COLOR4, PFGS_OVERALL, cubeColor, NULL); pfMakeScaleMat(scaleMat, size, size, size); pfdXformGSet(cubeGeoSet, scaleMat); pfMakeRotMat(rotMat, 45.0f, 1.0f, 0.0f, 0.0f); pfdXformGSet(cubeGeoSet, rotMat); pfAddGSet(cubeGeode, cubeGeoSet);

return(cubeGeode);

}

======================================================================= List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/ Submissions: info-performer++at++sgi.com Admin. requests: info-performer-request++at++sgi.com


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:55:46 PDT

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