Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > InvalWindowRect() is killing me....

InvalWindowRect() is killing me....
Thread Tools
Mac Elite
Join Date: Apr 2005
Location: Las Vegas, NV
Status: Offline
Reply With Quote
Jun 11, 2006, 10:19 PM
 
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

"In a world without walls or fences, what need have we for windows or gates?"
     
loki74  (op)
Mac Elite
Join Date: Apr 2005
Location: Las Vegas, NV
Status: Offline
Reply With Quote
Jun 20, 2006, 11:09 PM
 
okay, 67 views and no replies. is there nobody who can help me?

"In a world without walls or fences, what need have we for windows or gates?"
     
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Jun 21, 2006, 03:24 AM
 
Sorry man, my gl knowledge is rustier than the beater car my friend just got :/
     
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status: Offline
Reply With Quote
Jun 22, 2006, 12:37 PM
 
This is just a random guess, but you might try calling HIWindowFlush() after InvalWindowRect(). My understanding is that InvalWindowRect() will mark the rect as needing to be redrawn, but you might still need to explicity flush it to actually get it to redraw on screen.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:51 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2