glReadPixels

Started by
4 comments, last by TheMummy 22 years, 5 months ago
Hi there, I am currently writing a litte tool that reads wgl bitmap fonts and writes them into a file ... to get platform independent fonts. At first I put every letter from 32 - 255 into one frame to get the maximum size of the font. So I call glReadPixels the first time and check the size. Then I create a buffer and open an output file. After that I render every letter and read it with glReadPixels but during this call to glReadPixels the porgram always crashes... I commented the line and the access violation is gone Whats wrong ? Edited by - TheMummy on November 18, 2001 5:04:27 PM
Advertisement
My guess would be that you''ve not allocated your pixel array (last parameter to glReadPixels) or that it has the wrong size.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
make sure your read buffer is set to the back buffer (assuming double buffering). make sure your pixel store settings are set correctly and make sure you allocate enough memory to store the amount of ascii characters you need. make sure the file is open and set for writing.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
quote:Original post by jenova
make sure your read buffer is set to the back buffer (assuming double buffering) ...


errhm so do you mean I have to call glReadPixels after switching the buffers or right before ???

Render Frame
SwitchBuffer
glReadPixels --- The way I set it

or

Render Frame
glReadPixels
SwitchBuffer

well, i meant that you need to set the correct read buffer. i.e. if you are going to draw the scene first, then use:

"glReadBuffer(GL_FRONT);".

also the default "glPixelStore" settings, might not be what you want.

and the only other thing is to allocate enough memory for storing the pixel data. you might want to create a static array for testing purposes that''s the size of the screen.

i.e. "char bitmap[640][480][4];" // 640x480, 32-bit color.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Yes thanks you both were right !
I didn''t alocate enough memory !! I read w*h pixels and alcoated memory for (w-1)*(h-1) pixels ........
So I can continue now ...

This topic is closed to new replies.

Advertisement