New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sample script for the Gtk::GLArea widget #499
Conversation
when :OPENGL_PLATFORM_MACOSX | ||
OpenGL.load_lib("libGL.dylib", "/System/Library/Frameworks/OpenGL.framework/Libraries") | ||
when :OPENGL_PLATFORM_LINUX | ||
OpenGL.load_lib("libGL.so", "/usr/lib") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I'm worrying about #500 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:) I will work on it !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merci! ;)
Perhaps, in this PR, you should be fix like: cedlemo@23bf3af. |
Oops, just one step behind... |
# /usr/lib /usr/lib64 slackware | ||
# /usr/lib/i386.. /usr/lib/x86_64..debian | ||
libs = Dir.glob("/usr/lib*/libGL.so") # libs in /usr/lib or /usr/lib64 for most distribs | ||
libs = Dir.glob("/usr/lib*/*/libGL.so") if libs.empty? == 0 # debian like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array#empty?
returns Boolean value.
So, it is needless comparing to zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment means libs.size == 0
can rewrite libs.empty?
.
I did it too fast that is why I made an error. As I had already done it in the previous pull request I didn't focus enought on it thinking it was easy. すみません ! |
Thanks for your fixing! 油断大敵[(pronounce: Yudan'taiteki) Don't be too sure of yourself!] ですね! |
I like it! Merci ! |
For now, it's @kou's reviewing turn. Let's waiting for his review. |
Thanks.
Do you know requirements of this script? I'm a GNOME 3 user. So GL will be available on my environment. Here is my environment information:
|
The unique linux environment tested (which was mine) use nvidia. Check OpenGL on your system: What is the output of those commands on your system:
Find the libs :
|
Here are outputs:
I like nouveau driver rather than nvidia driver for NVIDIA video card. Because nouveau driver is free software. |
It seems that your OpenGL version is not very recent:
I have seen that the GtkGLArea needed OpenGL version => 3.2: source : https://www.bassi.io/articles/2015/02/17/using-opengl-with-gtk/
Maybe it is the problem. I will install nouveau instead of nvidia on my system in order to see if it does the same. I know that you must be busy but it would be great if you could find the time to just check the OpenGL samples (https://github.com/vaiorabbit/ruby-opengl/tree/master/sample) and send a report like I did here vaiorabbit/ruby-opengl#8 and add you system configuration and environment informations in the README.m. So far here is what we have (before I send an issue to @vaoirabbit):
Any other ideas? |
Ok so I have tested with nouveau and it seems that I have the same issue:
I have the same OpenGL version too:
I am about to tests all the opengl-bindings sample to see if there is no problem with the nouveau driver. I think that for this script I will use those methods: Gtk::GLArea.new.methods.grep(/version/)
=> [:required_version, :set_required_version]
irb(main):003:0> In order to make a test on the OpenGL version or use the opengl bindings to get the current version. |
Thanks for the information. It must be the problem on my environment.
It works but it's needless. We can just use
dlopen(3) used in I'll merge this sample script when you replace the current
I think so. Your test also says "yes".
"use the opengl bindings to get the current version" is better. Because
You're right. I'll do it in this month. |
Well I am not sure about that because I already talk with vaiorabbit about this( maybe I wasn't clear enought , english is not my native language). see (vaiorabbit/ruby-opengl#7):
But I will try again. |
(English is not my native language too. :<) I'll try to describe again. The following code works on my environment. (It is crashed but =begin
gtkglarea1.rb draw a triangle on a grey background
this script need the opengl-bindings gem from :
https://github.com/vaiorabbit/ruby-opengl
gem install opengl-bindings
sources:
http://antongerdelan.net/opengl/hellotriangle.html
opengl-bindings/sample/RedBook/varray
opengl-bindings/sample/GLES/gles.rb
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/
https://developer.gnome.org/gtk3/stable/GtkGLArea.html
https://www.bassi.io/articles/2015/02/17/using-opengl-with-gtk/
http://stackoverflow.com/questions/30337845/gldrawarrays-not-working-using-gtkglarea-in-gtk3
http://gamedev.stackexchange.com/questions/8042/vertex-array-object-opengl
=end
require "gtk3"
require "opengl"
unless Gtk::Version.or_later?(3, 16, 0)
puts "This sample requires GTK+ 3.16.0 or later: #{Gtk::Version::STRING}"
exit
end
OpenGL.load_lib
include OpenGL
window = Gtk::Window.new("OpenGL widget test")
window.set_size_request(400, 400)
glarea = Gtk::GLArea.new
window.add(glarea)
gl_vao = nil
glarea.signal_connect("realize") do |widget|
widget.make_current
puts "realize"
# Define a triangle in a vertex buffer ( Vertex Buffer Object)
points = [
0.0, 0.5, 0.0, # x1, y1, z1
0.5, -0.5, 0.0, # x2, y2, z2
-0.5, -0.5, 0.0 # x3, y3, z3
]
# Create a vertex array object (VAO) and "bind" it (set it as the current VAO)
vao_buf = " "
glGenVertexArrays(1, vao_buf)
gl_vao = vao_buf.unpack("L")[0]
glBindVertexArray(gl_vao)
# We copy points onto the graphics card in a unit called vertex buffer object (vbo).
# Create an empty buffer
vbo_buf = " "
glGenBuffers(1, vbo_buf)
g_vbo = vbo_buf.unpack("L")[0]
# Set the empty buffer as the current OpenGL's state machine by "binding"
glBindBuffer(GL_ARRAY_BUFFER, g_vbo)
# Copy the points in the currently bound buffer
glBufferData(GL_ARRAY_BUFFER,
3 * 4 * Fiddle::SIZEOF_FLOAT,
points.pack("F*"),
GL_STATIC_DRAW
)
# First attribute buffer : vertices
glEnableVertexAttribArray(0)
glVertexAttribPointer(0, # No particular reason for 0
3, # size
GL_FLOAT, # type
GL_FALSE, # normalized?
0, # stride
0 # array buffer offset
)
# Clear the current VAO
glBindVertexArray(0)
end
glarea.signal_connect("render") do |_widget, _context|
puts "render"
glClearColor(0.3, 0.3, 0.3, 1)
glClear(GL_COLOR_BUFFER_BIT)
# Reload the VAO we created previously
glBindVertexArray(gl_vao)
glDrawArrays(GL_TRIANGLES, 0, 3)
# we completed our drawing; the draw commands will be
# flushed at the end of the signal emission chain, and
# the buffers will be drawn on the window
true # to stop other handlers from being invoked for the event.
# false to propagate the event further.
end
window.signal_connect("destroy") { Gtk.main_quit }
window.show_all
Gtk.main |
分かりました! |
Great! :-) Could you also update this pull request? I'll merge. |
2e4b97e
to
9c5d287
Compare
f34b89b
to
946edc9
Compare
Sorry for the delay. Modifications done and rebase too. |
Add sample script for the Gtk::GLArea widget Patch by cedlemo. Thanks!!!
Thanks. |
Here is the first example of the Gtk::GLArea. I plan to do 2 or 3 more examples (for fun).
It could be great to put a reference of the OpenGL bindings we support in th README.