Created
November 26, 2012 03:45
-
-
Save glucero/4146516 to your computer and use it in GitHub Desktop.
An OpenGLES 'LCD dot-matrix' style pixel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pixel | |
attr_reader :pointer | |
Minimum = 0.00 | |
Maximum = 1.00 | |
Margin = 0.15 | |
Vertices = [ | |
# 4-point triangle fan | |
# | |
# | |
# -1,2 0,2 1,2 2,2 | |
# | |
# | |
# -1,1 0,1 1,1 2,1 | |
# C<----B | |
# | ^ | |
# V | | |
# -1,0 0D0 A1,0 2,0 | |
# | |
# | |
# | |
# -1,-1 0,-1 1,-1 2,-1 | |
# | |
# | |
Maximum - Margin, Minimum , # A (x, y) | |
Maximum - Margin, Maximum - Margin, # B (x, y) | |
Minimum , Maximum - Margin, # C (x, y) | |
Minimum , Minimum # D (x, y) | |
] | |
def self.create(x, y, size) | |
coordinates = Hash[true, x, false, y] | |
pointer = Pointer.new(:float, Vertices.size) | |
Vertices.each_with_index do |vertex, index| | |
vertex += coordinates[index.even?] | |
vertex *= size | |
pointer[index] = vertex | |
end | |
new pointer | |
end | |
def render | |
glEnableVertexAttribArray(GLKVertexAttribPosition) | |
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, pointer) | |
glDrawArrays(GL_TRIANGLE_FAN, 0, 4) | |
glDisableVertexAttribArray(GLKVertexAttribPosition) | |
end | |
def initialize(pointer) | |
@pointer = pointer | |
end | |
end |
Author
glucero
commented
Nov 26, 2012
activate each pixel in sequence over and over (limited by refresh rate and cpu)
(simplifed to show how the pixels are used)
def viewDidLoad
super.tap do
# build a 3x4 grid
@grid = 4.times.map { |height| 3.times.map { |width| Pixel.create(width, height, 20) } }
@grid.flatten!
@active = 0
# setupGL and the rest of the GLES view
end
end
def glkView(view, drawInRect:rect)
# after clearing the GL buffer
@grid[@active].render
end
def update
if @active > 10
@active = 0
else
@active += 1
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment