Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C Windows OpenGL resize
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 21-Sep-12 18:27pm
Edited 21-Sep-12 19:18pm
v2
Comments
Wes Aday at 21-Sep-12 23:44pm
   
And?
Mohibur Rashid at 21-Sep-12 23:53pm
   
go on, you are not done with the question yet.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 
onDrawFrame()
{
   // Draw frame relative to m_nWidth and m_nHeight.
   // Eg. glRect( 0,0, m_nWidth, m_nHeight )
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 265
2 Praneet Nadkar 237
3 Marcin Kozub 225
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 22 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100