mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
simplify gg; remove forced OpenGL dependency; graph builder /w hot code reloading
This commit is contained in:
50
vlib/gg/gg.v
50
vlib/gg/gg.v
@@ -9,6 +9,7 @@ import glm
|
||||
import gl
|
||||
import gx
|
||||
import os
|
||||
import glfw
|
||||
|
||||
struct Vec2 {
|
||||
x int
|
||||
@@ -36,6 +37,7 @@ pub fn vec2(x, y int) Vec2 {
|
||||
}
|
||||
|
||||
pub fn init() {
|
||||
glfw.init()
|
||||
println(gl.TEXT_VERT)
|
||||
gl.init_glad()
|
||||
}
|
||||
@@ -49,7 +51,11 @@ struct Cfg {
|
||||
height int
|
||||
use_ortho bool
|
||||
retina bool
|
||||
|
||||
font_size int
|
||||
create_window bool
|
||||
window_user_ptr voidptr
|
||||
window_title string
|
||||
}
|
||||
|
||||
struct GG {
|
||||
@@ -64,12 +70,25 @@ struct GG {
|
||||
line_vbo u32
|
||||
VBO u32
|
||||
scale int // retina = 2 , normal = 1
|
||||
pub mut:
|
||||
window *glfw.Window
|
||||
render_fn fn()
|
||||
}
|
||||
|
||||
|
||||
// fn new_context(width, height int, use_ortho bool, font_size int) *GG {
|
||||
pub fn new_context(cfg Cfg) *GG {
|
||||
// println('new context orhto=$cfg.use_ortho')
|
||||
// # glScissor(0,0,300,300);
|
||||
mut window := &glfw.Window{!}
|
||||
if cfg.create_window {
|
||||
window = glfw.create_window(glfw.WinCfg{
|
||||
title: cfg.window_title
|
||||
width: cfg.width
|
||||
height: cfg.height
|
||||
ptr: cfg.window_user_ptr
|
||||
})
|
||||
window.make_context_current()
|
||||
init()
|
||||
}
|
||||
shader := gl.new_shader('simple')
|
||||
shader.use()
|
||||
if cfg.use_ortho {
|
||||
@@ -122,22 +141,45 @@ pub fn new_context(cfg Cfg) *GG {
|
||||
//gl.enable_vertex_attrib_array(0)
|
||||
//gl.vertex_attrib_pointer(0, 4, GL_FLOAT, false, 4, 0)
|
||||
todo_remove_me(cfg, scale)
|
||||
mut ctx := &GG {
|
||||
return &GG {
|
||||
shader: shader
|
||||
width: cfg.width
|
||||
height: cfg.height
|
||||
VAO: vao
|
||||
VBO: vbo
|
||||
window: window
|
||||
|
||||
// /line_vao: gl.gen_vertex_array()
|
||||
// /line_vbo: gl.gen_buffer()
|
||||
//text_ctx: new_context_text(cfg, scale),
|
||||
scale: scale
|
||||
// use_ortho: use_ortho
|
||||
}
|
||||
|
||||
// ctx.init_rect_vao()
|
||||
return ctx
|
||||
//return ctx
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn (gg &GG) render_loop() bool {
|
||||
for !gg.window.show_close() {
|
||||
gg.render_fn()
|
||||
gg.window.swap_buffers()
|
||||
glfw.wait_events()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn clear(color gx.Color) {
|
||||
gl.clear()
|
||||
gl.clear_color(255, 255, 255, 255)
|
||||
}
|
||||
|
||||
pub fn (gg &GG) render() {
|
||||
gg.window.swap_buffers()
|
||||
glfw.wait_events()
|
||||
}
|
||||
|
||||
pub fn (ctx &GG) draw_triangle(x1, y1, x2, y2, x3, y3 f32, c gx.Color) {
|
||||
// println('draw_triangle $x1,$y1 $x2,$y2 $x3,$y3')
|
||||
ctx.shader.use()
|
||||
|
||||
Reference in New Issue
Block a user