multiple viewport problem with bitmap

  • Follow


Hi everyone,

I am trying to use OpenGl with C++ and am having problems with multiple
viewports. The problem happens when I try to display bitmaps in twp
different viewports.

I tried various combinations. The code seems to behave when I am
drawing triangles etc. However, when I try doing something with
bitmaps, it fails.

Here is the code in a nutshell:

glMatrixMode(GL_MODELVIEW);
glViewport(m_xPos, m_yPos, m_width,m_height);
glLoadIdentity();
glDrawPixels(bmp.bmWidth, bmp.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE,
bmp.bmBits);

// same code, but different set of values for the position...
glMatrixMode(GL_MODELVIEW);
glViewport(m_xPos, m_yPos, m_width,m_height);
glLoadIdentity();
glDrawPixels(bmp.bmWidth, bmp.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE,
bmp.bmBits);

SwapBuffers(hDC);

Now, the two bitmaps seem to get drawn on the same viewport... I would
appreciate any help anyone can give me regarding this...

Cheers,
xargy

0
Reply pankajdaga (63) 12/7/2005 2:37:19 PM

Actually, the bitmaps get drawn on the lower left side of the screen. I
guess I need to do some transformation before drawing the bitmap. I
thought setting the viewport should do that!

0
Reply xargon 12/7/2005 2:39:07 PM


I tried using some tricks with glOrtho, but still no luck...

So, in the code here: m_xPos = 500; m_YPos = 200; m_width and m_height
are 200 resp.

So, I do:
glMatrixMode(GL_MODELVIEW);
glViewport(m_xPos, m_yPos, m_width,m_height);
glLoadIdentity();

glOrtho(m_xPos, m_xPos + m_width, m_height, m_height + m_yPos, -1,
1);
glDrawPixels(bmp.bmWidth, bmp.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE,
bmp.bmBits);					

I hope someone can help me here...

Thanks,
xargy

0
Reply xargon 12/7/2005 3:03:43 PM

xargon wrote:
> I tried using some tricks with glOrtho, but still no luck...
> 
> So, in the code here: m_xPos = 500; m_YPos = 200; m_width and m_height
> are 200 resp.
> 
> So, I do:
 > glMatrixMode(GL_MODELVIEW);
 > glViewport(m_xPos, m_yPos, m_width,m_height);
 > glLoadIdentity();
 >
 > glOrtho(m_xPos, m_xPos + m_width, m_height, m_height + 
m_yPos, -1,
 > 1);


> glDrawPixels(bmp.bmWidth, bmp.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE,
> bmp.bmBits);					
> 
> I hope someone can help me here...
> 

The "glOrtho" must go in the GL_PROJECTION matrix,
not the GL_MODELVIEW matrix

glViewport(...);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(...);
glMatrixMode(GL_MODELVIEW);

Next you need a call to glRasterPos() before you can
draw a bitmap.

glrasterPos(...);
glDrawPixels(...);


-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.

In science it often happens that scientists say, 'You know
that's a really good argument; my position is mistaken,'
and then they actually change their minds and you never
hear that old view from them again.  They really do it.
It doesn't happen as often as it should, because scientists
are human and change is sometimes painful.  But it happens
every day.  I cannot recall the last time something like
that happened in politics or religion.

- Carl Sagan, 1987 CSICOP keynote address

0
Reply fungus 12/7/2005 3:30:08 PM

Hi,

Thanks for the reply! Do you think the arguments to the glOrtho call is
ok?

Thanks,
xargy

0
Reply xargon 12/7/2005 3:38:04 PM

4 Replies
265 Views

(page loaded in 0.005 seconds)

Similiar Articles:













7/24/2012 9:21:03 AM


Reply: