From: Rajesh R (rajeshr++at++cair.res.in)
Date: 07/26/2005 00:41:05
Dear Performers,
My destiny with background skybox rendering is very poor. So far I have
not able to
render even a background texture. The code given below works. But the
texture is rendering as a front portion instead of a background texture.
Any suggestions pLease,
#include <stdlib.h>
#include <Performer/pf.h>
#include <Performer/pfutil.h>
#include <Performer/pfdu.h>
#include <Performer/prmath.h>
#include <gl.h>
#include <glut.h>
typedef struct
{
long val;
} PassData;
static pfMatrix idmat ={{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 DrawChannel(pfChannel* chan,void *data);
int winWidth = 500;
int winHeight = 500;
void cullFunc(pfChannel *chan, void *data);
void drawFunc(pfChannel *chan, void *data);
int main()
{
PassData *pd;
float t = 0.0f;
char* filename = "esprit.pfb";
int i,j;
pfScene *scene;
pfNode *root;
pfPipe *p;
pfPipeWindow *pw;
pfChannel *chan;
pfSphere bsphere;
pfEarthSky *esky;
static int fbattr[] =
{PFFB_RGBA,PFFB_DOUBLEBUFFER,PFFB_DEPTH_SIZE, 24,
PFFB_RED_SIZE, 8,PFFB_SAMPLES, 8,PFFB_STENCIL_SIZE,
1,NULL,};
/* Initialize Performer */
pfInit();
/* Use default multiprocessing mode based on number of
* processors.
*/
pfMultiprocess( PFMP_DEFAULT );
/* Load all loader DSO's before pfConfig() forks */
pfdInitConverter(filename);
/* initiate multi-processing mode set in pfMultiprocess call
* FORKs for Performer processes, CULL and DRAW, etc. happen here.
*/
pfConfig();
/* Append to Performer search path, PFPATH, files in
* /usr/share/Performer/data */
pfFilePath(".:/usr/share/Performer/data");
/* Read a single file, of any known type. */
if ((root = pfdLoadFile(filename)) == NULL)
{
pfExit();
exit(-1);
}
/* Attach loaded file to a new pfScene. */
scene = pfNewScene();
pfAddChild(scene, root);
/* Create a pfLightSource and attach it to scene. */
pfAddChild(scene, pfNewLSource());
/* Configure and open GL window */
p = pfGetPipe(0);
pw = pfNewPWin(p);
pfPWinType(pw, PFPWIN_TYPE_X);
pfPWinName(pw, "OpenGL Performer");
pfPWinOriginSize(pw, 0, 0, winWidth,winHeight);
//pfPWinFBConfigAttrs(pw,fbattr);
/* Open and configure the GL window. */
pfOpenPWin(pw);
/* Create and configure a pfChannel. */
chan = pfNewChan(p);
pfChanScene(chan, scene);
pfChanFOV(chan, 45.0f, 0.0f);
/* determine extent of scene's geometry */
pfGetNodeBSphere (root, &bsphere);
pfChanNearFar(chan, 1.0f, 10.0f * bsphere.radius);
pfFrame();
/* allocate passthrough data */
pd = (PassData*)pfAllocChanData(chan,sizeof(PassData));
/* initialize channel callbacks */
/* Data intialization */
//pfChanTravFunc(chan, PFTRAV_CULL, cullFunc);
pfChanTravFunc(chan, PFTRAV_DRAW, drawFunc);
/* main simulation loop */
while(1)
{
pfCoord view;
float s, c;
pfSync();
//pd->val = 0;
pfPassChanData(chan);
pfFrame();
t = pfGetTime();
pfSinCos(45.0f*t, &s, &c);
pfSetVec3(view.hpr, 45.0f*t, -10.0f, 0);
pfSetVec3(view.xyz, 2.0f * bsphere.radius *s ,
-2.0f * bsphere.radius *c,
0.5f * bsphere.radius);
pfChanView(chan, view.xyz, view.hpr);
}
/* Terminate parallel processes and exit. */
pfExit();
return 0;
}
void cullFunc(pfChannel *chan, void *data)
{
PassData *pd = (PassData*)data;
pd->val++;
pfCull();
}
void drawFunc(pfChannel *chan, void *data)
{
GLubyte imagebuffer[500][500][3];
int i,j;
int c;
pfVec3 farPlaneLL,dummy;
for (i = 0; i < winWidth; i++) {
for (j = 0; j < winHeight; j++) {
c = ((((i&0x8)==0)^((j&0x8))==0))*255;
imagebuffer[i][j][0] = (GLubyte) c;
imagebuffer[i][j][1] = (GLubyte) c;
imagebuffer[i][j][2] = (GLubyte) c;
//imagebuffer[i][j][3] = (GLubyte) 255;
}
}
pfClearChan(chan);
pfDraw();
pfPushState();
pfBasicState();
glClearStencil(0x0);
glClear(GL_STENCIL_BUFFER_BIT);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glDepthFunc(GL_ALWAYS);
glDepthMask(GL_FALSE);
glPushMatrix();
pfGetChanFar(chan, farPlaneLL, dummy, dummy, dummy);
//glTranslatef(0.0f,0.0f,farPlaneLL[2]*0.9);
glTranslatef(0.0f,farPlaneLL[2]*0.005,2.0);
glRasterPos2i(0.0f,0.0f);
glDrawPixels(winWidth, winHeight, GL_RGB,GL_UNSIGNED_BYTE,
imagebuffer);
glPopMatrix();
glDepthFunc(GL_LEQUAL);
glDepthMask(GL_TRUE);
pfPopState();
}
Rajesh.R
Virtual Reality
Institute for Robotics and Virtual Reality
c/o Centre for AI and Robotics
Defence Research and Development Organization (DRDO)
Ministry of Defence
Bangalore - 1
Scientists are people of very dissimilar temperaments
doing different things in very different ways. Among
scientists are collectors, classifiers and compulsive
tidiers-up; many are detectives by temperament and many
are explorers; some are artists and others artisans.
There are poet-scientists and philosopher-scientists and
even a few mystics."
This archive was generated by hypermail 2b29 : Tue Jul 26 2005 - 01:06:10 PDT