I am using a C++ library that draws using openGL. I have overridden
one of the drawing classes and I want to add to the openGL scene using
glDrawPixels.
To test that I know what I am doing, I first try to cover the whole
screen with white pixels.
void MyClass::draw()
{
BaseClass::draw();
glLoadIdentity();
glRasterPos4d(-1.0,-1.0,-1.0,1.0);
// For testing create an array of all white pixels
// and attempt to cover the whole window
glDrawPixels(width,height,GL_RGBA,GL_BYTE,pixels);
}
This test code works most of the time, but sometimes the white
rectangle is offset from the top left hand corner by varying amounts
and the offset seems to depend on the size of the window.
Searching this group I found the glBitmap trick:
http://groups.google.com/groups?selm=3b1c8c25.947109912%40news.xs4all.nl
If I replace
glRasterPos4d(-1.0,-1.0,-1.0,1.0);
with
glRasterPos4d(0.0,0.0,-1.0,1.0);
glBitmap(0,0,0,0,-width/2,-height/2,NULL);
I get the same results, i.e. it works most of the time but sometimes
the pixels are offset. Anyone have any ideas how I can get this to
work all the time.
Thanks
What's your projection matrix?
--
<\___/> "To err is human, to moo bovine."
/ O O \
\_____/ FTB. For email, remove my socks.
> Hello
>
> I am using a C++ library that draws using openGL. I have overridden
> one of the drawing classes and I want to add to the openGL scene using
> glDrawPixels.
>
> To test that I know what I am doing, I first try to cover the whole
> screen with white pixels.
>
> void MyClass::draw()
> {
> BaseClass::draw();
> glLoadIdentity();
> glRasterPos4d(-1.0,-1.0,-1.0,1.0);
>
> // For testing create an array of all white pixels
> // and attempt to cover the whole window
> glDrawPixels(width,height,GL_RGBA,GL_BYTE,pixels);
> }
>
> This test code works most of the time, but sometimes the white
> rectangle is offset from the top left hand corner by varying amounts
> and the offset seems to depend on the size of the window.
>
> Searching this group I found the glBitmap trick:
>
> http://groups.google.com/groups?selm=3b1c8c25.947109912%40news.xs4all.nl
>
> If I replace
>
> glRasterPos4d(-1.0,-1.0,-1.0,1.0);
Wow! 4d raster positions.
> with
>
> glRasterPos4d(0.0,0.0,-1.0,1.0);
> glBitmap(0,0,0,0,-width/2,-height/2,NULL);
Try -0.5 * width and -0.5 * height to avoid integer division.
Or, if you have an OpenGL implementation version 1.4 or later, you can
use WindowPos instead of RasterPos. (Or use GL_ARB_window_pos extension.)
Or, get the rasterpos and adjust it with glBitmap. (If not valid, reset
ModelView and Projection matrices and use RasterPos.)
> I get the same results, i.e. it works most of the time but sometimes
> the pixels are offset. Anyone have any ideas how I can get this to
> work all the time.
What is the rasterpos when it works? What is it when it fails?
--
Andy V
Thanks to those who replied. I have found the problem now and it
turned out not to be openGL related. When I posted the message my code
was more involved than the example I posted. When I actually tried the
example, it worked correctly and then I worked back from there. Sorry
for wasting everyone's time. I forgot the first rule of posting code,
post real code that shows the problem not made up code that you think
will show the problem.