Okay so I'm writing a small application for personal use...and I've run into a bit of a problem... I have my OpenGL window up and running just swimmingly. The problem pops up when I try to resize my window--if the window gets bigger than it previously was, I cant get it to refresh... if I expose it or drag another window over it, it looks the way its supposed to.
Now I am somewhat of a beginner to Xcode, so forgive me if I'm missing something real obvious here... but my understanding is that the InvalWindowRect() function is what I need to use in order to force a redraw of the window.
so heres the code:
These are my declarations:
[FONT="Courier New"]AGLPixelFormat pixelFormat;
AGLContext aglRenderCtx;
CGrafPtr windowPtr;
int okay;
Rect windowBounds;
int windowHeight;
int windowWidth;
WindowRef window;
[/FONT]
This is my event handler installation in the main() function:
[FONT="Courier New"] eventType.eventClass = kEventClassWindow;
eventType.eventKind = kEventWindowBoundsChanged;
handlerUPP = NewEventHandlerUPP(mainWindow_Resized);
InstallWindowEventHandler (window, handlerUPP, 1, &eventType, NULL, NULL);
DisposeEventHandlerUPP (handlerUPP);[/FONT]
This is my mainWindow_Resized() function:
[FONT="Courier New"]pascal OSStatus mainWindow_Resized (EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) {
resizeGL();
DrawGLScene();
GetWindowPortBounds(window, &windowBounds);
InvalWindowRect(window, &windowBounds);
return noErr;
}[/FONT]
This is my resizeGL(); function:
[FONT="Courier New"]void resizeGL () {
GetWindowBounds(window, kWindowContentRgn, &windowBounds);
windowWidth = windowBounds.right - windowBounds.left;
windowHeight = windowBounds.bottom - windowBounds.top;
glViewport(
0,
0,
windowWidth - 300,
windowHeight - 300);
GLint glViewBounds[] = {
0,
300,
windowWidth - (300),
windowHeight - (300)};
aglSetInteger(aglGetCurrentContext(), AGL_BUFFER_RECT, glViewBounds);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, ((GLfloat)windowWidth - 300)/((GLfloat)windowHeight - 300), 0.1f, 100.0f);
glFlush();
}[/FONT]
I really can't understand whats going on here...I've compared my code with sample code from Apple, and I can't find any significant difference. I am pretty much 100% certain that the problem is taking place within the mainWindow_Resized() function, as the resizeGL() function does what its supposed to (restrict the OpenGL drawable area to everything but the bottom and right 300px of the window) and the event does work, as demonstrated by the fact that it works perfecly so long as I make the window smaller than it was before.
...im probably missing something very obvious.
any help in this matter would be much appreciated.
thanks in advace!
-loki