PDA

View Full Version : Image not rsizing properly when window get bigger than initial size



bigefrom84
12-08-2014, 07:19 AM
I have Opengl as a class in a MFC 2008 SDI, and initiate it as follows:

CView * pView = pFrame->GetActiveView();
pView->GetWindowPlacement(&placeWnd);

placeWnd.showCmd = SW_SHOWMAXIMIZED;
pView->SetWindowPlacement(&placeWnd);

windowRect.left = placeWnd.rcNormalPosition.left;
windowRect.top = placeWnd.rcNormalPosition.top;
windowRect.right = placeWnd.rcNormalPosition.right;
windowRect.bottom = placeWnd.rcNormalPosition.bottom;

fprintf(DebugFile,_T("Original Window Rect left %d right %d top %d bottom %d\n"),windowRect.left,windowRect.right,windowRect.top, windowRect.bottom);

m_pDisplay = new COpenGLClass;
m_pDisplay->Create( NULL, //CWnd default
NULL, //has no name
WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_VISIBL E,
windowRect,
this, //this is the parent
0); //this should really be a different number... check resource.h

for(int i=0; i<4; i++)
m_pDisplay->SetLocalBounds(i,Global);
m_pDisplay->Resize(windowRect.right-windowRect.left,
windowRect.bottom-windowRect.top);
m_pDisplay->ShowWindow(SW_SHOW);

m_pDisplay->Invalidate();

The initial image on the left, along with the resized image on the right is what i get when i resize the window to a larger size.:
1533 1534
It appears that the window rect for the display is not keeping up with the actual window rect.
Here is the resizing routine (which = 0)

if (WindowWidth[which] <= WindowHeight[which])
{
glOrtho (Local[which].xmin, Local[which].xmax,
Local[which].ymin/aspectRatio,Local[which].ymax/aspectRatio,
-nRange*2.0f, nRange*2.0f);
}
else
{
glOrtho (Local[which].xmin*aspectRatio, Local[which].xmax*aspectRatio,
Local[which].ymin, Local[which].ymax,
-nRange*2.0f, nRange*2.0f);
}

Osbios
12-08-2014, 08:20 AM
What you are looking for is glViewport (https://www.opengl.org/wiki/GLAPI/glViewport).

bigefrom84
12-08-2014, 12:44 PM
What you are looking for is glViewport (https://www.opengl.org/wiki/GLAPI/glViewport).
I use the glViewport command: and i checked the vaue is correct.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(MultiWindow)
{
glViewport(ViewPorts[which][0],ViewPorts[which][1],WindowWidth[which],WindowHeight[which]);
fprintf(DebugFile,_T("Window %d Viewport set to %d %d %d %d\n"),which,
ViewPorts[which][0],ViewPorts[which][1],WindowWidth[which],WindowHeight[which]);
}
else
{
glViewport(0,0,WindowWidth[0],WindowHeight[0]);
fprintf(DebugFile,_T("Window Viewport set to %d %d %d %d\n"),0,0,WindowWidth[which],WindowHeight[which]);
}


The problem i believe is with the original rect i give it when initialing, when i re-size the image to bigger than it starts out with, i get what you see in the second image.

Osbios
12-09-2014, 03:49 PM
Well I don't see what your event system is or what your event handler does, so I have to guess what can help.

Normally you get events for every window resize.
The event will carry the values of the new size, and you use that to set glViewport and the projection matrix.

Are the values OK that you get from the resize event? Does the event handler for resizing get called correctly?

bigefrom84
12-10-2014, 04:26 AM
Well I don't see what your event system is or what your event handler does, so I have to guess what can help.

Normally you get events for every window resize.
The event will carry the values of the new size, and you use that to set glViewport and the projection matrix.

Are the values OK that you get from the resize event? Does the event handler for resizing get called correctly?

The window re-sizing works fine as long as i re-size within the limits of the original size set at creation. This is what make me think it has something to do with the original setup for the OpenGL class:

CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd);
if(pFrame)
{
CView * pView = pFrame->GetActiveView();
pView->GetWindowPlacement(&placeWnd);

placeWnd.showCmd = SW_SHOWMAXIMIZED;
pView->SetWindowPlacement(&placeWnd);

windowRect.left = placeWnd.rcNormalPosition.left;
windowRect.top = placeWnd.rcNormalPosition.top;
windowRect.right = placeWnd.rcNormalPosition.right;
windowRect.bottom = placeWnd.rcNormalPosition.bottom;

//fprintf(DebugFile,_T("Original Window Rect left %d right %d top %d bottom %d\n"),windowRect.left,windowRect.right,windowRect.top, windowRect.bottom);

m_pDisplay = new COpenGLClass;
m_pDisplay->Create( NULL, //CWnd default
NULL, //has no name
WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_VISIBL E,
windowRect,
this, //this is the parent
0); //this should really be a different number... check resource.h

This seems to set a portion of the screen for my view, and if i re-size smaller, everything is fine, but once i exceed that original window size, i get what you see above.

bigefrom84
12-10-2014, 05:45 AM
The window re-sizing works fine as long as i re-size within the limits of the original size set at creation. This is what make me think it has something to do with the original setup for the OpenGL class:

CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd);
if(pFrame)
{
CView * pView = pFrame->GetActiveView();
pView->GetWindowPlacement(&placeWnd);

placeWnd.showCmd = SW_SHOWMAXIMIZED;
pView->SetWindowPlacement(&placeWnd);

windowRect.left = placeWnd.rcNormalPosition.left;
windowRect.top = placeWnd.rcNormalPosition.top;
windowRect.right = placeWnd.rcNormalPosition.right;
windowRect.bottom = placeWnd.rcNormalPosition.bottom;

//fprintf(DebugFile,_T("Original Window Rect left %d right %d top %d bottom %d\n"),windowRect.left,windowRect.right,windowRect.top, windowRect.bottom);

m_pDisplay = new COpenGLClass;
m_pDisplay->Create( NULL, //CWnd default
NULL, //has no name
WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_VISIBL E,
windowRect,
this, //this is the parent
0); //this should really be a different number... check resource.h

This seems to set a portion of the screen for my view, and if i re-size smaller, everything is fine, but once i exceed that original window size, i get what you see above.

In debugging, i found out that my client area remains constant, even thought i am changing the view rect. When the view rect exceeds the client rect, i get the problems. How do i increase the client area to match the view area?

bigefrom84
12-10-2014, 05:49 AM
In debugging, i found out that my client area remains constant, even thought i am changing the view rect. When the view rect exceeds the client rect, i get the problems. How do i increase the client area to match the view area?

here is the resizing code

void COpenGLTemplateView::OnSize(UINT nType, int cx, int cy)
{
WINDOWPLACEMENT placeWnd;
CRect newRect(0,0,cx,cy);

// Set the view rectangle
if(cx + cy > 0 && bHaveRect)
{
CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd);
if(pFrame)
{
CView * pView = pFrame->GetActiveView();
pView->GetWindowPlacement(&placeWnd);
placeWnd.rcNormalPosition = newRect;
pView->SetWindowPlacement(&placeWnd);
}
m_pDisplay->Resize(cx,cy);
}
}