diff options
author | sanine <sanine.not@pm.me> | 2023-02-19 19:03:51 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-02-19 19:03:51 -0600 |
commit | fb0eb6abac31ab1945a5b32e68824c9f9420d71f (patch) | |
tree | b414bb9f93af85755df553d003ed88afc24cef50 /demo | |
parent | bc4af3b47260ee0f79343303b135d1ea32cde4d4 (diff) |
refactor: bind (nearly) all nvg functions
Diffstat (limited to 'demo')
-rw-r--r-- | demo/fancy/honey.lua | 130 | ||||
-rw-r--r-- | demo/vector/main.lua | 4 |
2 files changed, 67 insertions, 67 deletions
diff --git a/demo/fancy/honey.lua b/demo/fancy/honey.lua index 75f0a99..d5b6ad0 100644 --- a/demo/fancy/honey.lua +++ b/demo/fancy/honey.lua @@ -121,45 +121,45 @@ gl.EnableVertexAttribArray(1) --===== load mesh from file =====-- -local scene = honey.import.importFile('suzanne.dae') -local mesh = scene.meshes[1] -local suzanne = {} -suzanne.vertices = {} -print('mesh.vertices', #mesh.vertices) -for i=1,#mesh.vertices do - local position = mesh.vertices[i] - local uv = mesh.uvs[1][i] - table.insert(suzanne.vertices, position.x) - table.insert(suzanne.vertices, position.y) - table.insert(suzanne.vertices, position.z) - table.insert(suzanne.vertices, uv.x) - table.insert(suzanne.vertices, uv.y) -end -suzanne.indices = {} -for _, face in ipairs(mesh.faces) do - assert(#face == 3) - for _, i in ipairs(face) do - table.insert(suzanne.indices, i) - end -end -print('mesh.faces', #mesh.faces) -print('suzanne.indices', #suzanne.indices) - -suzanne.vertexArr = gl.GenVertexArrays() -suzanne.vertexBuf = gl.GenBuffers() -suzanne.elementBuf = gl.GenBuffers() - -gl.BindVertexArray(suzanne.vertexArr) -gl.BindBuffer(gl.ARRAY_BUFFER, suzanne.vertexBuf) -gl.BufferData(gl.ARRAY_BUFFER, gl.FLOAT, suzanne.vertices, gl.STATIC_DRAW) - -gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, suzanne.elementBuf) -gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, gl.UNSIGNED_INT, suzanne.indices, gl.STATIC_DRAW) - -gl.VertexAttribPointer(0, 3, false, 5, 0) -gl.EnableVertexAttribArray(0) -gl.VertexAttribPointer(1, 2, false, 5, 3) -gl.EnableVertexAttribArray(1) +-- local scene = honey.import.importFile('suzanne.dae') +-- local mesh = scene.meshes[1] +-- local suzanne = {} +-- suzanne.vertices = {} +-- print('mesh.vertices', #mesh.vertices) +-- for i=1,#mesh.vertices do +-- local position = mesh.vertices[i] +-- local uv = mesh.uvs[1][i] +-- table.insert(suzanne.vertices, position.x) +-- table.insert(suzanne.vertices, position.y) +-- table.insert(suzanne.vertices, position.z) +-- table.insert(suzanne.vertices, uv.x) +-- table.insert(suzanne.vertices, uv.y) +-- end +-- suzanne.indices = {} +-- for _, face in ipairs(mesh.faces) do +-- assert(#face == 3) +-- for _, i in ipairs(face) do +-- table.insert(suzanne.indices, i) +-- end +-- end +-- print('mesh.faces', #mesh.faces) +-- print('suzanne.indices', #suzanne.indices) +-- +-- suzanne.vertexArr = gl.GenVertexArrays() +-- suzanne.vertexBuf = gl.GenBuffers() +-- suzanne.elementBuf = gl.GenBuffers() +-- +-- gl.BindVertexArray(suzanne.vertexArr) +-- gl.BindBuffer(gl.ARRAY_BUFFER, suzanne.vertexBuf) +-- gl.BufferData(gl.ARRAY_BUFFER, gl.FLOAT, suzanne.vertices, gl.STATIC_DRAW) +-- +-- gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, suzanne.elementBuf) +-- gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, gl.UNSIGNED_INT, suzanne.indices, gl.STATIC_DRAW) +-- +-- gl.VertexAttribPointer(0, 3, false, 5, 0) +-- gl.EnableVertexAttribArray(0) +-- gl.VertexAttribPointer(1, 2, false, 5, 3) +-- gl.EnableVertexAttribArray(1) --====== load texture ======-- @@ -190,26 +190,26 @@ gl.Uniform1i(gl.GetUniformLocation(shader, 'ourTexture'), 0) --===== generate cairo texture =====-- -local image = honey.image -local surface = image.surface_create(image.FORMAT_ARGB32, 512, 512) -local cr = image.context_create(surface) -image.context_select_font_face(cr, "sans-serif", image.FONT_SLANT_NORMAL, image.FONT_WEIGHT_NORMAL) -image.context_set_font_size(cr, 32) -image.context_set_source_rgb(cr, 1, 0, 0) -image.context_move_to(cr, 100, 100) -image.context_show_text(cr, "hello, world!") -local data = image.surface_get_data(surface) -gl.BindTexture(gl.TEXTURE_2D, texture) -gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_SWIZZLE_R, gl.BLUE) -gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_SWIZZLE_B, gl.RED) ---gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_SWIZZLE_A, gl.RED) -gl.TexImage2D( - gl.TEXTURE_2D, 0, - gl.RGB, width, height, - gl.RGBA, gl.UNSIGNED_BYTE, - data -) -gl.GenerateMipmap(gl.TEXTURE_2D) +-- local image = honey.image +-- local surface = image.surface_create(image.FORMAT_ARGB32, 512, 512) +-- local cr = image.context_create(surface) +-- image.context_select_font_face(cr, "sans-serif", image.FONT_SLANT_NORMAL, image.FONT_WEIGHT_NORMAL) +-- image.context_set_font_size(cr, 32) +-- image.context_set_source_rgb(cr, 1, 0, 0) +-- image.context_move_to(cr, 100, 100) +-- image.context_show_text(cr, "hello, world!") +-- local data = image.surface_get_data(surface) +-- gl.BindTexture(gl.TEXTURE_2D, texture) +-- gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_SWIZZLE_R, gl.BLUE) +-- gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_SWIZZLE_B, gl.RED) +-- --gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_SWIZZLE_A, gl.RED) +-- gl.TexImage2D( +-- gl.TEXTURE_2D, 0, +-- gl.RGB, width, height, +-- gl.RGBA, gl.UNSIGNED_BYTE, +-- data +-- ) +-- gl.GenerateMipmap(gl.TEXTURE_2D) --====== matrices ======-- @@ -264,11 +264,11 @@ while not window.shouldClose(w) do gl.UniformMatrix4fv(viewL, false, view) gl.UniformMatrix4fv(projectionL, false, projection) - --gl.BindVertexArray(vertexArray) - --gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, 0) + gl.BindVertexArray(vertexArray) + gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, 0) - gl.BindVertexArray(suzanne.vertexArr) - gl.DrawElements(gl.TRIANGLES, 3*#mesh.faces, gl.UNSIGNED_INT, 0) + --gl.BindVertexArray(suzanne.vertexArr) + --gl.DrawElements(gl.TRIANGLES, 3*#mesh.faces, gl.UNSIGNED_INT, 0) window.swapBuffers(w) window.pollEvents() @@ -279,5 +279,5 @@ end window.destroy(w) gl.Terminate() honey.audio.engine_uninit(engine) -image.surface_destroy(surface) -image.context_destroy(cr) +--image.surface_destroy(surface) +--image.context_destroy(cr) diff --git a/demo/vector/main.lua b/demo/vector/main.lua index 595131b..fda4bc8 100644 --- a/demo/vector/main.lua +++ b/demo/vector/main.lua @@ -7,7 +7,7 @@ local nvg = honey.nvg local vg function honey.init() - vg = nvg.Context() + vg = nvg.CreateContext() end @@ -31,7 +31,7 @@ end function honey.draw() nvg.BeginFrame(vg, 640, 480, 1.0) nvg.StrokeWidth(vg, 20) - nvg.StrokeColor(vg, 1, 0, 0, 1) + nvg.StrokeColor(vg, nvg.RGB(1, 0, 0)) local w = 640 local h = 480 |