<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,8 +1,7 @@
 require &quot;rubygems&quot;
 require &quot;glapp&quot;
 
-include GLApp::Engine
-public
+include GLApp
 
 class Texture
   attr_reader :num, :width, :height
@@ -157,15 +156,15 @@ def draw
   # change coordinate system to match screen pixels
   glMatrixMode(GL_PROJECTION)
   glLoadIdentity
-  glOrtho(0, 300, 300, 0, -1000, 1000)
+  glOrtho(0, width, height, 0, -1000, 1000)
   glMatrixMode(GL_MODELVIEW)
   glLoadIdentity
-
+  
   # draw a hedgehog in the center of the screen
   glPushMatrix
-    glTranslate(150, 150, 0)
+    glTranslate(width/2, height/2, 0)
     @sprites[@animator.frame].render
   glPopMatrix
 end
 
-GLApp.new(self, 300, 300).show
+show 300, 300, &quot;sprite demo&quot;</diff>
      <filename>examples/sprite.rb</filename>
    </modified>
    <modified>
      <diff>@@ -34,7 +34,7 @@ class Triangle
 end
 
 class TriangleDemo
-  include GLApp::Engine
+  include GLApp
   
   def setup
     @triangles = Triangle.boom(10)
@@ -53,5 +53,4 @@ class TriangleDemo
   end
 end
 
-app = GLApp.new(TriangleDemo.new, 800, 300, &quot;Triangle demo&quot;)
-app.show
+TriangleDemo.new.show 800, 300, &quot;triangle demo&quot;</diff>
      <filename>examples/triangles.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,8 +4,7 @@
 require &quot;rubygems&quot;
 require &quot;glapp&quot;
 
-include GLApp::Engine
-public
+include GLApp
 
 class Triangle
   attr_accessor :angle
@@ -53,4 +52,4 @@ end
 
 @triangles = Triangle.boom(10)
 
-GLApp.new(self, 800, 300).show
+show 800, 300, &quot;triangle demo&quot;</diff>
      <filename>examples/triangles2.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,58 +1,108 @@
 require 'rubygems'
 require 'opengl'
 
-class GLApp
-  def initialize(engine, width, height, title = &quot;&quot;)
-    @engine = engine
+module GLApp
+  attr_reader :width, :height, :title
+  
+  def show(width, height, title = &quot;glapp&quot;, fullscreen = false)
+    glutInit
+    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
+    
     @width = width
     @height = height
     @title = title
-    @running = false
-    self.gl_init
+    
+    fullscreen ? go_fullscreen : go_windowed
+    setup
+    
+    setup_context
+    wire
+    glutMainLoop
   end
 
-  def update(seconds)
-    @engine.update(seconds)
+  protected
+  
+  def go_windowed
+    if glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0
+      glutLeaveGameMode
+    end
+
+    unless @window
+      glutInitWindowSize(width, height)
+      @window = glutCreateWindow(title)
+    end
   end
 
-  def draw
-    @engine.draw
+  def go_fullscreen
+    glutGameModeString([width, height].join(&quot;x&quot;))
+
+    if glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)
+      glutEnterGameMode
+      if glutGameModeGet(GLUT_GAME_MODE_ACTIVE) == 0
+        go_windowed
+      end
+    else
+      go_windowed
+    end
   end
+  
+  # begin hooks
 
-  def keyboard(key, modifiers)
-    @engine.keyboard_down(key, modifiers)
+  def setup_context
+    glEnable(GL_DEPTH_TEST)
+    glEnable(GL_BLEND)
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
+    glutIgnoreKeyRepeat(1)
   end
+  
+  def setup
+  end
+  
+  def pre_draw
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
+    glMatrixMode(GL_PROJECTION)
+    glLoadIdentity
+    gluPerspective(30.0, width / height, 0.1, 1000.0)
 
+    glMatrixMode(GL_MODELVIEW)
+    glLoadIdentity
+  end
+  
+  def draw
+  end
+  
+  def post_draw
+    glutSwapBuffers
+  end
+  
+  def update(seconds)
+  end
+  
+  def keyboard_down(key, modifiers)
+  end
+  
   def keyboard_up(key, modifiers)
-    @engine.keyboard_up(key, modifiers)
   end
-
-  def special_keyboard(key, modifiers)
-    @engine.special_keyboard_down(key, modifiers)
+  
+  def special_keyboard_down(key, modifiers)
   end
-
+  
   def special_keyboard_up(key, modifiers)
-    @engine.special_keyboard_up(key, modifiers)
   end
-
+  
   def mouse_click(button, state, x, y)
-    @engine.mouse_click(button, state, x, y)
   end
-
-  def mouse_active_motion(x, y)
-    @engine.mouse_dragging_motion(x, y)
-    @engine.mouse_motion(x, y)
+  
+  def mouse_dragging_motion(x, y)
   end
-
+  
   def mouse_passive_motion(x, y)
-    @engine.mouse_passive_motion(x, y)
-    @engine.mouse_motion(x, y)
   end
-
-  def resize(width, height)
-    # avoid divide-by-zero
-    height = 1.0 if height &lt;= 0
-
+  
+  def mouse_motion(x, y)
+  end
+  
+  def resize
     # Reset the coordinate system
     glMatrixMode(GL_PROJECTION)
     glLoadIdentity
@@ -67,72 +117,17 @@ class GLApp
     gluLookAt(0, 0, 5,
               0, 0, -1,
               0, 1, 0)
-
-    @width, @height = width, height
-  end
-
-  def show
-    if glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0
-      glutLeaveGameMode
-    end
-
-    unless @window
-      glutInitWindowSize(@width, @height)
-      @window = glutCreateWindow(@title)
-    end
-
-    self.setup_context
-    self.go unless running?
-  end
-
-  protected
-
-  def go_fullscreen(width, height, title = &quot;&quot;)
-    glutGameModeString([width, height].join(&quot;x&quot;))
-
-    if glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)
-      glutEnterGameMode
-      if glutGameModeGet(GLUT_GAME_MODE_ACTIVE) == 0
-        self.go_windowed
-      end
-    else
-      go_windowed
-    end
-
-    self.setup_context
-    self.go unless self.running?
-  end
-
-  def go
-    @running = true
-    @engine.setup
-    glutMainLoop
-  end
-
-  def running?
-    @running
   end
-
-  def gl_init
-    glutInit
-    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
-  end
-
-  def setup_context
-    glEnable(GL_DEPTH_TEST)
-
-    glutIgnoreKeyRepeat(1)
-
+  
+  # end hooks
+  
+  private
+  
+  def wire
     glutDisplayFunc(lambda do
-      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
-      glMatrixMode(GL_PROJECTION)
-      glLoadIdentity
-      gluPerspective(30.0, @width / @height, 0.1, 1000.0)
-
-      glMatrixMode(GL_MODELVIEW)
-      glLoadIdentity
+      pre_draw
       draw
-      glutSwapBuffers
+      post_draw
     end)
 
     glutIdleFunc(lambda do
@@ -145,7 +140,7 @@ class GLApp
     end)
 
     glutKeyboardFunc(lambda do |key, x, y|
-      keyboard(key, glutGetModifiers)
+      keyboard_down(key, glutGetModifiers)
     end)
 
     glutKeyboardUpFunc(lambda do |key, x, y|
@@ -153,7 +148,7 @@ class GLApp
     end)
 
     glutSpecialFunc(lambda do |key, x, y|
-      special_keyboard(key, glutGetModifiers)
+      special_keyboard_down(key, glutGetModifiers)
     end)
 
     glutSpecialUpFunc(lambda do |key, x, y|
@@ -165,33 +160,19 @@ class GLApp
     end)
 
     glutMotionFunc(lambda do |x, y|
-      mouse_active_motion(x, y)
+      mouse_dragging_motion(x, y)
+      mouse_motion(x, y)
     end)
 
     glutPassiveMotionFunc(lambda do |x, y|
       mouse_passive_motion(x, y)
+      mouse_motion(x, y)
     end)
 
     glutReshapeFunc(lambda do |width, height|
-      resize(width, height)
+      @width = width
+      @height = height
+      resize
     end)
-
-    glEnable(GL_BLEND)
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
-  end
-
-  module Engine
-    def setup() end
-    def update(seconds) end
-    def draw() end
-    def keyboard_down(key, modifiers) end
-    def keyboard_up(key, modifiers) end
-    def special_keyboard_down(key, modifiers) end
-    def special_keyboard_up(key, modifiers) end
-    def mouse_click(button, state, x, y) end
-    def mouse_dragging_motion(x, y) end
-    def mouse_passive_motion(x, y) end
-    def mouse_motion(x, y) end
   end
 end
-</diff>
      <filename>lib/glapp.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>98d21b1f4739e6d8d853e67ac794a18b2ad93903</id>
    </parent>
  </parents>
  <author>
    <name>Tom Lieber</name>
    <email>tom@alltom.com</email>
  </author>
  <url>http://github.com/alltom/glapp/commit/de62c4b716dca034de0459353eeef449f8a64c07</url>
  <id>de62c4b716dca034de0459353eeef449f8a64c07</id>
  <committed-date>2009-05-18T18:15:04-07:00</committed-date>
  <authored-date>2009-05-18T18:15:04-07:00</authored-date>
  <message>Everything inside a GLApp module</message>
  <tree>8f9d3fd7d53c43d9221c959f3609bc17721036d8</tree>
  <committer>
    <name>Tom Lieber</name>
    <email>tom@alltom.com</email>
  </committer>
</commit>
