make lots of functions public

pull/679/head
Alexander Medvednikov 2019-06-26 17:49:50 +02:00
parent fc628f2ee9
commit b87e61aa4e
6 changed files with 75 additions and 75 deletions

View File

@ -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}

View File

@ -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')

View File

@ -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)
}

View File

@ -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<T>(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,

View File

@ -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)
}

View File

@ -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)
}