PDA

View Full Version : OS X glut window resizing bug


johnMG
2003.11.24, 06:00 PM
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>

//------------------------------------------------
void init();

void my_display_func();
void my_reshape_func( int w, int h );

//------------------------------------------------
double x_min = -0.4, x_max = 4.4, y_min = -0.8, y_max = 16.8;

//------------------------------------------------
int main( int argc, char * argv[] )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize( 400, 400 );
glutInitWindowPosition( 40, 10 );
glutCreateWindow( "plotter2d" );

init();

glutDisplayFunc( my_display_func );
glutReshapeFunc( my_reshape_func );

glutMainLoop();
return 0;
}

//------------------------------------------------
void init()
{
glClearColor( 0.3f, 0.3f, 0.3f, 0.0f );
glPointSize( 3.0 );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glOrtho( x_min, x_max, // left, right
y_min, y_max, // bottom, top
-1.0, 1.0 );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}

//------------------------------------------------
void my_display_func()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glColor3d( 1.0, 1.0, 0.6 );
glBegin( GL_LINES );
glVertex3d( x_min, 0.0, 0.0 ); // x-axis.
glVertex3d( x_max, 0.0, 0.0 );
glVertex3d( 0.0, y_min, 0.0 ); // y-axis.
glVertex3d( 0.0, y_max, 0.0 );
glEnd();

glColor3d( 1.0, 0.2, 0.2 );
glBegin( GL_POINTS );
glVertex3d( 0.0, 0.0, 0.0 );
glVertex3d( 1.0, 1.0, 0.0 );
glVertex3d( 2.0, 4.0, 0.0 );
glVertex3d( 3.0, 9.0, 0.0 );
glVertex3d( 4.0, 16.0, 0.0 );
glEnd();

glutSwapBuffers();
}

//------------------------------------------------
void my_reshape_func( int w, int h )
{
// We want to keep the aspect ratio (1, in this case) constant regardless
// of how the window is reshaped. It also needs to stay as large as possible
// and centered within the window. Note that the clipping volume is set
// once in init(), and left alone after that.
if ( w > h )
{
glViewport( w/2 - h/2, // x_bottom_left_corner
0, // y_bottom_left_corner
h, // width
h ); // height
}
else
{
glViewport( 0, h/2 - w/2, w, w );
}

glutPostRedisplay();
}



When I resize the window, it sometimes will cut off that last point at the top right. In fact, fiddling with resizing the window to be wide and short, then tall and thin, and then adjusting one dimension out then back, the bug is repeatable.

Resize the window to be very wide (even moving the left edge off the screen) to see what I mean.

I've got a dual-monitor setup here with my PowerBook G3, but the bug happens even when just resizing it in the main screen.

Please let me know if you see this bug as well.

Oh, and build the code with:
g++ main.cpp -framework OpenGL -framework GLUT -framework Foundation

Thanks.

Sohta
2003.11.24, 06:15 PM
edited for utter stupidity :blush:

OneSadCookie
2003.11.24, 06:45 PM
yet another good argument why comments are evil http://onesadcookie.is-a-geek.net/~keith/Smilies/tongue.png

johnMG
2003.11.24, 08:44 PM
> yet another good argument why comments are evil :P

?

Did you folks get the same error as me, or maybe,.. am I making some silly mistake?

Forgot to mention: I'm running Panther (10.3.1, Build 7C107), and using GLUT version 3.2.7 (the one that came with Panther).

Hmm.... I just logged into developer.apple.com ... can anyone tell me how I can browse the current buglist? Erm, I'm guessing there's a list of Panther bugs available for us to look through (?).

Tried searching
http://discussions.info.apple.com/
but that wasn't helpful at all. Has anyone here had any luck using those discussion boards?

Also looked at Apple's OpenGL mailing list archives:
http://search.lists.apple.com/mac-opengl
http://lists.apple.com/mailman/listinfo/mac-opengl
http://lists.apple.com/mhonarc/mac-opengl/
and browsed around the "web archives" of recent messages -- can't figure out how to do a *search* of these though... (?)

arekkusu
2003.11.24, 10:03 PM
You can't search for bugs via the RADAR web form. You can search via the RADAR application, but only if you have special access (e.g. work for Adobe) and then only on bugs logged by your group.

Apple's bugs aren't public knowledge.

You can search the mailing lists (http://search.lists.apple.com), but Apple's interface there is really terrible. I wish cocoa.mamasam.com would mirror ALL the lists, not just cocoa-dev.

OneSadCookie
2003.11.24, 10:50 PM
Originally posted by johnMG
> yet another good argument why comments are evil :P

?

Doesn't make much sense without Sohta's comment...

johnMG
2003.11.24, 10:56 PM
> Apple's bugs aren't public knowledge.

Hehehe. That's funny -- I guess I've been spoiled by GNU/Linux/OSS. :)

> You can search the mailing lists (http://
> search.lists.apple.com), but Apple's interface there is
> really terrible.

Whoops. Thanks. I read this:
http://www.lists.apple.com/cgi-bin/mwf/topic_show.pl?id=96
We have two types of archives: web-based archives that store recent messages and display them by date and by thread, and complete archives in text format.

then, after searching and seeing the results in plain text format, I guess I had a short-circuit between the seat and the keyboard and thought I was only seeing search results from an old archive.

> I wish cocoa.mamasam.com would mirror ALL the lists, not just cocoa-dev.

?

AnotherJake
2003.11.25, 12:09 AM
Well, I compiled it in Xcode, c++ (I assume this is still using g++ right?), on the same OS and version of GLUT and there were no disappearing points. Everything works as it should. Also threw in the same frameworks for kicks. Even using a dual monitor setup and followed the instructions to repeat the bug. Works just fine, all five points present and accounted for after various and numerous resizes. System is dual G4. This appears be the only difference.

Bachus
2003.11.25, 03:09 AM
GLUT in pre-X.3 is most likely using [NSWindow setAspectRatio] which has the amazing "feature" of including the titlebar of the window in the aspect ratio. in X.3 it probably switched to the much better setContentAspectRatio. Thus, in X.0-X.2 you'll notice the window not resizing properly.

I'm not positive on this (I don't use GLUT, and I didn't try your code), but it sounds like the likely culprit.

johnMG
2003.11.25, 12:27 PM
Thanks for trying it out Jake. It sounds like it could be some timing-related thing (dual-G4 faster than single G3)... anyhow, I'll go ahead and report it.

Well, I compiled it in Xcode, c++ (I assume this is still using g++ right?)

I think if you name the file .cpp, the g++ front-end to gcc is used; otherwise, if you name it .c, gcc is used.

Thanks Bachus... I know very little about Carbon/Cocoa, but what you suggest sounds like it has to do with 10 (or so) pixels in the vertical direction, where, what I'm seeing happens vertical or horizontal.

> > yet another good argument why comments are evil :P
>
> Doesn't make much sense without Sohta's comment...

Oh... I think you meant "...why editing comments is evil". :)

AnotherJake
2003.11.25, 04:56 PM
Originally posted by OneSadCookie
yet another good argument why comments are evil
Heeeheeeeheeeeheeee... My sides hurt... Things are getting blurry...