Memory cannot be written

I’ve put following code into program:

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

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)

you need to allocate memory for the pointer, otherwise the ReadPixels will write to unallocated memory causing a crash

Thanks.

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 :slight_smile: ). 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, [b]-[/b]1024, [b]-[/b]768,GL_RGB,GL_UNSIGNED_BYTE,bufer); 

and all is fine. Why? :slight_smile:

And could you tell me is 10247683 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.

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.)

readpixels is hideously slow, a better bet is glCopyTexImage2D, I think thats what many people use for fullscreen blurring