Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 50 lines (41 sloc) 1.558 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
import "AppKit"
import "GLUT"

nsapp = NSApplication sharedApplication

@TestView < NSOpenGLView {
    + defaultPixelFormat {
        attribs = TQPointer withObjects: [NSOpenGLPFADoubleBuffer, nil] type: "I"
        ^NSOpenGLPixelFormat alloc initWithAttributes: attribs
    }

    - reshape {
        pixelSize = (self convertRectToBase: @bounds)[1]
        GlViewport(0, 0, pixelSize[0], pixelSize[1])
        GlMatrixMode(GL_PROJECTION). GlLoadIdentity()
        GluPerspective(25, pixelSize[0] / pixelSize[1], 1, 100)
        GlMatrixMode(GL_MODELVIEW). GlLoadIdentity()
        GlTranslatef(0,0,-10)
    }

    - prepareOpenGL {
        GlClearColor(0,0,0,1)
    }

    - drawRect: dirtyRect {
        GlClear(GL_COLOR_BUFFER_BIT bitOr: GL_DEPTH_BUFFER_BIT)
        GlColor3f(1,1,1)
        GlutWireTeapot(1)
        @openGLContext flushBuffer
    }
}

\ Create a window to display the view
win = NSWindow alloc initWithContentRect: [[400, 400], [300, 200]]
                               styleMask: (NSResizableWindowMask bitOr: NSTitledWindowMask)
                                 backing: NSBackingStoreBuffered
                                   defer: no

view = TestView new setFrame: win contentView bounds;
         setAutoresizingMask: (NSViewWidthSizable bitOr: NSViewHeightSizable);
                        self
win contentView addSubview: view
win movableByWindowBackground = yes

\ Start the app
win makeKeyAndOrderFront: nil
nsapp setActivationPolicy: NSApplicationActivationPolicyRegular
nsapp activateIgnoringOtherApps: yes
nsapp run
Something went wrong with that request. Please try again.