Click here to Skip to main content
15,867,860 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to setup an OpenGL window to have the the top-left corner 0,0 and the bottom-right corner the width and height of the window (pixels not percentage). And when resized nothing drawn is scaled, instead the window area is enlarged/shrunk. It's for drawing 2D images. I'm using the Windows API. How can I do this?
Posted
Updated 21-Sep-12 18:18pm
v2
Comments
[no name] 21-Sep-12 23:44pm    
And?
Mohibur Rashid 21-Sep-12 23:53pm    
go on, you are not done with the question yet.

1 solution

C++
OnSize(UINT nType, int cx, int cy)
{
    // Set viewport widht as cx, and height as cy
    glViewport( 0, 0, cx, cy );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0, cx, cy, 0, 0, 1 );

    m_nWidth = cx;
    m_nHeight = cy;
}


You need to redraw all your frame related to new screen size.

C++
onDrawFrame()
{
   // Draw frame relative to m_nWidth and m_nHeight.
   // Eg. glRect( 0,0, m_nWidth, m_nHeight )
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900