From b87e61aa4e6008756bd8876eb1106f1d7662f551 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 26 Jun 2019 17:49:50 +0200 Subject: [PATCH] make lots of functions public --- gg/gg.v | 8 +++---- gl/gl.v | 2 +- glfw/glfw.v | 68 ++++++++++++++++++++++++++--------------------------- glm/glm.v | 14 +++++------ math/math.v | 50 +++++++++++++++++++-------------------- stbi/stbi.v | 8 +++---- 6 files changed, 75 insertions(+), 75 deletions(-) diff --git a/gg/gg.v b/gg/gg.v index 08b40a635d..cbf8b1c98a 100644 --- a/gg/gg.v +++ b/gg/gg.v @@ -47,7 +47,7 @@ struct Character { advance u32 } -fn init() { +pub fn init() { println(gl.TEXT_VERT) gl.init_glad() } @@ -198,7 +198,7 @@ pub fn (ctx &GG) draw_triangle_tex(x1, y1, x2, y2, x3, y3 f32, c gx.Color) { gl.draw_elements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0) } -fn (ctx &GG) draw_rect(x, y, w, h f32, c gx.Color) { +pub fn (ctx &GG) draw_rect(x, y, w, h f32, c gx.Color) { // println('gg.draw_rect($x,$y,$w,$h)') // wrong order // // ctx.draw_triangle(x, y, x + w, y, x + w, y + h, c) @@ -231,7 +231,7 @@ fn (ctx mut GG) init_rect_vao() { gl.set_ebo(ebo, indices, GL_STATIC_DRAW) } */ -fn (ctx &GG) draw_rect2(x, y, w, h f32, c gx.Color) { +pub fn (ctx &GG) draw_rect2(x, y, w, h f32, c gx.Color) { C.glDeleteBuffers(1, &ctx.VAO) C.glDeleteBuffers(1, &ctx.VBO) ctx.shader.use() @@ -305,7 +305,7 @@ fn ft_load_char(_face Face, code i64) Character { return ch } -fn new_context_text(cfg Cfg, scale int) *GG { +pub fn new_context_text(cfg Cfg, scale int) *GG { // Can only have text in ortho mode if !cfg.use_ortho { return &GG{text_ctx: 0} diff --git a/gl/gl.v b/gl/gl.v index 9fcffc3aaf..454c8f3d8b 100644 --- a/gl/gl.v +++ b/gl/gl.v @@ -20,7 +20,7 @@ import const ( #include "glad.h" #include "glad.c" -fn init_glad() { +pub fn init_glad() { ok := C.gladLoadGL() if !ok { println('Failed to initialize glad OpenGL context') diff --git a/glfw/glfw.v b/glfw/glfw.v index b235d4fbbc..74cc27940a 100644 --- a/glfw/glfw.v +++ b/glfw/glfw.v @@ -124,10 +124,10 @@ struct Pos { y int } -// type clickfn fn (window * GLFWwindow, button, action, mods int) -type clickfn fn (window voidptr, button, action, mods int) +// type clickpub fn pub fn (window * GLFWwindow, button, action, mods int) +type clickpubfn fn (window voidptr, button, action, mods int) -fn init() { +pub fn init() { C.glfwInit() # glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); # glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); @@ -135,17 +135,17 @@ fn init() { # glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); } -// fn mouse_move(w * GLFWwindow, x, y double) { -fn mouse_move(w voidptr, x, y f64) { +// pub fn mouse_move(w * GLFWwindow, x, y double) { +pub fn mouse_move(w voidptr, x, y f64) { // #printf("%f : %f => %d \n", x,y); } -// fn create_window(title string, w, h int) * Window { -fn window_hint(key, val int) { +// pub fn create_window(title string, w, h int) * Window { +pub fn window_hint(key, val int) { C.glfwWindowHint(key, val) } -fn create_window(c WinCfg) *Window { +pub fn create_window(c WinCfg) *Window { // TODO why i need this in stdlib? extern? // # if (!gconst_init) { init_consts(); gconst_init = 1; } // ChatsRepo @@ -180,92 +180,92 @@ fn create_window(c WinCfg) *Window { return window } -fn (w &Window) set_title(title string) { +pub fn (w &Window) set_title(title string) { C.glfwSetWindowTitle(w.data, title.str) } -fn (w &Window) make_context_current() { +pub fn (w &Window) make_context_current() { // ChatsRepo kkk := 0 // println('making context current' ) C.glfwMakeContextCurrent(w.data) } -fn swap_interval(interval int) { +pub fn swap_interval(interval int) { C.glfwSwapInterval(interval) } -fn wait_events() { +pub fn wait_events() { C.glfwWaitEvents() } -fn poll_events() { +pub fn poll_events() { C.glfwPollEvents() } -fn (w &Window) should_close() bool { +pub fn (w &Window) should_close() bool { // ChatsRepo return C.glfwWindowShouldClose(w.data) } -fn (w &Window) swap_buffers() { +pub fn (w &Window) swap_buffers() { C.glfwSwapBuffers(w.data) } -fn (w mut Window) onmousemove(cb voidptr) { +pub fn (w mut Window) onmousemove(cb voidptr) { C.glfwSetCursorPosCallback(w.data, cb) } -fn (w mut Window) set_mouse_button_callback(cb voidptr) { +pub fn (w mut Window) set_mouse_button_callback(cb voidptr) { C.glfwSetMouseButtonCallback(w.data, cb) } -fn (w mut Window) on_click(cb voidptr) { +pub fn (w mut Window) on_click(cb voidptr) { C.glfwSetMouseButtonCallback(w.data, cb) } -fn (w &Window) set_scroll_callback(cb voidptr) { +pub fn (w &Window) set_scroll_callback(cb voidptr) { C.glfwSetScrollCallback(w.data, cb) } -fn (w &Window) on_scroll(cb voidptr) { +pub fn (w &Window) on_scroll(cb voidptr) { C.glfwSetScrollCallback(w.data, cb) } -fn post_empty_event() { +pub fn post_empty_event() { C.glfwPostEmptyEvent() } -fn (w mut Window) onkeydown(cb voidptr) { +pub fn (w mut Window) onkeydown(cb voidptr) { C.glfwSetKeyCallback(w.data, cb) } -fn (w mut Window) onchar(cb voidptr) { +pub fn (w mut Window) onchar(cb voidptr) { C.glfwSetCharModsCallback(w.data, cb) } -fn get_time() f64 { +pub fn get_time() f64 { return C.glfwGetTime() } -fn key_pressed(wnd voidptr, key int) bool { +pub fn key_pressed(wnd voidptr, key int) bool { # return glfwGetKey(wnd, key) == GLFW_PRESS; return false } // TODO not mut -fn (w mut Window) get_clipboard_text() string { +pub fn (w mut Window) get_clipboard_text() string { return tos2(C.glfwGetClipboardString(w.data)) // # char *c = glfwGetClipboardString(w->data); // # return tos_no_len(c); // return '' } -fn (w &Window) set_clipboard_text(s string) { +pub fn (w &Window) set_clipboard_text(s string) { C.glfwSetClipboardString(w.data, s.str) } -fn (w &Window) get_cursor_pos() Pos { +pub fn (w &Window) get_cursor_pos() Pos { x := f64(0) y := f64(0) C.glfwGetCursorPos(w.data, &x, &y) @@ -275,17 +275,17 @@ fn (w &Window) get_cursor_pos() Pos { } } -fn (w &Window) user_ptr() voidptr { +pub fn (w &Window) user_ptr() voidptr { return C.glfwGetWindowUserPointer(w.data) } -fn (w &Window) set_user_ptr(ptr voidptr) { +pub fn (w &Window) set_user_ptr(ptr voidptr) { C.glfwSetWindowUserPointer(w.data, ptr) } -fn C.glfwGetVideoMode() C.GLFWvideoMode +pub fn C.glfwGetVideoMode() C.GLFWvideoMode -fn get_monitor_size() Size { +pub fn get_monitor_size() Size { # GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // window_width = mode->width; // window_height = mode->height; @@ -297,11 +297,11 @@ fn get_monitor_size() Size { return res } -fn (size Size) str() string { +pub fn (size Size) str() string { return '{$size.width, $size.height}' } -fn get_window_user_pointer(gwnd voidptr) voidptr { +pub fn get_window_user_pointer(gwnd voidptr) voidptr { return C.glfwGetWindowUserPointer(gwnd) } diff --git a/glm/glm.v b/glm/glm.v index 72616fcd71..912da5608c 100644 --- a/glm/glm.v +++ b/glm/glm.v @@ -134,7 +134,7 @@ fn f32_calloc(n int) *f32 { return *f32(calloc(n * sizeof(f32))) } // fn translate(vec Vec3) *f32 { -fn translate(m Mat4, v Vec3) Mat4 { +pub fn translate(m Mat4, v Vec3) Mat4 { // # return glm__mat4(myglm_translate(vec.x,vec.y,vec.z) ); a := m.data mut out := f32_calloc(16) @@ -161,7 +161,7 @@ fn normalize(vec Vec3) Vec3 { } */ // https://github.com/g-truc/glm/blob/0ceb2b755fb155d593854aefe3e45d416ce153a4/glm/ext/matrix_clip_space.inl -fn ortho(left, right, bottom, top f32) Mat4 { +pub fn ortho(left, right, bottom, top f32) Mat4 { println('glm ortho($left, $right, $bottom, $top)') // mat<4, 4, T, defaultp> Result(static_cast(1)); n := 16 @@ -176,7 +176,7 @@ fn ortho(left, right, bottom, top f32) Mat4 { } // fn scale(a *f32, v Vec3) *f32 { -fn scale(m Mat4, v Vec3) Mat4 { +pub fn scale(m Mat4, v Vec3) Mat4 { a := m.data mut out := f32_calloc(16) x := v.x @@ -202,7 +202,7 @@ fn scale(m Mat4, v Vec3) Mat4 { } // fn rotate_z(a *f32, rad f32) *f32 { -fn rotate_z(m Mat4, rad f32) Mat4 { +pub fn rotate_z(m Mat4, rad f32) Mat4 { a := m.data mut out := f32_calloc(16) s := math.sin(rad) @@ -235,7 +235,7 @@ fn rotate_z(m Mat4, rad f32) Mat4 { return mat4(out) } -fn identity() Mat4 { +pub fn identity() Mat4 { // 1 0 0 0 // 0 1 0 0 // 0 0 1 0 @@ -250,7 +250,7 @@ fn identity() Mat4 { } // returns *f32 without allocation -fn identity2(res *f32) { +pub fn identity2(res *f32) { res[0] = 1 res[5] = 1 res[10] = 1 @@ -261,7 +261,7 @@ fn identity2(res *f32) { // # gl__Shader_set_mat4(shader, tos2("projection"), f) ; } -fn identity3() []f32 { +pub fn identity3() []f32 { res := [1.0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, diff --git a/math/math.v b/math/math.v index 81f246f725..d5e9c6745e 100644 --- a/math/math.v +++ b/math/math.v @@ -20,111 +20,111 @@ const ( Log10E = 1.0 / Ln10 ) -fn abs(a f64) f64 { +pub fn abs(a f64) f64 { if a < 0 { return -a } return a } -fn acos(a f64) f64 { +pub fn acos(a f64) f64 { return C.acos(a) } -fn asin(a f64) f64 { +pub fn asin(a f64) f64 { return C.asin(a) } -fn atan(a f64) f64 { +pub fn atan(a f64) f64 { return C.atan(a) } -fn atan2(a, b f64) f64 { +pub fn atan2(a, b f64) f64 { return C.atan2(a, b) } -fn ceil(a f64) f64 { +pub fn ceil(a f64) f64 { return C.ceil(a) } -fn cos(a f64) f64 { +pub fn cos(a f64) f64 { return C.cos(a) } -fn cosh(a f64) f64 { +pub fn cosh(a f64) f64 { return C.cosh(a) } -fn exp(a f64) f64 { +pub fn exp(a f64) f64 { return C.exp(a) } -fn floor(a f64) f64 { +pub fn floor(a f64) f64 { return C.floor(a) } -fn fmod(a, b f64) f64 { +pub fn fmod(a, b f64) f64 { return C.fmod(a, b) } -fn log(a f64) f64 { +pub fn log(a f64) f64 { return C.log(a) } -fn log10(a f64) f64 { +pub fn log10(a f64) f64 { return C.log10(a) } -fn max(a, b f64) f64 { +pub fn max(a, b f64) f64 { if a > b { return a } return b } -fn min(a, b f64) f64 { +pub fn min(a, b f64) f64 { if a < b { return a } return b } -fn pow(a, b f64) f64 { +pub fn pow(a, b f64) f64 { return C.pow(a, b) } -fn radians(degrees f64) f64 { +pub fn radians(degrees f64) f64 { return degrees * (Pi / 180.0) } -fn degrees(radians f64) f64 { +pub fn degrees(radians f64) f64 { return radians * (180.0 / Pi) } -fn round(f f64) f64 { +pub fn round(f f64) f64 { return C.round(f) } -fn sin(a f64) f64 { +pub fn sin(a f64) f64 { return C.sin(a) } -fn sinh(a f64) f64 { +pub fn sinh(a f64) f64 { return C.sinh(a) } -fn sqrt(a f64) f64 { +pub fn sqrt(a f64) f64 { return C.sqrt(a) } -fn tan(a f64) f64 { +pub fn tan(a f64) f64 { return C.tan(a) } -fn tanh(a f64) f64 { +pub fn tanh(a f64) f64 { return C.tanh(a) } -fn trunc(a f64) f64 { +pub fn trunc(a f64) f64 { return C.trunc(a) } diff --git a/stbi/stbi.v b/stbi/stbi.v index a8b66fdbf6..4f6e63f9fa 100644 --- a/stbi/stbi.v +++ b/stbi/stbi.v @@ -29,7 +29,7 @@ import const ( STBI_rgb_alpha ) -fn load(path string) Image { +pub fn load(path string) Image { ext := path.all_after('.') mut res := Image { ok: true @@ -49,11 +49,11 @@ fn load(path string) Image { return res } -fn (img Image) free() { +pub fn (img Image) free() { C.stbi_image_free(img.data) } -fn (img Image) tex_image_2d() { +pub fn (img Image) tex_image_2d() { mut rgb_flag := GL_RGB if img.ext == 'png' { rgb_flag = GL_RGBA @@ -62,7 +62,7 @@ fn (img Image) tex_image_2d() { img.data) } -fn set_flip_vertically_on_load(val bool) { +pub fn set_flip_vertically_on_load(val bool) { C.stbi_set_flip_vertically_on_load(val) }