libsoy

annotate src/widgets/Canvas.gs @ 131:b44b4d9c375d

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