1
General / Can't modify Vertex of a VertexArray
« on: June 29, 2013, 12:35:33 am »
Hi !
I use rbSFML in my project. It works like a charm but I can't figure out how to get VertexArray to work properly.
My code :
But the triangle isn't drawn :/
I've done some testing and it seems that "@vertices[id]" return a new Vertex so I can't modify the Vertex of VertexArray.
For example, if I do something like that :
The only way I've find to do what I want is to clear the VertexArray and fill it with new Vertex (by using the "append" function) each time I want to modify a Vertex.
I've tried with a ruby array instead of a VertexArray. Works well but it's pretty slow.
So how can I easily change the Vertex position/color/texture of a VertexArray ?
I use the latest version of rbSFML on github and SFML2.0.
Thanks in advance
I use rbSFML in my project. It works like a charm but I can't figure out how to get VertexArray to work properly.
My code :
require 'sfml'
include SFML
class MainWindow
def initialize(width, height)
@window = RenderWindow.new([width, height], "VertexArray")
@vertices = VertexArray.new(Triangles, 3)
@vertices[0].position = [100, 100]
@vertices[1].position = [200, 100]
@vertices[2].position = [200, 200]
@vertices[0].color = Color::Red
@vertices[1].color = Color::Green
@vertices[2].color = Color::Blue
update
end
def update
while @window.open?
@window.each_event do |event|
@window.close if event.type == Event::Closed
end
@window.clear
@window.draw(@vertices)
@window.display
end
end
end
MainWindow.new(640, 480)
include SFML
class MainWindow
def initialize(width, height)
@window = RenderWindow.new([width, height], "VertexArray")
@vertices = VertexArray.new(Triangles, 3)
@vertices[0].position = [100, 100]
@vertices[1].position = [200, 100]
@vertices[2].position = [200, 200]
@vertices[0].color = Color::Red
@vertices[1].color = Color::Green
@vertices[2].color = Color::Blue
update
end
def update
while @window.open?
@window.each_event do |event|
@window.close if event.type == Event::Closed
end
@window.clear
@window.draw(@vertices)
@window.display
end
end
end
MainWindow.new(640, 480)
But the triangle isn't drawn :/
I've done some testing and it seems that "@vertices[id]" return a new Vertex so I can't modify the Vertex of VertexArray.
For example, if I do something like that :
@vertices = VertexArray.new(Triangles, 3)
vertex = @vertices[0]
vertex.position = [100, 100]
p @vertices[0].position == vertex.position #=> false
The vertex in the VertexArray doesn't have the new position.vertex = @vertices[0]
vertex.position = [100, 100]
p @vertices[0].position == vertex.position #=> false
The only way I've find to do what I want is to clear the VertexArray and fill it with new Vertex (by using the "append" function) each time I want to modify a Vertex.
I've tried with a ruby array instead of a VertexArray. Works well but it's pretty slow.
So how can I easily change the Vertex position/color/texture of a VertexArray ?
I use the latest version of rbSFML on github and SFML2.0.
Thanks in advance