Re: pfGeoSet question

New Message Reply Date view Thread view Subject view Author view

Uwe Woessner (woessner++at++hlrs.de)
Mon, 04 Oct 1999 19:54:54 +0200


Hello everybody,

we have a problem with textured strings.
If you load a pfFont with PFDFONT_TEXTURED,
it depends on the Order in the Scenegraph, whether the string is visible
or not.

I attached a little example to this mail, it should show a Text in front
of a rotating cube.
You will need the font file Helvetica.bw to test it.

You will see the effect, if you swap the two lines

pfAddChild(scene, textDCS);
pfAddChild(scene, rotateDCS);

or switch to PFDFONT_FILLED,
then everything is fine.

Can anybody tell me, if I am wrong, this is a bug, or it is a missing
feature?

Regards,
 Uwe

-- 
               \\\|///  *Rechenzentrum Universitaet Stuttgart*
   _I_         ( o o )            *Visualisierung*                 _I_
  (_++at++_)----oo0O--(_)--O0oo----------------------------------------(_++at++_)
   | |      Uwe Woessner      woessner++at++rus.uni-stuttgart.de        | |
   | |         .ooo0       http://www.hlrs.de/people/woessner/     | |
   |_|         (   )  Oooo.      Phone: +49-711-685-5790           |_|
  (_++at++_)---------\ (---(   )---------------------------------------(_++at++_)
    I            \_)   ) /                                          I
                      (_/

/****************************************************************************************/ /* */ /* Simple quadbuffer-stereo example */ /* OpenGL based Performer 2.0(1) */ /* */ /* cc -o testtext testtext.c -lpf_ogl -lpfdu_ogl -lpfutil_ogl */ /* -limage -lGLU -lGL -lX11 -lm */ /* */ /****************************************************************************************/

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

#include <X11/X.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/keysym.h>

#include <GL/gl.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 OpenStereoXWindow(pfPipeWindow *pw); void initChannels(pfChannel *leftChan, pfChannel *rightChan, pfScene *scene); void LeftDrawFunc(pfChannel *chan, void *data); void RightDrawFunc(pfChannel *chan, void *data); pfGeode *loadCube(float size);

pfText * loadText();

int main(int argc, char *argv[]) { pfScene *scene;

pfDCS *rotateDCS; pfDCS *textDCS; pfLightSource *sun; pfGeode *cubeGeode; pfText *text;

pfMatrix mat; pfMatrix DCSMat; pfPipe *pipe; pfPipeWindow *pw; pfChannel *leftChan, *rightChan; pfInit();

pfMultiprocess(PFMP_APP_CULL_DRAW);

pfConfig(); pfuInitUtil();

scene = pfNewScene(); sun = pfNewLSource(); pfLSourcePos(sun, 0.0f, 0.0f, 10.0f, 0.0f); /* infinite light */ pfLSourceColor(sun, PFLT_DIFFUSE, 1.0f, 1.0f, 1.0f); pfLSourceColor(sun, PFLT_AMBIENT, 0.5f, 0.5f, 0.5f); pfLSourceColor(sun, PFLT_SPECULAR, 0.5f, 0.5f, 0.5f); pfLSourceOn(sun); pfAddChild(scene, sun); rotateDCS = pfNewDCS(); cubeGeode = loadCube(2.0f); text = loadText(); textDCS = pfNewDCS(); pfMakeTransMat(mat,-4,-4,0); pfDCSMat(textDCS,mat); pfAddChild(textDCS, text); /* swap the following two lines: */ pfAddChild(scene, textDCS); pfAddChild(scene, rotateDCS); pfAddChild(rotateDCS, cubeGeode);

pipe = pfGetPipe(0); pw = pfNewPWin(pipe); pfPWinOriginSize(pw, 100, 100, 400, 400); pfPWinConfigFunc(pw, OpenStereoXWindow); pfConfigPWin(pw); pfFrame();

/* create a left and a right channel */ leftChan = pfNewChan(pfGetPipe(0)); rightChan = pfNewChan(pfGetPipe(0)); /* configure those channels */ initChannels(leftChan, rightChan, scene);

/* let the cube rotate */ pfMakeRotMat(mat, 0.9, 0.0f, 0.0f,1.0f);

while (1) { pfSync();

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

pfFrame(); } } void initChannels(pfChannel *leftChan, pfChannel *rightChan, pfScene *scene) { float xmin, xmax, zmin, zmax, ynear, yfar, dist, clip_near, clip_far, left, right, bottom, top, dx, dz, n_over_d, yzps, leftEye, rightEye;

pfVec3 xyzOffset, hprOffset; pfCoord view;

pfChanTravFunc(leftChan, PFTRAV_DRAW, LeftDrawFunc); pfChanTravFunc(rightChan, PFTRAV_DRAW, RightDrawFunc);

pfChanScene(leftChan,scene); pfChanScene(rightChan,scene);

/* size of the visible world */ xmin = -6.0f; xmax = 6.0f; zmin = -6.0; zmax = 6.0; ynear = -6.0f; yfar = 6.0f; yzps = 0.0f;

/* values from The CrystalEyes Handbook */ dist = -14.5; rightEye = 0.31; leftEye = -0.31; /*rightEye = 1.31; leftEye = -1.31; */ dx = xmax - xmin; dz = zmax - zmin;

clip_near = fabs(dist + yzps - ynear); clip_far = fabs(dist + yzps - yfar); pfChanNearFar(leftChan, clip_near, clip_far); /* fuer beide channels gleich */ pfChanNearFar(rightChan, clip_near, clip_far); /* fuer beide channels gleich */

/* left, right, top, bottom in channel-Koordinaten */ n_over_d = clip_near/fabs(dist); /* Strahlensatz! */

top = n_over_d* dz/2.0; bottom = -top;

/* Set left channel */ right = n_over_d*(dx/2.0 - leftEye); left = n_over_d*(-dx/2.0 - leftEye); pfMakePerspChan(leftChan, left, right, bottom, top);

/* Set right channel */ right = n_over_d*(dx/2.0 - rightEye); left = n_over_d*(-dx/2.0 - rightEye); pfMakePerspChan(rightChan, left, right, bottom, top);

pfSetVec3(view.xyz, 0.0f, dist, 0.0f); pfSetVec3(view.hpr, 0.0f, 0.0f, 0.0f); pfChanView(leftChan, view.xyz, view.hpr); pfChanView(rightChan, view.xyz, view.hpr);

/* Compute heading offset for horizontal tiling of channels. */ pfSetVec3(hprOffset, 0.0f, 0.0f, 0.0f);

pfSetVec3(xyzOffset, leftEye, 0.0f, 0.0f); pfChanViewOffsets(leftChan,xyzOffset,hprOffset);

pfSetVec3(xyzOffset, rightEye, 0.0f, 0.0f); pfChanViewOffsets(rightChan,xyzOffset,hprOffset);

} void OpenStereoXWindow(pfPipeWindow *pw) {

static int FBAttr[] = { PFFB_RGBA, PFFB_DOUBLEBUFFER, PFFB_STEREO, PFFB_DEPTH_SIZE, 23, PFFB_RED_SIZE, 1, PFFB_STENCIL_SIZE, 1, None }; pfLightModel *lm; pfMaterial *mtl;

/* set up stereo */

pfPWinFBConfigAttrs(pw, FBAttr);

pfOpenPWin(pw);

/* global state */ pfCullFace(PFCF_OFF); pfShadeModel(PFSM_GOURAUD); pfEnable(PFEN_LIGHTING); /* twosided lighting */ lm = pfNewLModel(pfGetSharedArena()); pfLModelTwoSide(lm, PF_ON); pfCullFace(PFCF_OFF); pfApplyLModel(lm); /* two sided material */ mtl = pfNewMtl(pfGetSharedArena()); pfMtlSide(mtl, PFMTL_BOTH); /* replace ambient and diffuse colors with gset colors */ pfMtlColorMode(mtl, PFMTL_BOTH, PFMTL_CMODE_AMBIENT_AND_DIFFUSE); pfMtlColor(mtl, PFMTL_AMBIENT, 0.5, 0.5, 0.5); pfMtlColor(mtl, PFMTL_DIFFUSE, 0.9, 0.9, 0.9); pfMtlColor(mtl, PFMTL_SPECULAR, 0.9, 0.9, 0.9); pfMtlColor(mtl, PFMTL_EMISSION, 0.0f, 0.0f, 0.0f); pfMtlShininess(mtl, 16.0f);

pfApplyMtl(mtl);

}

void RightDrawFunc(pfChannel *chan, void *data) { glDrawBuffer(GL_BACK_RIGHT); pfClearChan(chan); pfDraw(); } void LeftDrawFunc(pfChannel *chan, void *data) { glDrawBuffer(GL_BACK_LEFT); pfClearChan(chan); pfDraw(); }

pfGeode *loadCube(float size) { pfGeoSet *cubeGeoSet; pfGeode *cubeGeode; pfGeoState *geoState; pfMatrix scaleMat, rotMat; pfVec4 *cubeColor; pfMaterial *mtl; cubeGeode = pfNewGeode(); cubeGeoSet = pfdNewCube(pfGetSharedArena()); cubeColor = pfCalloc(1, sizeof(pfVec4), pfGetSharedArena()); pfGSetAttr(cubeGeoSet, PFGS_COLOR4, PFGS_OVERALL, cubeColor, NULL); pfdGSetColor(cubeGeoSet, 0.0f, 1.0f, 1.0f, 1.0f); pfMakeScaleMat(scaleMat, size, size, size); pfdXformGSet(cubeGeoSet, scaleMat); pfMakeRotMat(rotMat, 45.0f, 1.0f, 0.0f, 0.0f); pfdXformGSet(cubeGeoSet, rotMat); mtl = pfNewMtl(pfGetSharedArena()); pfMtlSide(mtl, PFMTL_BOTH); /* replace ambient and diffuse colors with gset colors */ pfMtlColorMode(mtl, PFMTL_BOTH, PFMTL_CMODE_AMBIENT_AND_DIFFUSE); pfMtlColor(mtl, PFMTL_AMBIENT, 0.5, 0.5, 0.5); pfMtlColor(mtl, PFMTL_DIFFUSE, 0.9, 0.9, 0.9); pfMtlColor(mtl, PFMTL_SPECULAR, 0.9, 0.9, 0.9); pfMtlColor(mtl, PFMTL_EMISSION, 0.0f, 0.0f, 0.0f); pfMtlShininess(mtl, 16.0f); geoState = pfNewGState(pfGetSharedArena()); pfMakeBasicGState(geoState); pfGStateAttr(geoState, PFSTATE_FRONTMTL, mtl); pfGStateAttr(geoState, PFSTATE_BACKMTL, mtl); pfGStateMode(geoState, PFSTATE_ENLIGHTING, PF_ON); pfGStateMode(geoState, PFSTATE_TRANSPARENCY, PFTR_OFF); pfGSetGState(cubeGeoSet, geoState); pfAddGSet(cubeGeode, cubeGeoSet);

return(cubeGeode);

}

pfText *loadText() { pfString *string; pfFont *font; pfText *txt;

font = pfdLoadFont("type1", "Helvetica", PFDFONT_TEXTURED);/*PFDFONT_FILLED PFDFONT_TEXTURED*/ if (font != NULL) { string = pfNewString(pfGetSharedArena());

pfStringMode(string, PFSTR_JUSTIFY, PFSTR_LEFT); pfStringColor(string,1.0, 0.0, 0.0,1.0); pfStringFont(string, font); pfStringString(string, "Performer spinnt =:-|");

} else { printf("Error(createString): Cannot load font.\n"); } txt = pfNewText(); pfAddString(txt,string); return txt; }


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Oct 04 1999 - 11:15:53 PDT

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