examples/hot_code_reloading: graph builder improvements
							parent
							
								
									5c12d13b19
								
							
						
					
					
						commit
						7f512eaf72
					
				|  | @ -4,11 +4,11 @@ import gx | ||||||
| import gg | import gg | ||||||
| import time  | import time  | ||||||
| import glfw  | import glfw  | ||||||
|  | import math  | ||||||
| 	 | 	 | ||||||
| const ( | const ( | ||||||
| 	WIDTH  = 1000 | 	Size  = 1000 | ||||||
| 	HEIGHT = 1000 | 	Scale  = 50.0  | ||||||
| 	SCALE  = 50 |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| struct Context { | struct Context { | ||||||
|  | @ -19,12 +19,13 @@ fn main() { | ||||||
| 	glfw.init() | 	glfw.init() | ||||||
| 	ctx:= &Context{  | 	ctx:= &Context{  | ||||||
| 		gg: gg.new_context(gg.Cfg { | 		gg: gg.new_context(gg.Cfg { | ||||||
| 			width: WIDTH  | 			width: Size  | ||||||
| 			height: HEIGHT  | 			height: Size  | ||||||
| 			use_ortho: true  | 			use_ortho: true  | ||||||
| 			create_window: true  | 			create_window: true  | ||||||
| 			window_title: 'graph builder'  | 			window_title: 'Graph builder'  | ||||||
| 			window_user_ptr: ctx  | 			window_user_ptr: ctx  | ||||||
|  | 			always_on_top: true | ||||||
| 		}) | 		}) | ||||||
| 	}  | 	}  | ||||||
| 	for {  | 	for {  | ||||||
|  | @ -36,21 +37,12 @@ fn main() { | ||||||
| 
 | 
 | ||||||
| [live]  | [live]  | ||||||
| fn (ctx &Context) draw() { | fn (ctx &Context) draw() { | ||||||
| 	// x axis
 | 	ctx.gg.draw_line(0, Size / 2, Size, Size / 2) // x axis 
 | ||||||
| 	ctx.gg.draw_line(0, HEIGHT / 2, WIDTH, HEIGHT / 2) | 	ctx.gg.draw_line(Size / 2, 0, Size / 2, Size) // y axis 
 | ||||||
| 	// y axis
 | 	center := f64(Size / 2)  | ||||||
| 	ctx.gg.draw_line(WIDTH / 2, 0, WIDTH / 2, HEIGHT) | 	for x := -10.0; x <= 10.0; x += 0.002 { | ||||||
| 	mut prev_x := f64(0) | 		y := (x - 1) * (x - 1) + 1 | ||||||
| 	mut prev_y := f64(0) | 		ctx.gg.draw_rect(center + x * Scale,  | ||||||
| 	center := f64(WIDTH / 2) | 			center - y * Scale, 1, 1, gx.Black)  | ||||||
| 	for x := f64(- 10); x <= f64(10); x += 0.01 { |  | ||||||
| 		//y := (x * x - 2) * f64(SCALE)
 |  | ||||||
| 		y := (1.0 / x) * f64(SCALE) |  | ||||||
| 		//ctx.gg.draw_line(int(center + prev_x), int(center+prev_y), 
 |  | ||||||
| 			//int(center + x*f64(10)), int(center+y))
 |  | ||||||
| 		ctx.gg.draw_rect(int(center) + int(x * f64(SCALE)), int(center - y), 2, 1, gx.Black) |  | ||||||
| 		// gx.draw_rect_f(center + (x * f64(SCALE)), center - y, 1, 1, gx.BLACK)
 |  | ||||||
| 		prev_x = x |  | ||||||
| 		prev_y = y |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -56,6 +56,7 @@ struct Cfg { | ||||||
| 	create_window bool  | 	create_window bool  | ||||||
| 	window_user_ptr voidptr  | 	window_user_ptr voidptr  | ||||||
| 	window_title string  | 	window_title string  | ||||||
|  | 	always_on_top bool  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| struct GG { | struct GG { | ||||||
|  | @ -85,6 +86,7 @@ pub fn new_context(cfg Cfg) *GG { | ||||||
| 			width: cfg.width  | 			width: cfg.width  | ||||||
| 			height: cfg.height  | 			height: cfg.height  | ||||||
| 			ptr: cfg.window_user_ptr  | 			ptr: cfg.window_user_ptr  | ||||||
|  | 			always_on_top: cfg.always_on_top  | ||||||
| 		}) | 		}) | ||||||
| 		window.make_context_current() | 		window.make_context_current() | ||||||
| 		init()  | 		init()  | ||||||
|  | @ -401,7 +403,7 @@ pub fn create_image(file string) u32 { | ||||||
| 	return texture | 	return texture | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn (ctx &GG) draw_line_c(x, y, x2, y2 int, color gx.Color) { | pub fn (ctx &GG) draw_line_c(x, y, x2, y2 f32, color gx.Color) { | ||||||
| 	C.glDeleteBuffers(1, &ctx.VAO) | 	C.glDeleteBuffers(1, &ctx.VAO) | ||||||
| 	C.glDeleteBuffers(1, &ctx.VBO) | 	C.glDeleteBuffers(1, &ctx.VBO) | ||||||
| 	ctx.shader.use() | 	ctx.shader.use() | ||||||
|  | @ -415,7 +417,7 @@ pub fn (ctx &GG) draw_line_c(x, y, x2, y2 int, color gx.Color) { | ||||||
| 	gl.draw_arrays(GL_LINES, 0, 2) | 	gl.draw_arrays(GL_LINES, 0, 2) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn (c &GG) draw_line(x, y, x2, y2 int) { | pub fn (c &GG) draw_line(x, y, x2, y2 f32) { | ||||||
| 	c.draw_line_c(x, y, x2, y2, gx.Gray) | 	c.draw_line_c(x, y, x2, y2, gx.Gray) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -423,6 +425,9 @@ pub fn (c &GG) draw_vertical(x, y, height int) { | ||||||
| 	c.draw_line(x, y, x, y + height) | 	c.draw_line(x, y, x, y + height) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | //ctx.gg.draw_line(center + prev_x, center+prev_y, center + x*10.0, center+y)
 | ||||||
|  | 
 | ||||||
| // fn (ctx &GG) draw_image(x, y, w, h f32, img stbi.Image) {
 | // fn (ctx &GG) draw_image(x, y, w, h f32, img stbi.Image) {
 | ||||||
| pub fn (ctx &GG) draw_image(x, y, w, h f32, tex_id u32) { | pub fn (ctx &GG) draw_image(x, y, w, h f32, tex_id u32) { | ||||||
| 	// println('DRAW IMAGE $x $y $w $h $tex_id')
 | 	// println('DRAW IMAGE $x $y $w $h $tex_id')
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue