imgui-bindings 0.0.1 → 0.0.2.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,11 @@
1
1
  require 'ffi'
2
2
  require 'opengl'
3
- include OpenGL
4
3
 
5
4
  require_relative 'imgui'
6
5
 
7
6
  module ImGui
8
7
 
9
- @@g_GlVersion = 0 # Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries.
8
+ @@g_GlVersion = 0 # Extracted at runtime using GL::MAJOR_VERSION, GL::MINOR_VERSION queries.
10
9
  @@g_GlslVersionString = "" # Specified by user or detected based on compile time
11
10
  @@g_FontTexture = nil
12
11
 
@@ -26,16 +25,16 @@ module ImGui
26
25
 
27
26
  def self.PrintShaderCompileStatus(handle)
28
27
  rvalue = ' ' * 4
29
- glGetShaderiv(handle, GL_COMPILE_STATUS, rvalue)
28
+ GL.GetShaderiv(handle, GL::COMPILE_STATUS, rvalue)
30
29
  rvalue = rvalue.unpack1('L')
31
- if rvalue == GL_FALSE
30
+ if rvalue == GL::FALSE
32
31
  $stderr.puts "Error in compiling shader"
33
32
  log_length = ' ' * 4
34
- glGetShaderiv(handle, GL_INFO_LOG_LENGTH, log_length)
33
+ GL.GetShaderiv(handle, GL::INFO_LOG_LENGTH, log_length)
35
34
  log_length = log_length.unpack1('L')
36
35
  if log_length > 0
37
36
  buf = ' ' * log_length
38
- glGetShaderInfoLog(handle, log_length, nil, buf)
37
+ GL.GetShaderInfoLog(handle, log_length, nil, buf)
39
38
  $stderr.puts(buf)
40
39
  exit()
41
40
  end
@@ -44,16 +43,16 @@ module ImGui
44
43
 
45
44
  def self.PrintProgramLinkStatus(handle)
46
45
  rvalue = ' ' * 4
47
- glGetProgramiv(handle, GL_LINK_STATUS, rvalue)
46
+ GL.GetProgramiv(handle, GL::LINK_STATUS, rvalue)
48
47
  rvalue = rvalue.unpack1('L')
49
- if rvalue == GL_FALSE
48
+ if rvalue == GL::FALSE
50
49
  $stderr.puts "Error in linking program"
51
50
  log_length = ' ' * 4
52
- glGetProgramiv(handle, GL_INFO_LOG_LENGTH, log_length)
51
+ GL.GetProgramiv(handle, GL::INFO_LOG_LENGTH, log_length)
53
52
  log_length = log_length.unpack1('L')
54
53
  if log_length > 0
55
54
  buf = ' ' * log_length
56
- glGetProgramInfoLog(handle, log_length, nil, buf)
55
+ GL.GetProgramInfoLog(handle, log_length, nil, buf)
57
56
  $stderr.puts(buf)
58
57
  exit()
59
58
  end
@@ -62,8 +61,8 @@ module ImGui
62
61
 
63
62
  def self.ImplOpenGL3_Init(glsl_version = nil)
64
63
  major, minor = ' ' * 4, ' ' * 4
65
- glGetIntegerv(GL_MAJOR_VERSION, major)
66
- glGetIntegerv(GL_MINOR_VERSION, minor)
64
+ GL.GetIntegerv(GL::MAJOR_VERSION, major)
65
+ GL.GetIntegerv(GL::MINOR_VERSION, minor)
67
66
  major = major.unpack1('L')
68
67
  minor = minor.unpack1('L')
69
68
  @@g_GlVersion = major * 1000 + minor
@@ -74,7 +73,7 @@ module ImGui
74
73
 
75
74
  # Ref.: Fix imgui_impl_opengl3 on MacOS
76
75
  # https://github.com/ocornut/imgui/pull/3199
77
- if OpenGL.get_platform() == :OPENGL_PLATFORM_MACOSX
76
+ if GL.get_platform() == :OPENGL_PLATFORM_MACOSX
78
77
  glsl_version = "#version 150" if glsl_version == nil
79
78
  else
80
79
  glsl_version = "#version 130" if glsl_version == nil
@@ -102,34 +101,34 @@ module ImGui
102
101
  return if fb_width == 0 || fb_height == 0
103
102
 
104
103
  # Backup GL state
105
- last_active_texture = ' ' * 4; glGetIntegerv(GL_ACTIVE_TEXTURE, last_active_texture)
106
- last_program = ' ' * 4; glGetIntegerv(GL_CURRENT_PROGRAM, last_program)
107
- last_texture = ' ' * 4; glGetIntegerv(GL_TEXTURE_BINDING_2D, last_texture)
108
-
109
- last_sampler = ' ' * 4; glGetIntegerv(GL_SAMPLER_BINDING, last_sampler)
110
- last_array_buffer = ' ' * 4; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, last_array_buffer)
111
- last_vertex_array_object = ' ' * 4; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, last_vertex_array_object)
112
-
113
- last_polygon_mode = ' ' * 8; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode)
114
- last_viewport = ' ' * 16; glGetIntegerv(GL_VIEWPORT, last_viewport)
115
- last_scissor_box = ' ' * 16; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box)
116
-
117
- last_blend_src_rgb = ' ' * 4; glGetIntegerv(GL_BLEND_SRC_RGB, last_blend_src_rgb)
118
- last_blend_dst_rgb = ' ' * 4; glGetIntegerv(GL_BLEND_DST_RGB, last_blend_dst_rgb)
119
- last_blend_src_alpha = ' ' * 4; glGetIntegerv(GL_BLEND_SRC_ALPHA, last_blend_src_alpha)
120
- last_blend_dst_alpha = ' ' * 4; glGetIntegerv(GL_BLEND_DST_ALPHA, last_blend_dst_alpha)
121
- last_blend_equation_rgb = ' ' * 4; glGetIntegerv(GL_BLEND_EQUATION_RGB, last_blend_equation_rgb)
122
- last_blend_equation_alpha = ' ' * 4; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, last_blend_equation_alpha)
123
-
124
- last_enable_blend = glIsEnabled(GL_BLEND)
125
- last_enable_cull_face = glIsEnabled(GL_CULL_FACE)
126
- last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST)
127
- last_enable_stencil_test = glIsEnabled(GL_STENCIL_TEST)
128
- last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST)
104
+ last_active_texture = ' ' * 4; GL.GetIntegerv(GL::ACTIVE_TEXTURE, last_active_texture)
105
+ last_program = ' ' * 4; GL.GetIntegerv(GL::CURRENT_PROGRAM, last_program)
106
+ last_texture = ' ' * 4; GL.GetIntegerv(GL::TEXTURE_BINDING_2D, last_texture)
107
+
108
+ last_sampler = ' ' * 4; GL.GetIntegerv(GL::SAMPLER_BINDING, last_sampler)
109
+ last_array_buffer = ' ' * 4; GL.GetIntegerv(GL::ARRAY_BUFFER_BINDING, last_array_buffer)
110
+ last_vertex_array_object = ' ' * 4; GL.GetIntegerv(GL::VERTEX_ARRAY_BINDING, last_vertex_array_object)
111
+
112
+ last_polygon_mode = ' ' * 8; GL.GetIntegerv(GL::POLYGON_MODE, last_polygon_mode)
113
+ last_viewport = ' ' * 16; GL.GetIntegerv(GL::VIEWPORT, last_viewport)
114
+ last_scissor_box = ' ' * 16; GL.GetIntegerv(GL::SCISSOR_BOX, last_scissor_box)
115
+
116
+ last_blend_src_rgb = ' ' * 4; GL.GetIntegerv(GL::BLEND_SRC_RGB, last_blend_src_rgb)
117
+ last_blend_dst_rgb = ' ' * 4; GL.GetIntegerv(GL::BLEND_DST_RGB, last_blend_dst_rgb)
118
+ last_blend_src_alpha = ' ' * 4; GL.GetIntegerv(GL::BLEND_SRC_ALPHA, last_blend_src_alpha)
119
+ last_blend_dst_alpha = ' ' * 4; GL.GetIntegerv(GL::BLEND_DST_ALPHA, last_blend_dst_alpha)
120
+ last_blend_equation_rgb = ' ' * 4; GL.GetIntegerv(GL::BLEND_EQUATION_RGB, last_blend_equation_rgb)
121
+ last_blend_equation_alpha = ' ' * 4; GL.GetIntegerv(GL::BLEND_EQUATION_ALPHA, last_blend_equation_alpha)
122
+
123
+ last_enable_blend = GL.IsEnabled(GL::BLEND)
124
+ last_enable_cull_face = GL.IsEnabled(GL::CULL_FACE)
125
+ last_enable_depth_test = GL.IsEnabled(GL::DEPTH_TEST)
126
+ last_enable_stencil_test = GL.IsEnabled(GL::STENCIL_TEST)
127
+ last_enable_scissor_test = GL.IsEnabled(GL::SCISSOR_TEST)
129
128
 
130
129
  # Setup desired GL state
131
130
  vertex_array_object = ' ' * 4
132
- glGenVertexArrays(1, vertex_array_object)
131
+ GL.GenVertexArrays(1, vertex_array_object)
133
132
  vertex_array_object = vertex_array_object.unpack1('L')
134
133
  ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object)
135
134
 
@@ -145,10 +144,9 @@ module ImGui
145
144
  idx_buffer = cmd_list[:IdxBuffer][:Data] # const ImDrawIdx*
146
145
 
147
146
  # Upload vertex/index buffers
148
- glBufferData(GL_ARRAY_BUFFER, cmd_list[:VtxBuffer][:Size] * ImDrawVert.size, Fiddle::Pointer.new(cmd_list[:VtxBuffer][:Data]), GL_STREAM_DRAW)
147
+ GL.BufferData(GL::ARRAY_BUFFER, cmd_list[:VtxBuffer][:Size] * ImDrawVert.size, Fiddle::Pointer.new(cmd_list[:VtxBuffer][:Data]), GL::STREAM_DRAW)
149
148
  # 2 == ImDrawIdx(:ushort).size
150
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, cmd_list[:IdxBuffer][:Size] * 2, Fiddle::Pointer.new(cmd_list[:IdxBuffer][:Data]), GL_STREAM_DRAW) # [TODO] Refer ImGui::ImDrawIdx
151
- # glBufferData(GL_ELEMENT_ARRAY_BUFFER, cmd_list[:IdxBuffer][:Size] * ImDrawIdx.size, Fiddle::Pointer.new(cmd_list[:IdxBuffer][:Data]), GL_STREAM_DRAW)
149
+ GL.BufferData(GL::ELEMENT_ARRAY_BUFFER, cmd_list[:IdxBuffer][:Size] * 2, Fiddle::Pointer.new(cmd_list[:IdxBuffer][:Data]), GL::STREAM_DRAW) # [TODO] Refer ImGui::ImDrawIdx
152
150
 
153
151
  cmd_list[:CmdBuffer][:Size].times do |cmd_i|
154
152
  pcmd = ImDrawCmd.new(cmd_list[:CmdBuffer][:Data] + ImDrawCmd.size * cmd_i) # const ImDrawCmd*
@@ -172,19 +170,17 @@ module ImGui
172
170
 
173
171
  if (clip_rect[:x] < fb_width && clip_rect[:y] < fb_height && clip_rect[:z] >= 0.0 && clip_rect[:w] >= 0.0)
174
172
  # Apply scissor/clipping rectangle
175
- glScissor(clip_rect[:x].to_i, (fb_height - clip_rect[:w]).to_i, (clip_rect[:z] - clip_rect[:x]).to_i, (clip_rect[:w] - clip_rect[:y]).to_i)
173
+ GL.Scissor(clip_rect[:x].to_i, (fb_height - clip_rect[:w]).to_i, (clip_rect[:z] - clip_rect[:x]).to_i, (clip_rect[:w] - clip_rect[:y]).to_i)
176
174
 
177
175
  # Bind texture, Draw
178
- glBindTexture(GL_TEXTURE_2D, pcmd[:TextureId].address)
176
+ GL.BindTexture(GL::TEXTURE_2D, pcmd[:TextureId].address)
179
177
 
180
178
  if @@g_GlVersion >= 3200
181
179
  # 2 == ImDrawIdx(:ushort).size
182
- glDrawElementsBaseVertex(GL_TRIANGLES, pcmd[:ElemCount], GL_UNSIGNED_SHORT, Fiddle::Pointer.new(pcmd[:IdxOffset] * 2), pcmd[:VtxOffset])
183
- # glDrawElementsBaseVertex(GL_TRIANGLES, pcmd[:ElemCount], GL_UNSIGNED_SHORT, Fiddle::Pointer.new(pcmd[:IdxOffset] * ImDrawIdx.size), pcmd[:VtxOffset]) # [TODO] Refer ImGui::ImDrawIdx
180
+ GL.DrawElementsBaseVertex(GL::TRIANGLES, pcmd[:ElemCount], GL::UNSIGNED_SHORT, Fiddle::Pointer.new(pcmd[:IdxOffset] * 2), pcmd[:VtxOffset])
184
181
  else
185
182
  # 2 == ImDrawIdx(:ushort).size
186
- glDrawElements(GL_TRIANGLES, pcmd[:ElemCount], GL_UNSIGNED_SHORT, Fiddle::Pointer.new(pcmd[:IdxOffset] * 2))
187
- # glDrawElements(GL_TRIANGLES, pcmd[:ElemCount], GL_UNSIGNED_SHORT, Fiddle::Pointer.new(pcmd[:IdxOffset] * ImDrawIdx.size)) # [TODO] Refer ImGui::ImDrawIdx
183
+ GL.DrawElements(GL::TRIANGLES, pcmd[:ElemCount], GL::UNSIGNED_SHORT, Fiddle::Pointer.new(pcmd[:IdxOffset] * 2))
188
184
  end
189
185
  end
190
186
 
@@ -194,29 +190,29 @@ module ImGui
194
190
  end
195
191
 
196
192
  # Destroy the temporary VAO
197
- glDeleteVertexArrays(1, [vertex_array_object].pack('L'))
193
+ GL.DeleteVertexArrays(1, [vertex_array_object].pack('L'))
198
194
 
199
195
  # Restore modified GL state
200
- glUseProgram(last_program.unpack1('L'))
201
- glBindTexture(GL_TEXTURE_2D, last_texture.unpack1('L'))
202
- glBindSampler(0, last_sampler.unpack1('L'))
203
- glActiveTexture(last_active_texture.unpack1('L'))
204
- glBindVertexArray(last_vertex_array_object.unpack1('L'))
205
- glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer.unpack1('L'))
206
- glBlendEquationSeparate(last_blend_equation_rgb.unpack1('L'), last_blend_equation_alpha.unpack1('L'))
207
-
208
- if last_enable_blend then glEnable(GL_BLEND) else glDisable(GL_BLEND) end
209
- if last_enable_cull_face then glEnable(GL_CULL_FACE) else glDisable(GL_CULL_FACE) end
210
- if last_enable_depth_test then glEnable(GL_DEPTH_TEST) else glDisable(GL_DEPTH_TEST) end
211
- if last_enable_stencil_test then glEnable(GL_STENCIL_TEST) else glDisable(GL_STENCIL_TEST) end
212
- if last_enable_scissor_test then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST) end
196
+ GL.UseProgram(last_program.unpack1('L'))
197
+ GL.BindTexture(GL::TEXTURE_2D, last_texture.unpack1('L'))
198
+ GL.BindSampler(0, last_sampler.unpack1('L'))
199
+ GL.ActiveTexture(last_active_texture.unpack1('L'))
200
+ GL.BindVertexArray(last_vertex_array_object.unpack1('L'))
201
+ GL.BindBuffer(GL::ARRAY_BUFFER, last_array_buffer.unpack1('L'))
202
+ GL.BlendEquationSeparate(last_blend_equation_rgb.unpack1('L'), last_blend_equation_alpha.unpack1('L'))
203
+
204
+ if last_enable_blend then GL.Enable(GL::BLEND) else GL.Disable(GL::BLEND) end
205
+ if last_enable_cull_face then GL.Enable(GL::CULL_FACE) else GL.Disable(GL::CULL_FACE) end
206
+ if last_enable_depth_test then GL.Enable(GL::DEPTH_TEST) else GL.Disable(GL::DEPTH_TEST) end
207
+ if last_enable_stencil_test then GL.Enable(GL::STENCIL_TEST) else GL.Disable(GL::STENCIL_TEST) end
208
+ if last_enable_scissor_test then GL.Enable(GL::SCISSOR_TEST) else GL.Disable(GL::SCISSOR_TEST) end
213
209
 
214
210
  last_polygon_mode = last_polygon_mode.unpack('L2')
215
- glPolygonMode(GL_FRONT_AND_BACK, last_polygon_mode[0])
211
+ GL.PolygonMode(GL::FRONT_AND_BACK, last_polygon_mode[0])
216
212
  last_viewport = last_viewport.unpack('L4')
217
- glViewport(last_viewport[0], last_viewport[1], last_viewport[2], last_viewport[3])
213
+ GL.Viewport(last_viewport[0], last_viewport[1], last_viewport[2], last_viewport[3])
218
214
  last_scissor_box = last_scissor_box.unpack('L4')
219
- glScissor(last_scissor_box[0], last_scissor_box[1], last_scissor_box[2], last_scissor_box[3])
215
+ GL.Scissor(last_scissor_box[0], last_scissor_box[1], last_scissor_box[2], last_scissor_box[3])
220
216
 
221
217
  end
222
218
 
@@ -224,18 +220,18 @@ module ImGui
224
220
 
225
221
  def self.ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object)
226
222
  # Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill
227
- glEnable(GL_BLEND)
228
- glBlendEquation(GL_FUNC_ADD)
229
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
230
- glDisable(GL_CULL_FACE)
231
- glDisable(GL_DEPTH_TEST)
232
- glDisable(GL_STENCIL_TEST)
233
- glEnable(GL_SCISSOR_TEST)
234
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) # GL_POLYGON_MODE
223
+ GL.Enable(GL::BLEND)
224
+ GL.BlendEquation(GL::FUNC_ADD)
225
+ GL.BlendFuncSeparate(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA, GL::ONE, GL::ONE_MINUS_SRC_ALPHA)
226
+ GL.Disable(GL::CULL_FACE)
227
+ GL.Disable(GL::DEPTH_TEST)
228
+ GL.Disable(GL::STENCIL_TEST)
229
+ GL.Enable(GL::SCISSOR_TEST)
230
+ GL.PolygonMode(GL::FRONT_AND_BACK, GL::FILL) # GL::POLYGON_MODE
235
231
 
236
232
  # Setup viewport, orthographic projection matrix
237
233
  # Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
238
- glViewport(0, 0, fb_width, fb_height)
234
+ GL.Viewport(0, 0, fb_width, fb_height)
239
235
  l = draw_data[:DisplayPos][:x]
240
236
  r = draw_data[:DisplayPos][:x] + draw_data[:DisplaySize][:x]
241
237
  t = draw_data[:DisplayPos][:y]
@@ -246,25 +242,25 @@ module ImGui
246
242
  0.0, 0.0, -1.0, 0.0,
247
243
  (r+l)/(l-r), (t+b)/(b-t), 0.0, 1.0,
248
244
  ]
249
- glUseProgram(@@g_ShaderHandle)
250
- glUniform1i(@@g_AttribLocationTex, 0)
251
- glUniformMatrix4fv(@@g_AttribLocationProjMtx, 1, GL_FALSE, ortho_projection.pack('F16'))
252
- # GL_SAMPLER_BINDING
253
- glBindSampler(0, 0) # We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
245
+ GL.UseProgram(@@g_ShaderHandle)
246
+ GL.Uniform1i(@@g_AttribLocationTex, 0)
247
+ GL.UniformMatrix4fv(@@g_AttribLocationProjMtx, 1, GL::FALSE, ortho_projection.pack('F16'))
248
+ # GL::SAMPLER_BINDING
249
+ GL.BindSampler(0, 0) # We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
254
250
 
255
- glBindVertexArray(vertex_array_object)
251
+ GL.BindVertexArray(vertex_array_object)
256
252
 
257
253
  # Bind vertex/index buffers and setup attributes for ImDrawVert
258
- glBindBuffer(GL_ARRAY_BUFFER, @@g_VboHandle)
259
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, @@g_ElementsHandle)
254
+ GL.BindBuffer(GL::ARRAY_BUFFER, @@g_VboHandle)
255
+ GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @@g_ElementsHandle)
260
256
 
261
- glEnableVertexAttribArray(@@g_AttribLocationVtxPos)
262
- glEnableVertexAttribArray(@@g_AttribLocationVtxUV)
263
- glEnableVertexAttribArray(@@g_AttribLocationVtxColor)
257
+ GL.EnableVertexAttribArray(@@g_AttribLocationVtxPos)
258
+ GL.EnableVertexAttribArray(@@g_AttribLocationVtxUV)
259
+ GL.EnableVertexAttribArray(@@g_AttribLocationVtxColor)
264
260
 
265
- glVertexAttribPointer(@@g_AttribLocationVtxPos, 2, GL_FLOAT, GL_FALSE, ImDrawVert.size, ImDrawVert.offset_of(:pos))
266
- glVertexAttribPointer(@@g_AttribLocationVtxUV, 2, GL_FLOAT, GL_FALSE, ImDrawVert.size, ImDrawVert.offset_of(:uv))
267
- glVertexAttribPointer(@@g_AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, ImDrawVert.size, ImDrawVert.offset_of(:col))
261
+ GL.VertexAttribPointer(@@g_AttribLocationVtxPos, 2, GL::FLOAT, GL::FALSE, ImDrawVert.size, ImDrawVert.offset_of(:pos))
262
+ GL.VertexAttribPointer(@@g_AttribLocationVtxUV, 2, GL::FLOAT, GL::FALSE, ImDrawVert.size, ImDrawVert.offset_of(:uv))
263
+ GL.VertexAttribPointer(@@g_AttribLocationVtxColor, 4, GL::UNSIGNED_BYTE, GL::TRUE, ImDrawVert.size, ImDrawVert.offset_of(:col))
268
264
 
269
265
  end
270
266
 
@@ -279,31 +275,31 @@ module ImGui
279
275
  # Upload texture to graphics system
280
276
  last_texture = ' ' * 4
281
277
  @@g_FontTexture = ' ' * 4
282
- glGetIntegerv(GL_TEXTURE_BINDING_2D, last_texture)
283
- glGenTextures(1, @@g_FontTexture)
284
- glBindTexture(GL_TEXTURE_2D, @@g_FontTexture.unpack1('L'))
285
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
286
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
287
- glPixelStorei(GL_UNPACK_ROW_LENGTH, 0)
278
+ GL.GetIntegerv(GL::TEXTURE_BINDING_2D, last_texture)
279
+ GL.GenTextures(1, @@g_FontTexture)
280
+ GL.BindTexture(GL::TEXTURE_2D, @@g_FontTexture.unpack1('L'))
281
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::LINEAR)
282
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::LINEAR)
283
+ GL.PixelStorei(GL::UNPACK_ROW_LENGTH, 0)
288
284
  # Ruby/FFI <-> Fiddle pointer exchange
289
285
  # p pixels
290
286
  # p pixels.read_pointer
291
287
  # p pixels.read_pointer.address.to_s(16)
292
288
  pixels_ptr = Fiddle::Pointer.new(pixels.read_pointer.address)
293
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width.read_uint, height.read_uint, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels_ptr)
289
+ GL.TexImage2D(GL::TEXTURE_2D, 0, GL::RGBA, width.read_uint, height.read_uint, 0, GL::RGBA, GL::UNSIGNED_BYTE, pixels_ptr)
294
290
 
295
291
  # Store our identifier
296
292
  io[:Fonts][:TexID] = @@g_FontTexture.unpack1('L')
297
293
 
298
294
  # Restore state
299
- glBindTexture(GL_TEXTURE_2D, last_texture.unpack1('L'))
295
+ GL.BindTexture(GL::TEXTURE_2D, last_texture.unpack1('L'))
300
296
 
301
297
  return true
302
298
  end
303
299
 
304
300
  def self.ImplOpenGL3_DestroyFontsTexture()
305
301
  if @@g_FontTexture != 0
306
- glDeleteTextures(1, @@g_FontTexture)
302
+ GL.DeleteTextures(1, @@g_FontTexture)
307
303
  io = ImGuiIO.new(ImGui::GetIO())
308
304
  io[:Fonts][:TexID] = 0
309
305
  @@g_FontTexture = 0
@@ -313,13 +309,13 @@ module ImGui
313
309
  def self.ImplOpenGL3_CreateDeviceObjects()
314
310
  # Backup GL state
315
311
  last_texture, last_array_buffer = ' ' * 4, ' ' * 4
316
- glGetIntegerv(GL_TEXTURE_BINDING_2D, last_texture)
317
- glGetIntegerv(GL_ARRAY_BUFFER_BINDING, last_array_buffer)
312
+ GL.GetIntegerv(GL::TEXTURE_BINDING_2D, last_texture)
313
+ GL.GetIntegerv(GL::ARRAY_BUFFER_BINDING, last_array_buffer)
318
314
  last_texture = last_texture.unpack1('L')
319
315
  last_array_buffer = last_array_buffer.unpack1('L')
320
316
 
321
317
  last_vertex_array = ' ' * 4
322
- glGetIntegerv(GL_VERTEX_ARRAY_BINDING, last_vertex_array)
318
+ GL.GetIntegerv(GL::VERTEX_ARRAY_BINDING, last_vertex_array)
323
319
  last_vertex_array = last_vertex_array.unpack1('L')
324
320
 
325
321
  glsl_version = @@g_GlslVersionString.split[1].to_i # == scanf(@@g_GlslVersionString, "#version %d")
@@ -386,7 +382,7 @@ module ImGui
386
382
  SRC
387
383
 
388
384
  fragment_shader_glsl_120 = <<-'SRC'
389
- #ifdef GL_ES
385
+ #ifdef GL::ES
390
386
  precision mediump float;
391
387
  #endif
392
388
  uniform sampler2D Texture;
@@ -443,67 +439,67 @@ module ImGui
443
439
  end
444
440
 
445
441
  vertex_shader.prepend(@@g_GlslVersionString + "\n")
446
- vert_handle = glCreateShader(GL_VERTEX_SHADER)
447
- glShaderSource(vert_handle, 1, [vertex_shader].pack('p'), nil)
448
- glCompileShader(vert_handle)
442
+ vert_handle = GL.CreateShader(GL::VERTEX_SHADER)
443
+ GL.ShaderSource(vert_handle, 1, [vertex_shader].pack('p'), nil)
444
+ GL.CompileShader(vert_handle)
449
445
  PrintShaderCompileStatus(vert_handle)
450
446
 
451
447
  fragment_shader.prepend(@@g_GlslVersionString + "\n")
452
- frag_handle = glCreateShader(GL_FRAGMENT_SHADER)
453
- glShaderSource(frag_handle, 1, [fragment_shader].pack('p'), [fragment_shader.size].pack('I'))
454
- glCompileShader(frag_handle)
448
+ frag_handle = GL.CreateShader(GL::FRAGMENT_SHADER)
449
+ GL.ShaderSource(frag_handle, 1, [fragment_shader].pack('p'), [fragment_shader.size].pack('I'))
450
+ GL.CompileShader(frag_handle)
455
451
  PrintShaderCompileStatus(frag_handle)
456
452
 
457
- @@g_ShaderHandle = glCreateProgram()
458
- glAttachShader(@@g_ShaderHandle, vert_handle)
459
- glAttachShader(@@g_ShaderHandle, frag_handle)
460
- glLinkProgram(@@g_ShaderHandle)
453
+ @@g_ShaderHandle = GL.CreateProgram()
454
+ GL.AttachShader(@@g_ShaderHandle, vert_handle)
455
+ GL.AttachShader(@@g_ShaderHandle, frag_handle)
456
+ GL.LinkProgram(@@g_ShaderHandle)
461
457
  PrintProgramLinkStatus(@@g_ShaderHandle)
462
458
 
463
- glDetachShader(@@g_ShaderHandle, vert_handle)
464
- glDetachShader(@@g_ShaderHandle, frag_handle)
465
- glDeleteShader(vert_handle)
466
- glDeleteShader(frag_handle)
459
+ GL.DetachShader(@@g_ShaderHandle, vert_handle)
460
+ GL.DetachShader(@@g_ShaderHandle, frag_handle)
461
+ GL.DeleteShader(vert_handle)
462
+ GL.DeleteShader(frag_handle)
467
463
 
468
- @@g_AttribLocationTex = glGetUniformLocation(@@g_ShaderHandle, "Texture")
469
- @@g_AttribLocationProjMtx = glGetUniformLocation(@@g_ShaderHandle, "ProjMtx")
464
+ @@g_AttribLocationTex = GL.GetUniformLocation(@@g_ShaderHandle, "Texture")
465
+ @@g_AttribLocationProjMtx = GL.GetUniformLocation(@@g_ShaderHandle, "ProjMtx")
470
466
 
471
- @@g_AttribLocationVtxPos = glGetAttribLocation(@@g_ShaderHandle, "Position")
472
- @@g_AttribLocationVtxUV = glGetAttribLocation(@@g_ShaderHandle, "UV")
473
- @@g_AttribLocationVtxColor = glGetAttribLocation(@@g_ShaderHandle, "Color")
467
+ @@g_AttribLocationVtxPos = GL.GetAttribLocation(@@g_ShaderHandle, "Position")
468
+ @@g_AttribLocationVtxUV = GL.GetAttribLocation(@@g_ShaderHandle, "UV")
469
+ @@g_AttribLocationVtxColor = GL.GetAttribLocation(@@g_ShaderHandle, "Color")
474
470
 
475
471
  # Create buffers
476
472
  posBuf = ' ' * 4
477
- glGenBuffers(1, posBuf)
478
- glBindBuffer(GL_ARRAY_BUFFER, posBuf.unpack('L')[0])
473
+ GL.GenBuffers(1, posBuf)
474
+ GL.BindBuffer(GL::ARRAY_BUFFER, posBuf.unpack('L')[0])
479
475
 
480
476
  @@g_VboHandle, @@g_ElementsHandle = ' ' * 4, ' ' * 4
481
- glGenBuffers(1, @@g_VboHandle)
482
- glGenBuffers(1, @@g_ElementsHandle)
477
+ GL.GenBuffers(1, @@g_VboHandle)
478
+ GL.GenBuffers(1, @@g_ElementsHandle)
483
479
  @@g_VboHandle = @@g_VboHandle.unpack1('L')
484
480
  @@g_ElementsHandle = @@g_ElementsHandle.unpack1('L')
485
481
 
486
482
  ImplOpenGL3_CreateFontsTexture()
487
483
 
488
484
  # Restore modified GL state
489
- glBindTexture(GL_TEXTURE_2D, last_texture)
490
- glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer)
491
- glBindVertexArray(last_vertex_array)
485
+ GL.BindTexture(GL::TEXTURE_2D, last_texture)
486
+ GL.BindBuffer(GL::ARRAY_BUFFER, last_array_buffer)
487
+ GL.BindVertexArray(last_vertex_array)
492
488
 
493
489
  return true
494
490
  end
495
491
 
496
492
  def self.ImplOpenGL3_DestroyDeviceObjects()
497
493
  if @@g_VboHandle != 0
498
- glDeleteBuffers(1, [@@g_VboHandle].pack('L'))
494
+ GL.DeleteBuffers(1, [@@g_VboHandle].pack('L'))
499
495
  @@g_VboHandle = 0
500
496
  end
501
497
  if @@g_ElementsHandle != 0
502
- glDeleteBuffers(1, [@@g_ElementsHandle].pack('L'))
498
+ GL.DeleteBuffers(1, [@@g_ElementsHandle].pack('L'))
503
499
  @@g_ElementsHandle = 0
504
500
  end
505
501
  if @@g_ShaderHandle != 0
506
- glDeleteProgram(@@g_ShaderHandle)
502
+ GL.DeleteProgram(@@g_ShaderHandle)
507
503
  @@g_ShaderHandle = 0
508
504
  end
509
505