Class: RBGLox::Mesh

Inherits:
Resource show all
Includes:
Gl
Defined in:
lib/rbglox/mesh.rb

Overview

Semi-abstract Mesh Class

Direct Known Subclasses

MeshCube, MeshQuad

Instance Attribute Summary

Attributes inherited from Resource

#id

Instance Method Summary collapse

Constructor Details

#initialize(verts, texs, norms, tris) ⇒ Mesh

Constructor



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rbglox/mesh.rb', line 6

def initialize(verts, texs, norms, tris)
  @id = glGenLists 1

  glNewList id, GL_COMPILE
    glPushClientAttrib GL_CLIENT_VERTEX_ARRAY_BIT
		glEnableClientState GL_VERTEX_ARRAY
 	glEnableClientState GL_TEXTURE_COORD_ARRAY
  glEnableClientState GL_NORMAL_ARRAY
  glVertexPointer 3, GL_FLOAT, 0, verts
  glNormalPointer GL_FLOAT, 0, norms
    glTexCoordPointer 2, GL_FLOAT, 0, texs
		glDrawElements GL_TRIANGLES, tris.size, GL_UNSIGNED_INT, tris
    glPopClientAttrib
  glEndList
end

Instance Method Details

#drawObject

Draw the mesh by calling the internal display list



23
24
25
# File 'lib/rbglox/mesh.rb', line 23

def draw
  glCallList id
end

#freeObject

Free the mesh by destroying the internal display list



33
34
35
# File 'lib/rbglox/mesh.rb', line 33

def free
  glDeleteLists id, 1
end

#reloadObject

Reload the mesh



28
29
30
# File 'lib/rbglox/mesh.rb', line 28

def reload
  # do nothing
end