I am trying to render volumetric data using OpenGL function glDrawPixels()
#define SIZE 480
unsigned int rgbPixels[SIZE][SIZE]
...
glDrawPixels(SIZE, SIZE, GL_RGB, GL_UNSIGNED_INT, rgbPixels);
If I do sizeof(rgbpixels)
it returns 921600 which is what 480*480*4.
I have tried GL_RGBA
but does no good. Finally I got something on the screen without getting access violation using glDrawPixels(SIZE, SIZE*0.81, GL_RGB, GL_UNSIGNED_INT, rgbPixels);
But it is not as per my expected output. So can anyone help me in this case?
You are telling glDrawPixels
that your data is SIZExSIZE
pixels and each pixel has 3 components ( GL_RGB
) of 32-bit unsigned integer type each ( GL_UNSIGNED_INT
). If this is not the case for rgbPixels
(which probably isn't when you say it's just SIZE*SIZE*4
instead of the required SIZE*SIZE*3*4
), then this will likely result in an access violation or other undefined behaviour.
When you say your rgbPixels
is of size SIZE*SIZE*4
, then I guess each pixel contains 4-bytes, with each individual byte being one color component. If this is the case you need
glDrawPixels(SIZE, SIZE, GL_RGBA, GL_UNSIGNED_BYTE, rgbPixels);
Just always keep in mind that all the parameters of glDrawPixels
tell the OpenGL how much memory the pointer argument ( rgbPixels
) uses and in which format it is layed out. So those of course have to match the actual memory that rgbPixels
contains (or points to).
As given the OpenGL will expect 3 unsigned integers per pixel! You probably want to use GL_UNSIGNED_INT_8_8_8_8
instead as the data type.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.