1

几年来,我一直在使用 Chris 移植到 Mac OS X 的 Noof 屏幕保护程序:

斯科罗世界

我让它在 10.8 下运行良好,并且已经用高分辨率艺术品更新了项目,并对 prefs 面板进行了一些其他调整以使其正常工作,但是我似乎无法弄清楚如何让它使用更高分辨率的渲染而不是像素- Retina 显示屏上的东西翻倍。下面的代码似乎在 2880x1800 处绘制窗口,但它仍然是像素的两倍。

我已经粘贴了我认为是代码的相关部分。


代码

static void
reshape_noof(int w, int h)
{
     glViewport(0, 0, w, h);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 if (w <= h) {
      wd = 1.0;
      ht = (GLfloat) h / (GLfloat) w;
      glOrtho(0.0, 1.0,
                0.0, 1.0 * (GLfloat) h / (GLfloat) w,
                -16.0, 4.0);
 } else {
      wd = (GLfloat) w / (GLfloat) h;
      ht = 1.0;
      glOrtho(0.0, 1.0 * (GLfloat) w / (GLfloat) h,
                0.0, 1.0,
                -16.0, 4.0);
 }
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();

 glClearColor( 0.0, 0.0, 0.0, 1.0 );
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

剪辑

// ScreenSaverView methods

- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
self = [super initWithFrame:frame isPreview:isPreview];
if (self) {
      [self loadSettings];
    [self setAnimationTimeInterval:1.0/delay];

      NSRect newFrame = frame;
      newFrame.origin.x = 0.0;
      newFrame.origin.y = 0.0;

      glView = [[NSOpenGLView alloc] initWithFrame:newFrame pixelFormat:[NSOpenGLView defaultPixelFormat]];
    if( glView ) {
        [self setAutoresizesSubviews:YES];
           [self addSubview:glView];
      }
 }

return self;
}

- (void)startAnimation
{
[super startAnimation];

 // Load our settings
 [self loadSettings];

 // Turn off the cursor; this doesn't always seem to happen on Tiger. :-(
 if( ![self isPreview] ) [NSCursor hide];

 firstRun = YES;

 // Prepare OpenGL.
 [[glView openGLContext] makeCurrentContext];
[self setWantsBestResolutionOpenGLSurface:YES];
[self convertRectToBacking:[self bounds]];
// Get view dimensions in pixels
NSRect backingBounds = [self convertRectToBacking:[self bounds]];

GLsizei backingPixelWidth  = (GLsizei)(backingBounds.size.width),
backingPixelHeight = (GLsizei)(backingBounds.size.height);
 float w = backingPixelWidth;
 float h = backingPixelHeight;
 reshape_noof( w, h );

 // from init_noof
 glEnable(GL_LINE_SMOOTH);
 glShadeModel(GL_FLAT);
 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 int i;
 for (i = 0; i < N_SHAPES; i++)
      initshapes(i);

 //[self animateOneFrame];
 glClearColor( 0.0, 0.0, 0.0, 0.0 );
 glClear( GL_COLOR_BUFFER_BIT );
 glFlush();
}

- (void)stopAnimation
{
 // Turn on the cursor.
 if( ![self isPreview] ) [NSCursor unhide];

[super stopAnimation];
}

- (void)animateOneFrame
{
 int i;

 if( firstRun ) {
      // Make **** sure our view port is correct.
    [self setWantsBestResolutionOpenGLSurface:YES];
    [self convertRectToBacking:[self bounds]];
    // Get view dimensions in pixels
    NSRect backingBounds = [self convertRectToBacking:[self bounds]];

    GLsizei backingPixelWidth  = (GLsizei)(backingBounds.size.width),
    backingPixelHeight = (GLsizei)(backingBounds.size.height);

    // Set viewport
      reshape_noof( backingPixelWidth, backingPixelHeight );
      firstRun = NO;
 }

 gravity( -2.0 );
 for( i = 0; i < N_SHAPES; i++ ) {
      motionUpdate( i );
      colorUpdate( i );
      drawleaf( i );
 }

 glFinish();
}
4

1 回答 1

2

在你初始化之后,我会把这条线[self setWantsBestResolutionOpenGLSurface:YES];移到右边NSOpenGLView

glView = [[NSOpenGLView alloc] initWithFrame:newFrame pixelFormat:[NSOpenGLView defaultPixelFormat]];
[glView setWantsBestResolutionOpenGLSurface:YES];

至少这就是我做屏幕保护程序的方式,而且它似乎有效。

于 2013-08-08T17:07:45.297 回答