diff options
Diffstat (limited to 'demo/fancy')
-rw-r--r-- | demo/fancy/honey.lua | 130 |
1 files changed, 65 insertions, 65 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) |