libsoy
view src/widgets/Canvas.gs @ 131:b44b4d9c375d
Fix GL version checking code.
| author | DavidCzech |
|---|---|
| date | Thu Jan 28 16:53:41 2010 -0800 (6 weeks ago) |
| parents | d15af322d322 |
| children | 0ffc4df88ca8 |
line source
1 /*
2 * libsoy - soy.widgets.Canvas
3 * Copyright (C) 2006,2007,2008,2009,2010 PySoy Group
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program; if not, see http://www.gnu.org/licenses
17 *
18 */
19 [indent=2]
20 uses
21 GLib
22 Gdk
23 GL
24 soy.textures
26 //namespace soy.widgets
28 class soy.widgets.Canvas : soy.widgets.Widget
30 texture : soy.textures.Texture
32 verts : array of GLfloat = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,\
33 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,\
34 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,\
35 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }
37 faces : array of GLushort = { 0,1,2,2,3,0 }
39 vbuffer : GLint // Vertex Buffer
40 ibuffer : GLint // Index Buffer
42 construct ( )
43 texture = new soy.textures.Texture()
45 def override render ( ) : void
46 //
47 ///////////////////////////////////////
48 //
49 // don't bother rendering w/o a texture
50 //
52 if texture == null
53 return
55 //
56 ///////////////////////////////////////
57 //
58 // Set the viewport to the current Widget position and size
59 //
60 //glViewport( (GL.GLint) Xpos, (GL.GLint) Ypos, (GL.GLint) width, (GL.GLint) height)
61 //
62 ///////////////////////////////////////
63 //
64 // Reset the projection and modelview matrix, set ortho rendering
65 //
66 glMatrixMode(GL_PROJECTION)
67 glLoadIdentity()
68 glOrtho(0.0, 1.0, 0.0, 1.0, -1, 1)
69 glMatrixMode(GL_MODELVIEW)
70 glLoadIdentity()
72 glDisableClientState(GL_NORMAL_ARRAY) // We're not going to use Normals
74 texture.enable()
76 glVertexPointer(3, GL_FLOAT, 20, verts)
77 glTexCoordPointer(2, GL_FLOAT, 20, verts+3)
78 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, faces)
80 glEnableClientState(GL_NORMAL_ARRAY) // But remember to enable them for later...
