Re: readback
Svend Tang-Petersen (svend++at++digi.lego.com)
Tue, 11 Aug 1998 12:54:19 +0200
Hi,
I guess I cleaned up my e-mails to quickly. But I seem to remember
someone asking about
texture readback (pfTexture::subLoad).
Well attached is a small example, consisting of:
Makefile
performer.h
readback.h
readback.C
envtex.rgb
box.flt
--
Svend Tang-Petersen, MSc
Silicon Graphics
Stationsparken 25
2600 Glostrup
Denmark
svend++at++copen.sgi.com
Currently:
LEGO, wiZards
Kloevermarken 120
7190 Billund
Denmark
svend++at++digi.lego.com
Hi,
I guess I cleaned up my e-mails to quickly. But I seem to remember someone
asking about
texture readback (pfTexture::subLoad).
Well attached is a small example, consisting of:
Makefile
performer.h
readback.h
readback.C
envtex.rgb
box.flt
--
Svend Tang-Petersen, MSc
Silicon Graphics
Stationsparken 25
2600 Glostrup
Denmark
svend++at++copen.sgi.com
Currently:
LEGO, wiZards
Kloevermarken 120
7190 Billund
Denmark
svend++at++digi.lego.com
#
#
#
#
#
OBJS = readback.o
CFLAGS = -xansi -n32 -mips4 -O3 -nostdinc -I/usr/include/CC -I/usr/include
LFLAGS = -all -ignore_unresolved
NOWARN =
LIBS = -L/usr/lib32 -L/usr/lib32/libpfdb -L/lib32 -lpf_ogl -lpfdu_ogl -lpfutil_ogl -lmpc -limage -lGLU -lGL -lXext -lfpe -lXm -lXt -lXmu -lX11 -lm -lmalloc -lC
readback: $(OBJS)
CC $(NOWARN) $(OBJS) $(CFLAGS) $(LFLAGS) $(LIBS) -o readback
readback.o: readback.C readback.h performer.h
CC $(NOWARN) $(CFLAGS) -c readback.C
clean:
rm readback *.o
//
//
//
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//
//
//
typedef struct
{
pfPipeWindow *mainwindow;
pfTexture *chan_tex;
pfCoord view1, view2;
int exitFlag;
} SharedData;
- application/octet-stream attachment: box.flt
//
// Small test example of how to read texture from channel.
//
#include "performer.h"
#include "readback.h"
#include "stdio.h"
SharedData *Shared;
pfLight *Sun;
pfScene *scene1;
pfScene *scene2;
pfChannel *chan1, *chan2;
pfDCS *rotdcs;
void SceneSetup( void )
{
extern pfScene *scene1;
extern pfScene *scene2;
extern SharedData *Shared;
extern pfDCS *rotdcs;
pfNode *model;
pfVec2* tex_coords;
pfVec3* verts;
pfVec4* colors;
pfGeode *geode;
pfGeoSet *gset;
pfGeoState *gstate;
pfTexEnv *tex_env;
scene1 = new pfScene();
scene2 = new pfScene();
rotdcs = new pfDCS();
rotdcs->setRot( 0.0, 0.0, 0.0 );
scene2->addChild( rotdcs );
if ((model = pfdLoadFile("box.flt")) != NULL ) {
rotdcs->addChild( model );
};
Shared->chan_tex = new pfTexture();
Shared->chan_tex->loadFile("envtex.rgb");
// Shared->chan_tex->setRepeat( PFTEX_WRAP_S, PFTEX_CLAMP );
// Shared->chan_tex->setRepeat( PFTEX_WRAP_T, PFTEX_CLAMP );
tex_coords = (pfVec2 *)pfMalloc( 4 * sizeof(pfVec2) );
verts = (pfVec3 *)pfMalloc( 4 * sizeof(pfVec3) );
colors = (pfVec4 *)pfMalloc( 4 * sizeof(pfVec4) );
tex_coords[0].set( 0.0, 0.0 );
tex_coords[1].set( 1.0, 0.0 );
tex_coords[2].set( 1.0, 1.0 );
tex_coords[3].set( 0.0, 1.0 );
verts[0].set( -0.5, 0.0, -0.5 );
verts[1].set( 0.5, 0.0, -0.5 );
verts[2].set( 0.5, 0.0, 0.5 );
verts[3].set( -0.5, 0.0, 0.5 );
colors[0].set( 1.0, 1.0, 1.0, 1.0 );
colors[1].set( 1.0, 1.0, 1.0, 1.0 );
colors[2].set( 1.0, 1.0, 1.0, 1.0 );
colors[3].set( 1.0, 1.0, 1.0, 1.0 );
int *primLen = (int *)pfMalloc( sizeof( int ));
primLen[0] = 4;
gset = new pfGeoSet();
gset->setAttr( PFGS_COORD3, PFGS_PER_VERTEX, verts, NULL );
gset->setAttr( PFGS_TEXCOORD2, PFGS_PER_VERTEX, tex_coords, NULL );
gset->setAttr( PFGS_COLOR4, PFGS_PER_VERTEX, colors, NULL );
gset->setPrimLengths( primLen );
gset->setPrimType( PFGS_QUADS );
gset->setNumPrims( 1 );
gstate = new pfGeoState();
gstate->setMode( PFSTATE_CULLFACE, PFCF_OFF );
gstate->setMode( PFSTATE_ENTEXTURE, PF_ON );
gstate->setAttr( PFSTATE_TEXTURE, Shared->chan_tex );
tex_env = new pfTexEnv();
tex_env->setMode( PFTE_MODULATE );
gstate->setAttr( PFSTATE_TEXENV, tex_env );
gset->setGState( gstate );
geode = new pfGeode();
geode->addGSet( gset );
scene1->addChild( geode );
}
void updateSim( void )
{
extern pfDCS *rotdcs;
rotdcs->setRot( 36 * pfGetTime(), 0.0, 0.0 );
}
void OpenPipeWin( pfPipeWindow *pw )
{
pfLightModel *LModel;
extern pfLight *Sun;
pw->open();
Sun = new pfLight();
LModel = new pfLightModel();
Sun->setColor(PFLT_AMBIENT, 1.0, 1.0, 1.0);
Sun->setPos( 0.0f, 0.0f, 50.0f, 0.0f);
LModel->setLocal(PF_ON);
LModel->apply();
}
static void DrawChannel( pfChannel *channel, void *)
{
extern SharedData *Shared;
extern pfLight *Sun;
Sun->on();
channel->clear();
pfDraw();
// readback the texture
if (Shared->chan_tex)
Shared->chan_tex->subload( PFTEX_SOURCE_FRAMEBUFFER, NULL, 0, 0, 128, 128, 128, 128, 128 );
}
void WindowSetup( void )
{
extern SharedData *Shared;
extern pfScene *scene1;
extern pfChannel *chan1, *chan2;
Shared->mainwindow = new pfPipeWindow( pfGetPipe(0) );
Shared->mainwindow->setName( "Readback");
Shared->mainwindow->setWinType( PFPWIN_TYPE_X );
Shared->mainwindow->setConfigFunc(OpenPipeWin);
Shared->mainwindow->config();
Shared->mainwindow->setOriginSize( 0, 0, 512, 256 );
pfFrame();
chan1 = new pfChannel( pfGetPipe(0) );
Shared->mainwindow->addChan( chan1 );
chan1->setTravFunc( PFTRAV_DRAW, DrawChannel );
chan1->setViewport( 0.0, 0.25, 0.0, 0.5 );
chan1->setScene( scene2 );
chan1->setNearFar( 0.01f, 1000.0f );
chan1->setFOV( 60.0f, -1.0f );
Shared->view1.xyz.set( 0.0, -1.5, 0.0 );
Shared->view1.hpr.set( 0.0, 0.0, 0.0 );
chan1->setView( Shared->view1.xyz, Shared->view1.hpr );
chan2 = new pfChannel( pfGetPipe(0) );
Shared->mainwindow->addChan( chan2 );
chan2->setViewport( 0.50, 1.0, 0.0, 1.0 );
chan2->setScene( scene1 );
chan2->setNearFar( 0.01f, 1000.0f );
chan2->setFOV( 60.0f, -1.0f );
Shared->view2.xyz.set( 0.0, -1.0, 0.0 );
Shared->view2.hpr.set( 0.0, 0.0, 0.0 );
chan2->setView( Shared->view2.xyz, Shared->view2.hpr );
}
int main( int argc, char *argv[] )
{
pfInit();
pfMultiprocess( PFMP_DEFAULT );
pfdInitConverter( "flt" );
Shared = (SharedData *) pfMalloc( sizeof(SharedData), pfGetSharedArena() );
Shared->exitFlag = 0;
pfConfig();
pfInitClock( 0.0 );
SceneSetup();
WindowSetup();
while (!Shared->exitFlag) {
pfSync();
pfFrame();
updateSim();
}
pfExit();
return 0;
}
=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
Submissions: info-performer++at++sgi.com
Admin. requests: info-performer-request++at++sgi.com
This archive was generated by hypermail 2.0b2
on Tue Aug 11 1998 - 13:42:35 PDT