Anita Kishore (kishore++at++electrogig.com)
Tue, 19 Sep 1995 14:53:22 -0700
I generate an image that looks like a checkerboard ( as given in the
open GL book, page 261) and use that image in pfTexImage API hoping to be
able to map this new texture on to my geometry which is a square facing the
user. But instead of a check image I get a solid purple square. If I change the
number of components/pixel in the API, then I don't get anything. What am I
doing wrong? I am enclosing a small smaple program to demo this.
Thanks for any help.
-anita
#include <stdio.h>
#include <stdlib.h>
#include <Performer/pf.h>
#include <Performer/pr.h>
#include <gl.h>
int xsize, ysize;
pfTexture *tex;
void *arena;
void makeTexture(void);
pfGroup *MkScene();
pfGeoSet *makeGeometry(void);
int main(int argc, char *argv[])
{
pfPipe *p;
pfChannel *chan;
pfScene *scene;
pfGroup *root;
pfCoord view;
pfPipeWindow *pw;
pfInit();
pfConfig();
arena = pfGetSharedArena();
makeTexture();
scene = pfNewScene();
if ((root = MkScene()) == NULL)
{
printf("Unable to create scene data base....\n");
pfExit();
exit(-1);
}
pfAddChild(scene, root);
p = pfGetPipe(0);
pw = pfNewPWin(p);
pfPWinType(pw, PFWIN_TYPE_X);
pfPWinName(pw, "Textures");
pfPWinOriginSize(pw, 100, 100, 100+720, 100+486);
pfOpenPWin(pw);
chan = pfNewChan(p);
pfChanScene(chan, scene);
pfChanNearFar(chan, 1.0f, 10000.0f);
pfChanFOV(chan, 10.0f, -1.0f);
pfSetVec3(view.hpr, 0, 0, 0);
pfSetVec3(view.xyz, 0, -50, 0);
pfChanView(chan, view.xyz, view.hpr);
while (1)
{
pfSync();
pfFrame();
}
pfExit();
exit(0);
}
void makeTexture()
{
int i, j, r, c;
unsigned long img[64][64][3];
tex = pfNewTex(arena);
xsize = ysize = 64;
/* make check image : from openGL book */
for ( i = 0; i < ysize; i++ )
for ( j = 0; j < xsize; j++ )
{
c = ((((i&0x8)==0)^((j&0x8))==0)) * 255;
img[i][j][0] = (unsigned long) c;
img[i][j][1] = (unsigned long) c;
img[i][j][2] = (unsigned long) c;
}
pfTexImage(tex, img, 2, xsize, ysize, 1);
}
pfGroup *MkScene()
{
pfGroup *group;
pfGeode *geode;
pfGeoSet *geometry;
group = pfNewGroup();
geode = pfNewGeode();
geometry = makeGeometry();
pfAddGSet(geode, geometry);
pfAddChild(group, geode);
return group;
}
#define GEO_SIZE 1.0f
pfGeoSet *makeGeometry(void)
{
pfGeoSet *gset;
pfGeoState *gst;
pfTexEnv *tenv;
static pfVec3 verts[] ={{-GEO_SIZE, 0, -GEO_SIZE},
{ GEO_SIZE, 0, -GEO_SIZE},
{ GEO_SIZE, 0, GEO_SIZE},
{-GEO_SIZE, 0, GEO_SIZE}};
static ushort vindex[] ={0, 1, 2, 3}; /* front */
static pfVec3 norms[] ={{ 0.0f, -1.0f, 0.0f}};
static ushort nindex[] ={0};
static pfVec2 tcoords[] ={{0.0f, 0.0f},
{1.0f, 0.0f},
{1.0f, 1.0f},
{0.0f, 1.0f}};
static ushort tindex[] ={0, 1, 2, 3};
gset = pfNewGSet(arena);
pfGSetAttr(gset, PFGS_COORD3, PFGS_PER_VERTEX, verts, vindex);
pfGSetAttr(gset, PFGS_NORMAL3, PFGS_PER_PRIM, norms, nindex);
pfGSetAttr(gset, PFGS_TEXCOORD2, PFGS_PER_VERTEX, tcoords, tindex);
pfGSetPrimType(gset, PFGS_QUADS);
pfGSetNumPrims(gset, 1);
gst = pfNewGState(arena);
pfGStateMode(gst, PFSTATE_ENTEXTURE, 1);
pfGSetGState(gset, gst);
/*tex = pfNewTex(arena);
pfLoadTexFile(tex, "/disk4/people/kishore/performer/data/smallGlobeDesat.rgb");
*/
pfGStateAttr(gst, PFSTATE_TEXTURE, tex);
tenv = pfNewTEnv(arena);
pfTEnvMode(tenv, PFTE_DECAL);
pfGStateAttr(gst, PFSTATE_TEXENV, tenv);
return gset;
}
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:51:53 PDT