View Full Version : Memory cannot be written

03-27-2004, 08:56 AM
I've put following code into program:

void *bufer;
glReadPixels(0,0,100,100,GL_RGB,GL_UNSIGNED_BYTE,b ufer);

and there is an error. Program collapses after executing this instructions. What can be wrong?

(I've used example from OpenGL - Game Programming <or sth like that> by Dave Astle and Kevin Hawkins)

03-27-2004, 09:12 AM
you need to allocate memory for the pointer, otherwise the ReadPixels will write to unallocated memory causing a crash

03-27-2004, 09:32 AM

I knew about it but, I thought that glReadPixels handles it (I know, I know, that is not explain, but I am really not idiot :) ). I've changed code to

unsigned char *bufer=new unsigned char[1024*768*3];
glReadPixels(0,0,1024,768,GL_RGB,GL_UNSIGNED_BYTE, bufer);and... it was still collapsing. Then I've changed to

unsigned char *bufer=new unsigned char[1024*768*3];
glReadPixels(0,0, -1024, -768,GL_RGB,GL_UNSIGNED_BYTE,bufer); and all is fine. Why? :)

And could you tell me is 1024*768*3 array good? I read about sthing about sizes of arrays used to read pixels and I can't remember if there won't be any error with that size.

03-27-2004, 10:07 AM
Oh, gee, it is so slow. Is there any method to fullscreen anything that is effective? Surely yes, but how to do that (fullscreen blur, for example)? Theory only would help me too.

(I've changed -values to +values; it is fine right now.)

03-27-2004, 10:51 AM
readpixels is hideously slow, a better bet is glCopyTexImage2D, I think thats what many people use for fullscreen blurring