gg: set_pixels() (#11236)
							parent
							
								
									a440b43630
								
							
						
					
					
						commit
						70a658a265
					
				|  | @ -0,0 +1,39 @@ | |||
| module main | ||||
| 
 | ||||
| import gg | ||||
| import gx | ||||
| 
 | ||||
| struct App { | ||||
| mut: | ||||
| 	gg &gg.Context | ||||
| } | ||||
| 
 | ||||
| fn main() { | ||||
| 	mut app := &App{ | ||||
| 		gg: 0 | ||||
| 	} | ||||
| 	app.gg = gg.new_context( | ||||
| 		bg_color: gx.rgb(174, 198, 255) | ||||
| 		width: 100 | ||||
| 		height: 100 | ||||
| 		window_title: 'Set Pixels' | ||||
| 		frame_fn: frame | ||||
| 		user_data: app | ||||
| 	) | ||||
| 	app.gg.run() | ||||
| } | ||||
| 
 | ||||
| fn frame(mut app App) { | ||||
| 	mut pixels := []f32{} | ||||
| 
 | ||||
| 	for x in 30 .. 60 { | ||||
| 		for y in 30 .. 60 { | ||||
| 			pixels << f32(x) | ||||
| 			pixels << f32(y) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	app.gg.begin() | ||||
| 	app.gg.set_pixels(pixels, gx.red) | ||||
| 	app.gg.end() | ||||
| } | ||||
							
								
								
									
										21
									
								
								vlib/gg/gg.v
								
								
								
								
							
							
						
						
									
										21
									
								
								vlib/gg/gg.v
								
								
								
								
							|  | @ -268,6 +268,27 @@ pub fn (ctx &Context) set_pixel(x f32, y f32, c gx.Color) { | |||
| 	ctx.draw_square(x, y, 1, c) | ||||
| } | ||||
| 
 | ||||
| pub fn (ctx &Context) set_pixels(points []f32, c gx.Color) { | ||||
| 	assert points.len % 2 == 0 | ||||
| 	len := points.len / 2 | ||||
| 
 | ||||
| 	if c.a != 255 { | ||||
| 		sgl.load_pipeline(ctx.timage_pip) | ||||
| 	} | ||||
| 
 | ||||
| 	sgl.c4b(c.r, c.g, c.b, c.a) | ||||
| 	sgl.begin_quads() | ||||
| 	for i in 0 .. len { | ||||
| 		x, y := points[i * 2], points[i * 2 + 1] | ||||
| 
 | ||||
| 		sgl.v2f(x * ctx.scale, y * ctx.scale) | ||||
| 		sgl.v2f((x + 1) * ctx.scale, y * ctx.scale) | ||||
| 		sgl.v2f((x + 1) * ctx.scale, (y + 1) * ctx.scale) | ||||
| 		sgl.v2f(x * ctx.scale, (y + 1) * ctx.scale) | ||||
| 	} | ||||
| 	sgl.end() | ||||
| } | ||||
| 
 | ||||
| pub fn (ctx &Context) draw_triangle(x f32, y f32, x2 f32, y2 f32, x3 f32, y3 f32, c gx.Color) { | ||||
| 	if c.a != 255 { | ||||
| 		sgl.load_pipeline(ctx.timage_pip) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue