Commits

Bob Ippolito committed 91730e9

Simple OpenGL demonstration

  • Participants
  • Parent commits a130ec8

Comments (0)

Files changed (7)

File pyobjc/Examples/OpenGLDemo/LICENSE.txt

+(This is the MIT license)
+
+ Copyright (c) 2003 Bob Ippolito.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

File pyobjc/Examples/OpenGLDemo/OpenGLDemo.nib/classes.nib

+{
+    IBClasses = (
+        {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 
+        {
+            ACTIONS = {setClearColor = id; }; 
+            CLASS = OpenGLDemoView; 
+            LANGUAGE = ObjC; 
+            SUPERCLASS = NSOpenGLView; 
+        }
+    ); 
+    IBVersion = 1; 
+}

File pyobjc/Examples/OpenGLDemo/OpenGLDemo.nib/info.nib

+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>IBDocumentLocation</key>
+	<string>168 232 356 240 0 0 1600 1002 </string>
+	<key>IBEditorPositions</key>
+	<dict>
+		<key>29</key>
+		<string>69 213 195 44 0 0 1600 1002 </string>
+	</dict>
+	<key>IBFramework Version</key>
+	<string>349.0</string>
+	<key>IBOpenObjects</key>
+	<array>
+		<integer>21</integer>
+		<integer>29</integer>
+	</array>
+	<key>IBSystem Version</key>
+	<string>7B85</string>
+</dict>
+</plist>

File pyobjc/Examples/OpenGLDemo/OpenGLDemo.nib/objects.nib

Binary file added.

File pyobjc/Examples/OpenGLDemo/OpenGLDemo.py

+"""ClassBrowser.py -- A simple class browser, demonstrating the use of an NSBrowser.
+
+To build the demo program, run this line in Terminal.app:
+
+    $ python buildapp.py --link build
+
+This creates a directory "build" containing ClassBrowser.app. (The
+--link option causes the files to be symlinked to the .app bundle instead
+of copied. This means you don't have to rebuild the app if you edit the
+sources or nibs.)
+
+See also the iClass demo.
+"""
+
+from PyObjCTools import NibClassBuilder, AppHelper
+from objc import getClassList, objc_object
+from AppKit import *
+from Foundation import *
+from OpenGL.GL import *
+
+
+NibClassBuilder.extractClasses("OpenGLDemo")
+
+
+ClearColors = redIndex, greenIndex, blueIndex, alphaIndex = range(4)
+
+class OpenGLDemoView(NibClassBuilder.AutoBaseClass):
+    def awakeFromNib(self):
+        self.color_index = alphaIndex
+
+    def initWithFrame_(self, frame):
+        attribs = [
+            NSOpenGLPFANoRecovery,
+            NSOpenGLPFAWindow,
+            NSOpenGLPFAAccelerated,
+            NSOpenGLPFADoubleBuffer,
+            NSOpenGLPFAColorSize, 24,
+            NSOpenGLPFAAlphaSize, 8,
+            NSOpenGLPFADepthSize, 24,
+            NSOpenGLPFAStencilSize, 8,
+            NSOpenGLPFAAccumSize, 0,
+        ]
+        fmt = NSOpenGLPixelFormat.alloc().initWithAttributes_(attribs)
+        self = super(OpenGLDemoView, self).initWithFrame_pixelFormat_(frame, fmt)
+        return self
+
+    def setClearColor_(self, sender):
+        self.color_index = sender.tag()
+        self.setNeedsDisplay_(True)
+        
+    def drawRect_(self, ((x, y), (w, h))):
+        glViewport(0, 0, w, h)
+        clear_color = [0.0]*4
+        clear_color[self.color_index] = 1.0
+        glClearColor(*clear_color)
+        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT)
+        self.openGLContext().flushBuffer()
+
+if __name__ == "__main__":
+    AppHelper.runEventLoop()

File pyobjc/Examples/OpenGLDemo/README.txt

+OpenGLDemo
+
+OpenGLDemo is probably the simplest possible demonstration of 
+using OpenGL from a PyObjC application.  It is a port of Apple's
+"CocoaGL" example.  Note that this requires PyOpenGL to be installed.
+
+See:    /Developer/Examples/OpenGL/Cocoa/CocoaGL
+        http://pyopengl.sourceforge.net/
+
+The source of this application demonstrates
+- Using PyOpenGL from Cocoa
+
+Bob Ippolito
+bob@redivi.com

File pyobjc/Examples/OpenGLDemo/buildapp.py

+from bundlebuilder import buildapp
+
+buildapp(
+	mainprogram = "OpenGLDemo.py",
+	resources = ["OpenGLDemo.nib"],
+	nibname = "OpenGLDemo",
+)