From: larry ramey (ramey++at++vrco.com)
Date: 06/26/2002 10:23:56
Hello Performers,
I am attempting to capture images from a screen. I've got 2 problems,
they are somehow tied together, but I can't figure out why.
Bug 1:
The first problem is a crash. If I resize a window by dragging the edge
(NOTE: the bug does NOT appear when using the maximize button) then the
SECOND pass through my image capture code dies in malloc. Clearly the
memory arena was corrupted on the first pass. I placed this code inside
earthsky.C for ease of testing. (I wanted something utterly simple as a
test case.....)
Bug 2:
Now, if I try to dump a JPEG or an 8 bit RGB image file my image is
skewed to the left (after a resize of the window). Uncomment the
commented code and comment out the current capture to view this
incarnation of the bug. (It also crashes.)
I'm wondering if there is a difference between my image man page and the
file I am using. The only image.h I have is in the Performer include
tree. /usr/include/gl/image.h does NOT exist on my machine. Of course
this doesn't exaplain why JPEG files are skewed.
I am compiling Performer 2.4 (Onyx II), but I get the same results on
our Performer 2.5 (Onyx III) machine.
-- "With every racist pointed finger/ I can hear the goose-steps getting closer." - Propaghandi Larry E. Ramey Software Engineer ramey++at++vrco.com <mailto:ramey++at++vrco.com>------------------------------------------------------------------------
#include <stdlib.h>
#include <algorithm> #include <string>
#include <Performer/pr/pfTexture.h> #include <Performer/pf/pfChannel.h> #include <Performer/pf/pfEarthSky.h> #include <Performer/pf/pfLightSource.h> #include <Performer/pfdu.h>
static void DrawChannel (pfChannel *chan, void *data);
// // Usage() -- print usage advice and exit. This // procedure is executed in the application process. // static void Usage (void) { pfNotify(PFNFY_FATAL, PFNFY_USAGE, "Usage: earthsky file.ext ...\n"); exit(1); }
int main (int argc, char *argv[]) { float t = 0.0f; pfSphere bsphere; if (argc < 2) Usage(); // Initialize Performer pfInit(); // Use default multiprocessing mode based on number of // processors. pfMultiprocess(PFMP_DEFAULT);
// Load all loader DSO's before pfConfig() forks pfdInitConverter(argv[1]); // Configure multiprocessing mode and start parallel // processes. pfConfig(); // Append to PFPATH additional standard directories where // geometry and textures exist pfFilePath(".:/usr/share/Performer/data"); // Read a single file, of any known type. pfNode *root = pfdLoadFile(argv[1]); if (root == NULL) { pfExit(); exit(-1); } // Attach loaded file to a pfScene. pfScene *scene = new pfScene; scene->addChild(root); // determine extent of scene's geometry scene->getBound (&bsphere); // Create a pfLightSource and attach it to scene. scene->addChild(new pfLightSource); // Configure and open GL window pfPipe *p = pfGetPipe(0); pfPipeWindow *pw = new pfPipeWindow(p); pw->setWinType(PFPWIN_TYPE_X); pw->setName(argv[0]); pw->setOriginSize(0,0,500,500); pw->open(); // Create and configure a pfChannel. pfChannel *chan = new pfChannel(p); chan->setScene(scene); chan->setNearFar(1.0f, 10.0f * bsphere.radius); chan->setFOV(45.0f, 0.0f); chan->setTravFunc(PFTRAV_DRAW, DrawChannel); pfEarthSky *esky = new pfEarthSky(); esky->setMode(PFES_BUFFER_CLEAR, PFES_SKY_GRND); esky->setAttr(PFES_GRND_HT, -1.0f * bsphere.radius); esky->setColor(PFES_GRND_FAR, 0.3f, 0.1f, 0.0f, 1.0f); esky->setColor(PFES_GRND_NEAR, 0.5f, 0.3f, 0.1f, 1.0f); chan->setESky(esky);
// Simulate for twenty seconds. while (t < 20.0f) { float s, c; pfCoord view; // Go to sleep until next frame time. pfSync(); // Compute new view position. t = pfGetTime(); pfSinCos(45.0f*t, &s, &c); view.hpr.set(45.0f*t, -10.0f, 0); view.xyz.set(2.0f * bsphere.radius * s, -2.0f * bsphere.radius *c, 0.5f * bsphere.radius); chan->setView(view.xyz, view.hpr); // Initiate cull/draw for this frame. pfFrame(); } // Terminate parallel processes and exit. pfExit(); return 0; }
static int doTwice = 0; // Draw process callback static void DrawChannel (pfChannel *chan, void *) { float t = pfGetTime(); chan->clear(); pfDraw ();
/* if( doTwice < 2 && t>10.0f){ ++doTwice; GLint intv[4]; glGetIntegerv(GL_VIEWPORT,intv); unsigned startX,startY,sizeX,sizeY; startX = intv[0]; startY = intv[1]; sizeX = intv[2]; sizeY = intv[3]; IMAGE* image = iopen("image.rgb","w",VERBATIM(2),3,sizeX,sizeY,4); GLushort* red = new GLushort[sizeX*sizeY]; GLushort* green = new GLushort[sizeX*sizeY]; GLushort* blue = new GLushort[sizeX*sizeY]; GLushort* alpha = new GLushort[sizeX*sizeY]; glReadBuffer(GL_FRONT); glReadPixels(startX, startY, sizeX, sizeY,GL_RED, GL_UNSIGNED_SHORT, red); glReadPixels(startX, startY, sizeX, sizeY,GL_GREEN,GL_UNSIGNED_SHORT, green); glReadPixels(startX, startY, sizeX, sizeY,GL_BLUE, GL_UNSIGNED_SHORT, blue); glReadPixels(startX, startY, sizeX, sizeY,GL_ALPHA,GL_UNSIGNED_SHORT, alpha); for(unsigned int y=0;y<sizeY;++y){ putrow(image,red+y*sizeX ,y,0); putrow(image,green+y*sizeX,y,1); putrow(image,blue+y*sizeX ,y,2); putrow(image,alpha+y*sizeX,y,3); }
iclose(image); delete [] red; delete [] blue; delete [] green; delete [] alpha; }*/ if( doTwice < 2 && t>10.0f){ GLint intv[4]; glGetIntegerv(GL_VIEWPORT,intv); unsigned startX,startY,sizeX,sizeY; startX = intv[0]; startY = intv[1]; sizeX = intv[2]; sizeY = intv[3]; std::string fname; if(doTwice == 0){ fname = "8bit_1.rgb"; } else{ fname = "8bit_2.rgb"; } ++doTwice; IMAGE* image = iopen((char*)fname.data(),"w",VERBATIM(1),3,sizeX,sizeY,4); GLushort* red = new GLushort[sizeX*sizeY]; GLushort* green = new GLushort[sizeX*sizeY]; GLushort* blue = new GLushort[sizeX*sizeY]; GLushort* alpha = new GLushort[sizeX*sizeY]; GLubyte* bred = new GLubyte[sizeX*sizeY]; GLubyte* bgreen = new GLubyte[sizeX*sizeY]; GLubyte* bblue = new GLubyte[sizeX*sizeY]; GLubyte* balpha = new GLubyte[sizeX*sizeY]; glReadBuffer(GL_FRONT); glReadPixels(startX, startY, sizeX, sizeY,GL_RED, GL_UNSIGNED_BYTE, bred); glReadPixels(startX, startY, sizeX, sizeY,GL_GREEN, GL_UNSIGNED_BYTE, bgreen); glReadPixels(startX, startY, sizeX, sizeY,GL_BLUE, GL_UNSIGNED_BYTE, bblue); glReadPixels(startX, startY, sizeX, sizeY,GL_ALPHA, GL_UNSIGNED_BYTE, balpha); std::copy(bred,bred+sizeX*sizeY,red); std::copy(bgreen,bgreen+sizeX*sizeY,green); std::copy(bblue,bblue+sizeX*sizeY,blue); std::copy(balpha,balpha+sizeX*sizeY,alpha); for(unsigned int y=0;y<sizeY;++y){ putrow(image,red+y*sizeX,y,0); putrow(image,green+y*sizeX,y,1); putrow(image,blue+y*sizeX,y,2); putrow(image,alpha+y*sizeX,y,3); } iclose(image); delete [] bred; delete [] bblue; delete [] bgreen; delete [] balpha; delete [] red; delete [] blue; delete [] green; delete [] alpha; } }
------------------------------------------------------------------------
CC = CC LINK = CC
FLAGS = -g -LANG:ansi-for-init-scope=on -LANG:std
# Performer PERF_LIBS = -lpfdu_ogl -lpfutil_ogl -lpf_ogl
# XLibrary XGL_LIBS = -lGL -lGLU -lXi -lX11
# System SIMPLE_LIBS = -lm -limage -lC
test : test.o $(LINK) -g -v -o test test.o $(PERF_LIBS) $(XGL_LIBS) $(SIMPLE_LIBS)
.SUFFIXES: .C .cc .o
.C.o: $(CC) $(FLAGS) -c $<
.cc.o: $(CC) $(FLAGS) -c $<
clean : rm -f *.o
-- "With every racist pointed finger/ I can hear the goose-steps getting closer." - Propaghandi Larry E. Ramey Software Engineer ramey++at++vrco.com
This archive was generated by hypermail 2b29 : Wed Jun 26 2002 - 10:25:08 PDT