forked from Metalab/The-Flying-Camera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameView.rb
56 lines (47 loc) · 1.12 KB
/
GameView.rb
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
50
51
52
53
54
55
56
#
# GameView.rb
# CtF
#
# Created by Thomas R. Koll on 09.12.10.
# Copyright (c) 2010 ananasblau. All rights reserved.
#
class GameView < NSOpenGLView
attr_accessor :controller, :active
def initWithFrame(frame)
attributes = Pointer.new_with_type('I', 8)
attributes[0] = NSOpenGLPFANoRecovery
attributes[1] = NSOpenGLPFAColorSize
attributes[2] = 24
attributes[3] = NSOpenGLPFADepthSize
attributes[4] = 16
attributes[5] = NSOpenGLPFADoubleBuffer
attributes[6] = NSOpenGLPFAAccelerated
attributes[7] = 0
pixel_format = NSOpenGLPixelFormat.alloc.initWithAttributes(attributes)
initWithFrame(frame, pixelFormat:pixel_format)
@active = true
return self
end
def prepareOpenGL
glEnable(GL_CULL_FACE)
glEnable(GL_MULTISAMPLE)
glAlphaFunc ( GL_GREATER, 0.1 )
glEnable ( GL_ALPHA_TEST )
glClearColor(0, 0, 0, 0)
end
def acceptsFirstResponder
return true
end
def drawRect(rect)
return unless @active
end
def reshape
@controller.game_loop.set_viewport_rectangle(bounds)
end
def keyDown(event)
@controller.keyDown(event)
end
def mouseDown(event)
@controller.mouse_down(event)
end
end