From: tom f. <tf...@al...> - 2009-07-27 01:01:41
|
Srimal Jayawardena <sr...@gm...> writes: > GLvoid* data; > data =3D (GLvoid *) malloc (1024*768); > glReadPixels (0,0,1024,768,GL_RED, GL_UNSIGNED_BYTE, data); > for(int i=3D0; i<1024*768; i++) > cout << data[i]; > free(data); > > But it gives this error: > > $ make > g++ -Wall -o render main.cpp -lglut > main.cpp: In function =E2=80=98void drawScene()=E2=80=99: > main.cpp:154: error: pointer of type =E2=80=98void *=E2=80=99 used in arith= > metic > main.cpp:154: error: =E2=80=98GLvoid*=E2=80=99 is not a pointer-to-object t= > ype > make: *** [render] Error 1 > > Am I missing something here? Yep. In short, your types are wrong. You can't have a void object, so you can't directly dereference a void pointer. Try a GLubyte instead. That said, you might want to read up on C. I suggest the white book: http://cm.bell-labs.com/cm/cs/cbook/ Though your `cout' implies you actually want to write C++, contrary to malloc/free. Stroustrup's book is the classic text here: http://www.research.att.com/~bs/3rd.html > Is there a better way to do this? Somewhere in the Mesa demos (IIRC) there's some code for reading the current image buffer into a ppm file. If not there, some simple googling should bring up code to do this. -tom |