Hi all!
An example of the delivery of the compiler opengl_button.bas in the folder GTK+ I for some reason crashes . I know that GTK2 is deprecated, but I need a working example GTK2+OpenGL. Can someone give a working example GTK2+OpenGL or fix opengl_button.bas to make it work?
P.S. Linux Mint 64-bit
(SOLVED) Linux GTK2 example opengl_button.bas not work
(SOLVED) Linux GTK2 example opengl_button.bas not work
Last edited by VANYA on Feb 17, 2019 8:16, edited 1 time in total.
Re: Linux GTK2 example not work
I never managed to get to work opengl_button.bas example. Most likely something changed in the function gtk_widget_set_gl_capability and it's not working as it was originally conceived. This is not surprising because the source code of GTK very often, plowed with it for many changes at all no reason.
how this is done conditionally:
version 1 - the function has name settextwidget
version 2 - the function rename in the settext
version 3 - all obsolete. Search a month a replacement in help, good luck!
Developers GTK no worries about backward compatibility. That's one of the reasons why Linux is always dragged in the ass
In any case, I found a solution that will help to me use OpenGl+GTK2. No one in the topic no answer , so I think that the topic is not interesting to anyone. I mark the topic as solved.
how this is done conditionally:
version 1 - the function has name settextwidget
version 2 - the function rename in the settext
version 3 - all obsolete. Search a month a replacement in help, good luck!
Developers GTK no worries about backward compatibility. That's one of the reasons why Linux is always dragged in the ass
In any case, I found a solution that will help to me use OpenGl+GTK2. No one in the topic no answer , so I think that the topic is not interesting to anyone. I mark the topic as solved.
Re: (SOLVED) Linux GTK2 example opengl_button.bas not work
https://www.freebasic-portal.de/downloa ... i-164.htmlVANYA wrote:Can someone give a working example GTK2+OpenGL ...?
P.S. Linux Mint 64-bit
https://www.freebasic-portal.de/downloa ... 1-178.html (OpenGL only, no GTK)
https://www.freebasic-portal.de/downloa ... r-225.html
Regards
Linux GTK3 example not work
TJF thank you for the examples. Now I have another headache. Can't understand why my system is not working properly in this example (GTK3 + OpenGL):
I see the gray window with sliders. In the window no more appears :
Why is nothing displayed except the gray shading of the window?
Code: Select all
#define GL_GLEXT_PROTOTYPES
#include "crt/stdlib.bi"
#include "gtk/gtk3.bi"
#include "GL/gl.bi"
#include "GL/glu.bi"
#inclib "epoxy"
enum
X_AXIS
Y_AXIS
Z_AXIS
N_AXIS
end enum
dim shared as single rotation_angles(N_AXIS) = { 0.0 }
dim shared as GtkWidget ptr gl_area
dim shared as GLfloat vertex_data(...) = { 0., 0.5, 0., 1., 0.5, -0.366, 0., 1., -0.5, -0.366, 0., 1. }
sub init_buffers (vao_out as GLuint ptr, buffer_out as GLuint ptr)
dim as GLuint vao, buffer
'/* we only use one VAO, so we always keep it bound */
glGenVertexArrays (1, @vao)
glBindVertexArray (vao)
glGenBuffers (1, @buffer)
glBindBuffer (GL_ARRAY_BUFFER, buffer)
glBufferData (GL_ARRAY_BUFFER, ubound (vertex_data), @vertex_data(0), GL_STATIC_DRAW)
glBindBuffer (GL_ARRAY_BUFFER, 0)
if (vao_out <> NULL) then
*vao_out = vao
EndIf
if (buffer_out <> NULL) then
*buffer_out = buffer
EndIf
end sub
function create_shader (type_ as integer , src as zstring ptr) as GLuint
dim as GLuint shader
dim as integer status
shader = glCreateShader (type_)
glShaderSource (shader, 1, @src, NULL)
glCompileShader (shader)
glGetShaderiv (shader, GL_COMPILE_STATUS, cast(any ptr,@status))
if (status = GL_FALSE) then
dim as integer log_len
dim as zstring ptr buffer
glGetShaderiv (shader, GL_INFO_LOG_LENGTH, cast(any ptr,@log_len))
buffer = g_malloc (log_len + 1)
glGetShaderInfoLog (shader, log_len, NULL, buffer)
'g_warning (!"Compile failure in %s shader:\n%s\n",_
'type_ == GL_VERTEX_SHADER ? "vertex" : "fragment",
'buffer);
g_free (buffer)
glDeleteShader (shader)
return 0
endif
return shader
end function
dim shared as zstring ptr vertex_shader_code = _
@(!"#version 330\n\n layout(location = 0) in vec4 position;\nuniform mat4 mvp;\nvoid main() {\n gl_Position = mvp * position;\n}")
dim shared as zstring ptr fragment_shader_code = @(!"#version 330\n\nout vec4 outputColor;\nvoid main() {\n float lerpVal = gl_FragCoord.y / 400.0f;\n outputColor = mix(vec4(1.0f, 0.85f, 0.35f, 1.0f), vec4(0.2f, 0.2f, 0.2f, 1.0f), lerpVal);\n}")
sub init_shaders (program_out as GLuint ptr, mvp_out as GLuint ptr)
dim as GLuint vertex, fragment
dim as GLuint program = 0
dim as GLuint mvp = 0
dim as integer status
vertex = create_shader (GL_VERTEX_SHADER, vertex_shader_code)
if (vertex = 0) then
*program_out = 0
exit sub
endif
fragment = create_shader (GL_FRAGMENT_SHADER, fragment_shader_code)
if (fragment = 0) then
glDeleteShader (vertex)
*program_out = 0
exit sub
endif
program = glCreateProgram ()
glAttachShader (program, vertex)
glAttachShader (program, fragment)
glLinkProgram (program)
glGetProgramiv (program, GL_LINK_STATUS, cast(any ptr,@status))
if (status = GL_FALSE) then
dim as integer log_len
dim as zstring ptr buffer
glGetProgramiv (program, GL_INFO_LOG_LENGTH, cast(any ptr,@log_len))
buffer = g_malloc (log_len + 1)
glGetProgramInfoLog (program, log_len, NULL, buffer)
g_warning (!"Linking failure:\n%s\n", buffer)
g_free (buffer)
glDeleteProgram (program)
program = 0
else
mvp = glGetUniformLocation (program, "mvp")
glDetachShader (program, vertex)
glDetachShader (program, fragment)
endif
glDeleteShader (vertex)
glDeleteShader (fragment)
if (program_out <> NULL) then *program_out = program
if (mvp_out <> NULL) then *mvp_out = mvp
end sub
sub compute_mvp (res as single ptr, phi as single, theta as single, psi as single)
dim as single x = phi * (G_PI / 180.f)
dim as single y = theta * (G_PI / 180.f)
dim as single z = psi * (G_PI / 180.f)
dim as single c1 = cos (x) , s1 = sin (x)
dim as single c2 = cos (y), s2 = sin (y)
dim as single c3 = cos (z), s3 = sin (z)
dim as single c3c2 = c3 * c2
dim as single s3c1 = s3 * c1
dim as single c3s2s1 = c3 * s2 * s1
dim as single s3s1 = s3 * s1
dim as single c3s2c1 = c3 * s2 * c1
dim as single s3c2 = s3 * c2
dim as single c3c1 = c3 * c1
dim as single s3s2s1 = s3 * s2 * s1
dim as single c3s1 = c3 * s1
dim as single s3s2c1 = s3 * s2 * c1
dim as single c2s1 = c2 * s1
dim as single c2c1 = c2 * c1
'/* initialize to the identity matrix */
res[0] = 1.: res[4] = 0.: res[8] = 0.: res[12] = 0.
res[1] = 0.: res[5] = 1.: res[9] = 0.: res[13] = 0.
res[2] = 0.: res[6] = 0.: res[10] = 1.: res[14] = 0.
res[3] = 0.: res[7] = 0.: res[11] = 0.: res[15] = 1.
'/* apply all three rotations using the three matrices:
'*
'* ⎡ c3 s3 0 ⎤ ⎡ c2 0 -s2 ⎤ ⎡ 1 0 0 ⎤
'* ⎢ -s3 c3 0 ⎥ ⎢ 0 1 0 ⎥ ⎢ 0 c1 s1 ⎥
'* ⎣ 0 0 1 ⎦ ⎣ s2 0 c2 ⎦ ⎣ 0 -s1 c1 ⎦
'*/
res[0] = c3c2: res[4] = s3c1 + c3s2s1: res[8] = s3s1 - c3s2c1: res[12] = 0.f
res[1] = -s3c2: res[5] = c3c1 - s3s2s1: res[9] = c3s1 + s3s2c1: res[13] = 0.f
res[2] = s2: res[6] = -c2s1: res[10] = c2c1: res[14] = 0.f
res[3] = 0.: res[7] = 0.f: res[11] = 0.f: res[15] = 1.f
end sub
dim shared as GLuint position_buffer
dim shared as GLuint program
dim shared as GLuint mvp_location
sub realize (widget as GtkWidget ptr)
gtk_gl_area_make_current (GTK_GL_AREA (widget))
init_buffers (@position_buffer, NULL)
init_shaders (@program, @mvp_location)
End Sub
sub unrealize (widget as GtkWidget ptr)
gtk_gl_area_make_current (GTK_GL_AREA (widget))
glDeleteBuffers (1, @position_buffer)
glDeleteProgram (program)
End Sub
sub draw_triangle ()
dim as single mvp(16)
'g_assert (position_buffer <> 0)
'g_assert (program <> 0)
compute_mvp (@mvp(0),_
rotation_angles(X_AXIS),_
rotation_angles(Y_AXIS),_
rotation_angles(Z_AXIS))
glUseProgram (program)
glUniformMatrix4fv (mvp_location, 1, GL_FALSE, @mvp(0))
glBindBuffer (GL_ARRAY_BUFFER, position_buffer)
glEnableVertexAttribArray (0)
glVertexAttribPointer (0, 4, GL_FLOAT, GL_FALSE, 0, 0)
glDrawArrays (GL_TRIANGLES, 0, 3)
glDisableVertexAttribArray (0)
glUseProgram (0)
End Sub
function render (area as GtkGLArea ptr, context as GdkGLContext ptr) as gboolean
glClearColor (0.5, 0.5, 0.5, 1.0)
glClear (GL_COLOR_BUFFER_BIT)
draw_triangle ()
glFlush ()
return TRUE
end function
sub on_axis_value_change (adjustment as GtkAdjustment ptr, data_ as gpointer )
dim as integer axis = GPOINTER_TO_INT (data_)
if (axis < 0 orelse axis >= N_AXIS) then exit sub
rotation_angles(axis) = gtk_adjustment_get_value (adjustment)
gtk_widget_queue_draw (gl_area)
end sub
function create_axis_slider (axis as integer) as GtkWidget ptr
dim as GtkWidget ptr box, label, slider
dim as GtkAdjustment ptr adj
dim as zstring ptr text
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE)
select case (axis)
case X_AXIS
text = @"X axis"
case Y_AXIS
text = @"Y axis"
case Z_AXIS
text = @"Z axis"
case else
'g_assert_not_reached ()
end select
label = gtk_label_new (text)
gtk_container_add (GTK_CONTAINER (box), label)
gtk_widget_show (label)
adj = gtk_adjustment_new (0.0, 0.0, 360.0, 1.0, 12.0, 0.0)
g_signal_connect (adj, "value-changed", G_CALLBACK (@on_axis_value_change), GINT_TO_POINTER (axis))
slider = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, adj)
gtk_container_add (GTK_CONTAINER (box), slider)
gtk_widget_set_hexpand (slider, TRUE)
gtk_widget_show (slider)
gtk_widget_show (box)
return box
end function
dim as GtkWidget ptr window_, box, button, controls
dim as integer i
gtk_init (0, 0)
'/* create a new pixel format; we use this to configure the
'* GL context, and to check for features
'*/
window_ = gtk_window_new (GTK_WINDOW_TOPLEVEL)
gtk_window_set_title (GTK_WINDOW (window_), "GtkGLArea - Triangle")
gtk_window_set_default_size (GTK_WINDOW (window_), 400, 600)
gtk_container_set_border_width (GTK_CONTAINER (window_), 12)
g_signal_connect (window_, "destroy", G_CALLBACK (@gtk_main_quit), NULL)
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE)
gtk_box_set_spacing (GTK_BOX (box), 6)
gtk_container_add (GTK_CONTAINER (window_), box)
gtk_widget_show (box)
gl_area = gtk_gl_area_new ()
gtk_widget_set_hexpand (gl_area, TRUE)
gtk_widget_set_vexpand (gl_area, TRUE)
gtk_container_add (GTK_CONTAINER (box), gl_area)
g_signal_connect (gl_area, "realize", G_CALLBACK (@realize), NULL)
g_signal_connect (gl_area, "unrealize", G_CALLBACK (@unrealize), NULL)
g_signal_connect (gl_area, "render", G_CALLBACK (@render), NULL)
gtk_widget_show (gl_area)
controls = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE)
gtk_container_add (GTK_CONTAINER (box), controls)
gtk_widget_set_hexpand (controls, TRUE)
gtk_widget_show (controls)
for i = 0 to N_AXIS-1
gtk_container_add (GTK_CONTAINER (controls), create_axis_slider (i))
Next
button = gtk_button_new_with_label ("Quit")
gtk_widget_set_hexpand (button, TRUE)
gtk_container_add (GTK_CONTAINER (box), button)
g_signal_connect_swapped (button, "clicked", G_CALLBACK (@gtk_widget_destroy), window_)
gtk_widget_show (button)
gtk_widget_show (window_)
gtk_main ()
Why is nothing displayed except the gray shading of the window?