Help with drawpixels...

I’m having a heck of a time working with gldrawpixels! It works great if I use GL_UNSIGNED_BYTE, but if I use anything else (like GL_UNSIGNED_SHORT), I get nothing!!

I tried fiddling with the packing alignment and what not, all to no avail. It’s probably something stupid, but it’s driving me nuts!

Any help will be greatly appreciated!

Thanks,
Doug

If it works with GL_UNSIGNED_BYTE, then I assube the data is unsigned byte. So if you change the format to GL_UNSIGNED_SHORT, you also have to change the data to unsigned short. Did you do that?

Yes make sure you are passing in Shorts you can use the reinterpret_cast to help

reinterpret_cast<unsigned short*>( yourdata );

Originally posted by UrbanLegend:
[b]Yes make sure you are passing in Shorts you can use the reinterpret_cast to help

reinterpret_cast<unsigned short*>( yourdata );[/b]

That will only convert the pointer from unsigned char * to unsigned short*. It will not convert the data pointed to from unsigned char to unsigned short, and that is what OpenGL is expecting when you pass GL_UNSIGNED_SHORT instead of UNSIGNED_BYTE.

[This message has been edited by Bob (edited 02-10-2004).]

No my data is unsigned shorts. If i do something like:
for(i=0;i<Width*Height;i++)
Img[i] = foo[i]%256;

And copy the value of each unsigned short into
an array of unsigned bytes, it works.
That’s what’s confusing me.

Thanks,
Doug

Originally posted by thafreak:
No my data is unsigned shorts.
<…>
Img[i] = foo[ i]%256;
Really?
Well, technically yes, but it’s no wonder you don’t see anything if your image data never goes above 255/65535 in intensity.

If you want full intensity from unsigned short values, you must use 65535, not 255. If you limit yourself to 255 maximum, why would you need unsigned shorts anyway!?

No no no, I was giving an example of how I convert my unsigned shorts into unsigned bytes!
My unsigned shorts do go above 255.

If i take all my unsigned shorts and mod them by 255 so that they fit in unsigned bytes, then I get an image.

The mod 255 was just an example I was using…

Doug

My original post of the code was kind of unclear…

GLubyte Img[Width][Height]
GLushort foo[Width][Height]

for(i=0;i<Width*Height;i++)
Img[i] = foo[i]%256;

So if I do this and convert my shorts to bytes, I get an image, if I leave them as shorts I get all black!

I actually took one of the examples from the redbook called image.c and converted it to use unsigned shorts instead of unsigned bytes and I get the same results.

I can post my version of the image.c if anyone thinks that might help…