remove "import const" everywhere
							parent
							
								
									dcfc9eb1a1
								
							
						
					
					
						commit
						f61b14584a
					
				|  | @ -374,7 +374,7 @@ fn key_down(wnd voidptr, key, code, action, mods int) { | ||||||
| 	switch key { | 	switch key { | ||||||
| 	case glfw.KEY_ESCAPE: | 	case glfw.KEY_ESCAPE: | ||||||
| 		glfw.set_should_close(wnd, true) | 		glfw.set_should_close(wnd, true) | ||||||
| 	case GLFW_KEY_SPACE: | 	case glfw.key_space: | ||||||
| 		if game.state == .running { | 		if game.state == .running { | ||||||
| 			game.state = .paused | 			game.state = .paused | ||||||
| 		} else if game.state == .paused { | 		} else if game.state == .paused { | ||||||
|  |  | ||||||
|  | @ -8,10 +8,6 @@ import math | ||||||
| 
 | 
 | ||||||
| #include <sys/syscall.h> | #include <sys/syscall.h> | ||||||
| 
 | 
 | ||||||
| import const( |  | ||||||
| 	SYS_getrandom |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| // const (
 | // const (
 | ||||||
| // 	SYS_getrandom = 278 // AArch65
 | // 	SYS_getrandom = 278 // AArch65
 | ||||||
| // 	SYS_getrandom = 384 // ARM
 | // 	SYS_getrandom = 384 // ARM
 | ||||||
|  | @ -47,5 +43,5 @@ fn _getrandom(bytes_needed int, buffer voidptr) int { | ||||||
| 	if bytes_needed > ReadBatchSize { | 	if bytes_needed > ReadBatchSize { | ||||||
| 		panic('_getrandom() dont request more thane $ReadBatchSize bytes at once.') | 		panic('_getrandom() dont request more thane $ReadBatchSize bytes at once.') | ||||||
| 	} | 	} | ||||||
| 	return C.syscall(SYS_getrandom, buffer, bytes_needed, 0) | 	return C.syscall(C.SYS_getrandom, buffer, bytes_needed, 0) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -6,20 +6,10 @@ module rand | ||||||
| 
 | 
 | ||||||
| #flag darwin -framework Security | #flag darwin -framework Security | ||||||
| 
 | 
 | ||||||
| // import const (
 |  | ||||||
| // 	kSecRandomDefault
 |  | ||||||
| // 	errSecSuccess
 |  | ||||||
| // )
 |  | ||||||
| 
 |  | ||||||
| const ( |  | ||||||
| 	kSecRandomDefault = 0 |  | ||||||
| 	errSecSuccess     = 0 |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| pub fn read(bytes_needed int) ?[]byte { | pub fn read(bytes_needed int) ?[]byte { | ||||||
| 	mut buffer := malloc(bytes_needed) | 	mut buffer := malloc(bytes_needed) | ||||||
| 	status := C.SecRandomCopyBytes(kSecRandomDefault, bytes_needed, buffer) | 	status := C.SecRandomCopyBytes(0, bytes_needed, buffer) | ||||||
| 	if status != errSecSuccess { | 	if status != 0 { | ||||||
| 		return ReadError | 		return ReadError | ||||||
| 	} | 	} | ||||||
| 	return c_array_to_bytes_tmp(bytes_needed, buffer) | 	return c_array_to_bytes_tmp(bytes_needed, buffer) | ||||||
|  |  | ||||||
|  | @ -111,9 +111,9 @@ fn ft_load_char(_face Face, code i64) Character { | ||||||
| 	C.glTexImage2D(C.GL_TEXTURE_2D, 0, C.GL_RED, fgwidth,  fgrows, | 	C.glTexImage2D(C.GL_TEXTURE_2D, 0, C.GL_RED, fgwidth,  fgrows, | ||||||
| 		0, C.GL_RED, C.GL_UNSIGNED_BYTE, face.glyph.bitmap.buffer) | 		0, C.GL_RED, C.GL_UNSIGNED_BYTE, face.glyph.bitmap.buffer) | ||||||
| 	// Set texture options
 | 	// Set texture options
 | ||||||
| 	C.glTexParameteri(GL_TEXTURE_2D, C.GL_TEXTURE_WRAP_S, C.GL_CLAMP_TO_EDGE) | 	C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_WRAP_S, C.GL_CLAMP_TO_EDGE) | ||||||
| 	C.glTexParameteri(GL_TEXTURE_2D, C.GL_TEXTURE_WRAP_T, C.GL_CLAMP_TO_EDGE) | 	C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_WRAP_T, C.GL_CLAMP_TO_EDGE) | ||||||
| 	C.glTexParameteri(GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_LINEAR) | 	C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_LINEAR) | ||||||
| 	C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_LINEAR) | 	C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_LINEAR) | ||||||
| 	fgleft := face.glyph.bitmap_left | 	fgleft := face.glyph.bitmap_left | ||||||
| 	fgtop := face.glyph.bitmap_top | 	fgtop := face.glyph.bitmap_top | ||||||
|  | @ -146,7 +146,7 @@ pub fn new_context(cfg gg.Cfg) *Context { | ||||||
| 	gl.viewport(0, 0, width, height) | 	gl.viewport(0, 0, width, height) | ||||||
| */ | */ | ||||||
| 	// gl.enable(GL_CULL_FACE) // TODO NEED CULL?
 | 	// gl.enable(GL_CULL_FACE) // TODO NEED CULL?
 | ||||||
| 	gl.enable(GL_BLEND) | 	gl.enable(C.GL_BLEND) | ||||||
| 	C.glBlendFunc(C.GL_SRC_ALPHA, C.GL_ONE_MINUS_SRC_ALPHA) | 	C.glBlendFunc(C.GL_SRC_ALPHA, C.GL_ONE_MINUS_SRC_ALPHA) | ||||||
| 	shader := gl.new_shader('text') | 	shader := gl.new_shader('text') | ||||||
| 	shader.use() | 	shader.use() | ||||||
|  | @ -209,10 +209,10 @@ pub fn new_context(cfg gg.Cfg) *Context { | ||||||
| 	println('new gg text context vao=$vao') | 	println('new gg text context vao=$vao') | ||||||
| 	vbo := gl.gen_buffer() | 	vbo := gl.gen_buffer() | ||||||
| 	gl.bind_vao(vao) | 	gl.bind_vao(vao) | ||||||
| 	gl.bind_buffer(GL_ARRAY_BUFFER, vbo) | 	gl.bind_buffer(C.GL_ARRAY_BUFFER, vbo) | ||||||
| 	// # glBufferData(GL_ARRAY_BUFFER, sizeof(GLf32) * 6 * 4, NULL, GL_DYNAMIC_DRAW);
 | 	// # glBufferData(GL_ARRAY_BUFFER, sizeof(GLf32) * 6 * 4, NULL, GL_DYNAMIC_DRAW);
 | ||||||
| 	gl.enable_vertex_attrib_array(0) | 	gl.enable_vertex_attrib_array(0) | ||||||
| 	gl.vertex_attrib_pointer(0, 4, GL_FLOAT, false, 4, 0) | 	gl.vertex_attrib_pointer(0, 4, C.GL_FLOAT, false, 4, 0) | ||||||
| 	// # glVertexAttribPointer(0, 4, GL_FLOAT,false, 4 * sizeof(GLf32), 0);
 | 	// # glVertexAttribPointer(0, 4, GL_FLOAT,false, 4 * sizeof(GLf32), 0);
 | ||||||
| 	// gl.bind_buffer(GL_ARRAY_BUFFER, uint(0))
 | 	// gl.bind_buffer(GL_ARRAY_BUFFER, uint(0))
 | ||||||
| 	// # glBindVertexArray(0);
 | 	// # glBindVertexArray(0);
 | ||||||
|  | @ -336,11 +336,11 @@ fn (ctx mut Context) _draw_text(_x, _y int, utext ustring, cfg gx.TextCfg) { | ||||||
| 		// Render glyph texture over quad
 | 		// Render glyph texture over quad
 | ||||||
| 		C.glBindTexture(C.GL_TEXTURE_2D, ch.texture_id) | 		C.glBindTexture(C.GL_TEXTURE_2D, ch.texture_id) | ||||||
| 		// Update content of VBO memory
 | 		// Update content of VBO memory
 | ||||||
| 		gl.bind_buffer(GL_ARRAY_BUFFER, ctx.vbo) | 		gl.bind_buffer(C.GL_ARRAY_BUFFER, ctx.vbo) | ||||||
| 		// glBufferSubData(..)
 | 		// glBufferSubData(..)
 | ||||||
| 		C.glBufferData(GL_ARRAY_BUFFER, 96, vertices.data, C.GL_DYNAMIC_DRAW) | 		C.glBufferData(C.GL_ARRAY_BUFFER, 96, vertices.data, C.GL_DYNAMIC_DRAW) | ||||||
| 		// Render quad
 | 		// Render quad
 | ||||||
| 		gl.draw_arrays(GL_TRIANGLES, 0, 6) | 		gl.draw_arrays(C.GL_TRIANGLES, 0, 6) | ||||||
| 		// Now advance cursors for next glyph (note that advance is number of 1/64 pixels)
 | 		// Now advance cursors for next glyph (note that advance is number of 1/64 pixels)
 | ||||||
| 		// Bitshift by 6 to get value in pixels (2^6 = 64 (divide amount of 1/64th pixels by 64 to get amount of pixels))
 | 		// Bitshift by 6 to get value in pixels (2^6 = 64 (divide amount of 1/64th pixels by 64 to get amount of pixels))
 | ||||||
| 		x += ch.advance >> u32(6) | 		x += ch.advance >> u32(6) | ||||||
|  |  | ||||||
							
								
								
									
										64
									
								
								vlib/gg/gg.v
								
								
								
								
							
							
						
						
									
										64
									
								
								vlib/gg/gg.v
								
								
								
								
							|  | @ -17,14 +17,6 @@ pub: | ||||||
| 	y int | 	y int | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| import const ( |  | ||||||
| 	GL_STATIC_DRAW |  | ||||||
| 	GL_FLOAT |  | ||||||
| 	GL_FALSE |  | ||||||
| 	GL_UNSIGNED_INT |  | ||||||
| 	GL_INT |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| pub fn vec2(x, y int) Vec2 { | pub fn vec2(x, y int) Vec2 { | ||||||
| 	res := Vec2 { | 	res := Vec2 { | ||||||
| 		x: x | 		x: x | ||||||
|  | @ -165,8 +157,8 @@ pub fn (ctx &GG) draw_triangle(x1, y1, x2, y2, x3, y3 f32, c gx.Color) { | ||||||
| 	// bind the Vertex Array Object first, then bind and set vertex buffer(s),
 | 	// bind the Vertex Array Object first, then bind and set vertex buffer(s),
 | ||||||
| 	// and then configure vertex attributes(s).
 | 	// and then configure vertex attributes(s).
 | ||||||
| 	gl.bind_vao(ctx.vao) | 	gl.bind_vao(ctx.vao) | ||||||
| 	gl.set_vbo(ctx.vbo, vertices, GL_STATIC_DRAW) | 	gl.set_vbo(ctx.vbo, vertices, C.GL_STATIC_DRAW) | ||||||
| 	gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 3, 0) | 	gl.vertex_attrib_pointer(0, 3, C.GL_FLOAT, false, 3, 0) | ||||||
| 	gl.enable_vertex_attrib_array(0) | 	gl.enable_vertex_attrib_array(0) | ||||||
| 	// gl.bind_buffer(GL_ARRAY_BUFFER, uint(0))
 | 	// gl.bind_buffer(GL_ARRAY_BUFFER, uint(0))
 | ||||||
| 	// You can unbind the VAO afterwards so other VAO calls won't accidentally modify this VAO,
 | 	// You can unbind the VAO afterwards so other VAO calls won't accidentally modify this VAO,
 | ||||||
|  | @ -175,7 +167,7 @@ pub fn (ctx &GG) draw_triangle(x1, y1, x2, y2, x3, y3 f32, c gx.Color) { | ||||||
| 	// (nor VBOs) when it's not directly necessary.
 | 	// (nor VBOs) when it's not directly necessary.
 | ||||||
| 	// gl.bind_vertex_array(uint(0))
 | 	// gl.bind_vertex_array(uint(0))
 | ||||||
| 	// gl.bind_vertex_array(ctx.VAO)
 | 	// gl.bind_vertex_array(ctx.VAO)
 | ||||||
| 	gl.draw_arrays(GL_TRIANGLES, 0, 3) | 	gl.draw_arrays(C.GL_TRIANGLES, 0, 3) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn (ctx &GG) draw_triangle_tex(x1, y1, x2, y2, x3, y3 f32, c gx.Color) { | pub fn (ctx &GG) draw_triangle_tex(x1, y1, x2, y2, x3, y3 f32, c gx.Color) { | ||||||
|  | @ -188,19 +180,19 @@ pub fn (ctx &GG) draw_triangle_tex(x1, y1, x2, y2, x3, y3 f32, c gx.Color) { | ||||||
| 	x3, y3, 0, 0, 0, 0, 0, 0, | 	x3, y3, 0, 0, 0, 0, 0, 0, | ||||||
| 	] ! | 	] ! | ||||||
| 	gl.bind_vao(ctx.vao) | 	gl.bind_vao(ctx.vao) | ||||||
| 	gl.set_vbo(ctx.vbo, vertices, GL_STATIC_DRAW) | 	gl.set_vbo(ctx.vbo, vertices, C.GL_STATIC_DRAW) | ||||||
| 	// position attribute
 | 	// position attribute
 | ||||||
| 	gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 3, 0) | 	gl.vertex_attrib_pointer(0, 3, C.GL_FLOAT, false, 3, 0) | ||||||
| 	gl.enable_vertex_attrib_array(0) | 	gl.enable_vertex_attrib_array(0) | ||||||
| 	// color attribute
 | 	// color attribute
 | ||||||
| 	gl.vertex_attrib_pointer(1, 3, GL_FLOAT, false, 8, 3) | 	gl.vertex_attrib_pointer(1, 3, C.GL_FLOAT, false, 8, 3) | ||||||
| 	gl.enable_vertex_attrib_array(1) | 	gl.enable_vertex_attrib_array(1) | ||||||
| 	// texture attribute
 | 	// texture attribute
 | ||||||
| 	gl.vertex_attrib_pointer(2, 2, GL_FLOAT, false, 8, 6) | 	gl.vertex_attrib_pointer(2, 2, C.GL_FLOAT, false, 8, 6) | ||||||
| 	gl.enable_vertex_attrib_array(2) | 	gl.enable_vertex_attrib_array(2) | ||||||
| 	// /
 | 	// /
 | ||||||
| 	// gl.draw_arrays(GL_TRIANGLES, 0, 3)
 | 	// gl.draw_arrays(GL_TRIANGLES, 0, 3)
 | ||||||
| 	gl.draw_elements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0) | 	gl.draw_elements(C.GL_TRIANGLES, 6, C.GL_UNSIGNED_INT, 0) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub 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) { | ||||||
|  | @ -230,10 +222,10 @@ fn (ctx mut GG) init_rect_vao() { | ||||||
| 	1, 2, 3// second triangle
 | 	1, 2, 3// second triangle
 | ||||||
| 	] ! | 	] ! | ||||||
| 	gl.bind_vao(ctx.rect_vao) | 	gl.bind_vao(ctx.rect_vao) | ||||||
| 	gl.set_vbo(ctx.rect_vbo, vertices, GL_STATIC_DRAW) | 	gl.set_vbo(ctx.rect_vbo, vertices, C.GL_STATIC_DRAW) | ||||||
| 	ebo := gl.gen_buffer() | 	ebo := gl.gen_buffer() | ||||||
| 	// ///////
 | 	// ///////
 | ||||||
| 	gl.set_ebo(ebo, indices, GL_STATIC_DRAW) | 	gl.set_ebo(ebo, indices, C.GL_STATIC_DRAW) | ||||||
| } | } | ||||||
| */ | */ | ||||||
| pub 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) { | ||||||
|  | @ -258,16 +250,16 @@ pub fn (ctx &GG) draw_rect2(x, y, w, h f32, c gx.Color) { | ||||||
| 	1, 2, 3// second triangle
 | 	1, 2, 3// second triangle
 | ||||||
| 	] ! | 	] ! | ||||||
| 	gl.bind_vao(ctx.vao) | 	gl.bind_vao(ctx.vao) | ||||||
| 	gl.set_vbo(ctx.vbo, vertices, GL_STATIC_DRAW) | 	gl.set_vbo(ctx.vbo, vertices, C.GL_STATIC_DRAW) | ||||||
| 	ebo := gl.gen_buffer() | 	ebo := gl.gen_buffer() | ||||||
| 	// ///////
 | 	// ///////
 | ||||||
| 	gl.set_ebo(ebo, indices, GL_STATIC_DRAW)// !!! LEAKS
 | 	gl.set_ebo(ebo, indices, C.GL_STATIC_DRAW)// !!! LEAKS
 | ||||||
| 	// /////
 | 	// /////
 | ||||||
| 	gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 3, 0) | 	gl.vertex_attrib_pointer(0, 3, C.GL_FLOAT, false, 3, 0) | ||||||
| 	gl.enable_vertex_attrib_array(0) | 	gl.enable_vertex_attrib_array(0) | ||||||
| 	// gl.bind_vao(ctx.rect_vao)
 | 	// gl.bind_vao(ctx.rect_vao)
 | ||||||
| 	gl.bind_vao(ctx.vao) | 	gl.bind_vao(ctx.vao) | ||||||
| 	gl.draw_elements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0) | 	gl.draw_elements(C.GL_TRIANGLES, 6, C.GL_UNSIGNED_INT, 0) | ||||||
| 	C.glDeleteBuffers(1, &ebo) | 	C.glDeleteBuffers(1, &ebo) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -279,8 +271,8 @@ fn todo_remove_me(cfg Cfg, scale int) { | ||||||
| 	mut width := cfg.width * scale | 	mut width := cfg.width * scale | ||||||
| 	mut height := cfg.height * scale | 	mut height := cfg.height * scale | ||||||
| 	font_size := cfg.font_size * scale | 	font_size := cfg.font_size * scale | ||||||
| 	gl.enable(GL_BLEND) | 	gl.enable(C.GL_BLEND) | ||||||
| 	//# glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 | 	//# glBlendFunc(C.GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 | ||||||
| 	shader := gl.new_shader('text') | 	shader := gl.new_shader('text') | ||||||
| 	shader.use() | 	shader.use() | ||||||
| 	projection := glm.ortho(0, width, 0, height)// 0 at BOT
 | 	projection := glm.ortho(0, width, 0, height)// 0 at BOT
 | ||||||
|  | @ -291,9 +283,9 @@ fn todo_remove_me(cfg Cfg, scale int) { | ||||||
| 	//println('new gg text context VAO=$VAO')
 | 	//println('new gg text context VAO=$VAO')
 | ||||||
| 	vbo := gl.gen_buffer() | 	vbo := gl.gen_buffer() | ||||||
| 	gl.bind_vao(vao) | 	gl.bind_vao(vao) | ||||||
| 	gl.bind_buffer(GL_ARRAY_BUFFER, vbo) | 	gl.bind_buffer(C.GL_ARRAY_BUFFER, vbo) | ||||||
| 	gl.enable_vertex_attrib_array(0) | 	gl.enable_vertex_attrib_array(0) | ||||||
| 	gl.vertex_attrib_pointer(0, 4, GL_FLOAT, false, 4, 0) | 	gl.vertex_attrib_pointer(0, 4, C.GL_FLOAT, false, 4, 0) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn update() { | fn update() { | ||||||
|  | @ -372,7 +364,7 @@ pub fn create_image(file string) u32 { | ||||||
| 	img := stbi.load(file) | 	img := stbi.load(file) | ||||||
| 	gl.bind_2d_texture(texture) | 	gl.bind_2d_texture(texture) | ||||||
| 	img.tex_image_2d() | 	img.tex_image_2d() | ||||||
| 	gl.generate_mipmap(GL_TEXTURE_2D) | 	gl.generate_mipmap(C.GL_TEXTURE_2D) | ||||||
| 	img.free() | 	img.free() | ||||||
| 	// println('gg end')
 | 	// println('gg end')
 | ||||||
| 	return texture | 	return texture | ||||||
|  | @ -385,11 +377,11 @@ pub fn (ctx &GG) draw_line_c(x, y, x2, y2 f32, color gx.Color) { | ||||||
| 	ctx.shader.set_color('color', color) | 	ctx.shader.set_color('color', color) | ||||||
| 	vertices := [f32(x), f32(y), f32(x2), f32(y2)] ! | 	vertices := [f32(x), f32(y), f32(x2), f32(y2)] ! | ||||||
| 	gl.bind_vao(ctx.vao) | 	gl.bind_vao(ctx.vao) | ||||||
| 	gl.set_vbo(ctx.vbo, vertices, GL_STATIC_DRAW) | 	gl.set_vbo(ctx.vbo, vertices, C.GL_STATIC_DRAW) | ||||||
| 	gl.vertex_attrib_pointer(0, 2, GL_FLOAT, false, 2, 0) | 	gl.vertex_attrib_pointer(0, 2, C.GL_FLOAT, false, 2, 0) | ||||||
| 	gl.enable_vertex_attrib_array(0) | 	gl.enable_vertex_attrib_array(0) | ||||||
| 	gl.bind_vao(ctx.vao) | 	gl.bind_vao(ctx.vao) | ||||||
| 	gl.draw_arrays(GL_LINES, 0, 2) | 	gl.draw_arrays(C.GL_LINES, 0, 2) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn (c &GG) draw_line(x, y, x2, y2 f32) { | pub fn (c &GG) draw_line(x, y, x2, y2 f32) { | ||||||
|  | @ -425,18 +417,18 @@ pub fn (ctx &GG) draw_image(x, y, w, h f32, tex_id u32) { | ||||||
| 	// VAO := gl.gen_vertex_array()
 | 	// VAO := gl.gen_vertex_array()
 | ||||||
| 	// VBO := gl.gen_buffer()
 | 	// VBO := gl.gen_buffer()
 | ||||||
| 	gl.bind_vao(ctx.vao) | 	gl.bind_vao(ctx.vao) | ||||||
| 	gl.set_vbo(ctx.vbo, vertices, GL_STATIC_DRAW) | 	gl.set_vbo(ctx.vbo, vertices, C.GL_STATIC_DRAW) | ||||||
| 	ebo := gl.gen_buffer() | 	ebo := gl.gen_buffer() | ||||||
| 	gl.set_ebo(ebo, indices, GL_STATIC_DRAW) | 	gl.set_ebo(ebo, indices, C.GL_STATIC_DRAW) | ||||||
| 	gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 8, 0) | 	gl.vertex_attrib_pointer(0, 3, C.GL_FLOAT, false, 8, 0) | ||||||
| 	gl.enable_vertex_attrib_array(0) | 	gl.enable_vertex_attrib_array(0) | ||||||
| 	gl.vertex_attrib_pointer(1, 3, GL_FLOAT, false, 8, 3) | 	gl.vertex_attrib_pointer(1, 3, C.GL_FLOAT, false, 8, 3) | ||||||
| 	gl.enable_vertex_attrib_array(1) | 	gl.enable_vertex_attrib_array(1) | ||||||
| 	gl.vertex_attrib_pointer(2, 2, GL_FLOAT, false, 8, 6) | 	gl.vertex_attrib_pointer(2, 2, C.GL_FLOAT, false, 8, 6) | ||||||
| 	gl.enable_vertex_attrib_array(2) | 	gl.enable_vertex_attrib_array(2) | ||||||
| 	gl.bind_2d_texture(u32(tex_id)) | 	gl.bind_2d_texture(u32(tex_id)) | ||||||
| 	gl.bind_vao(ctx.vao) | 	gl.bind_vao(ctx.vao) | ||||||
| 	gl.draw_elements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0) | 	gl.draw_elements(C.GL_TRIANGLES, 6, C.GL_UNSIGNED_INT, 0) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn (c &GG) draw_empty_rect(x, y, w, h int, color gx.Color) { | pub fn (c &GG) draw_empty_rect(x, y, w, h int, color gx.Color) { | ||||||
|  |  | ||||||
|  | @ -9,15 +9,6 @@ import gx | ||||||
| import glm | import glm | ||||||
| 
 | 
 | ||||||
| // import darwin
 | // import darwin
 | ||||||
| import const ( |  | ||||||
| 	GL_VERTEX_SHADER |  | ||||||
| 	GL_FRAGMENT_SHADER |  | ||||||
| 	GL_ARRAY_BUFFER |  | ||||||
| 	GL_TRIANGLES |  | ||||||
| 	GL_CULL_FACE |  | ||||||
| 	GL_BLEND |  | ||||||
| 	GL_LINES |  | ||||||
| ) |  | ||||||
| 
 | 
 | ||||||
| struct Shader { | struct Shader { | ||||||
| 	program_id int | 	program_id int | ||||||
|  | @ -118,7 +109,7 @@ pub fn new_shader(name string) Shader { | ||||||
| 		fragment_src = SIMPLE_FRAG | 		fragment_src = SIMPLE_FRAG | ||||||
| 	} | 	} | ||||||
| 	// ////////////////////////////////////////
 | 	// ////////////////////////////////////////
 | ||||||
| 	vertex_shader := gl.create_shader(GL_VERTEX_SHADER) | 	vertex_shader := gl.create_shader(C.GL_VERTEX_SHADER) | ||||||
| 	gl.shader_source(vertex_shader, 1, vertex_src, 0) | 	gl.shader_source(vertex_shader, 1, vertex_src, 0) | ||||||
| 	gl.compile_shader(vertex_shader) | 	gl.compile_shader(vertex_shader) | ||||||
| 	if gl.shader_compile_status(vertex_shader) == 0 { | 	if gl.shader_compile_status(vertex_shader) == 0 { | ||||||
|  | @ -130,7 +121,7 @@ pub fn new_shader(name string) Shader { | ||||||
| 	} | 	} | ||||||
| 	// fragment shader
 | 	// fragment shader
 | ||||||
| 	// fragment_src := os.read_file(fragment_path.trim_space())
 | 	// fragment_src := os.read_file(fragment_path.trim_space())
 | ||||||
| 	fragment_shader := gl.create_shader(GL_FRAGMENT_SHADER) | 	fragment_shader := gl.create_shader(C.GL_FRAGMENT_SHADER) | ||||||
| 	gl.shader_source(fragment_shader, 1, fragment_src, 0) | 	gl.shader_source(fragment_shader, 1, fragment_src, 0) | ||||||
| 	gl.compile_shader(fragment_shader) | 	gl.compile_shader(fragment_shader) | ||||||
| 	if gl.shader_compile_status(fragment_shader) == 0 { | 	if gl.shader_compile_status(fragment_shader) == 0 { | ||||||
|  |  | ||||||
							
								
								
									
										35
									
								
								vlib/gl/gl.v
								
								
								
								
							
							
						
						
									
										35
									
								
								vlib/gl/gl.v
								
								
								
								
							|  | @ -4,21 +4,6 @@ | ||||||
| 
 | 
 | ||||||
| module gl | module gl | ||||||
| 
 | 
 | ||||||
| import const ( |  | ||||||
| 	GL_TEXTURE_2D |  | ||||||
| 	GL_TEXTURE0 |  | ||||||
| 	GL_FLOAT |  | ||||||
| 	GL_VERTEX_SHADER |  | ||||||
| 	GL_ELEMENT_ARRAY_BUFFER |  | ||||||
| 	GL_DEPTH_TEST |  | ||||||
| 	GL_COLOR_BUFFER_BIT |  | ||||||
| 	GL_DEPTH_BUFFER_BIT |  | ||||||
| 	GL_STENCIL_BUFFER_BIT |  | ||||||
| 	GL_COMPILE_STATUS |  | ||||||
| 	GL_LINK_STATUS |  | ||||||
| 	GL_ARRAY_BUFFER |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| #flag  -I @VROOT/thirdparty/glad | #flag  -I @VROOT/thirdparty/glad | ||||||
| #include "glad.h" | #include "glad.h" | ||||||
| #flag @VROOT/thirdparty/glad/glad.o | #flag @VROOT/thirdparty/glad/glad.o | ||||||
|  | @ -40,7 +25,7 @@ pub fn clear_color(r, g, b, a int) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn clear() { | pub fn clear() { | ||||||
| 	C.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT) | 	C.glClear(C.GL_COLOR_BUFFER_BIT | C.GL_DEPTH_BUFFER_BIT | C.GL_STENCIL_BUFFER_BIT) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn create_shader(typ int) int { | pub fn create_shader(typ int) int { | ||||||
|  | @ -61,7 +46,7 @@ pub fn compile_shader(shader int) { | ||||||
| 
 | 
 | ||||||
| pub fn shader_compile_status(shader int) int { | pub fn shader_compile_status(shader int) int { | ||||||
| 	success := 0 | 	success := 0 | ||||||
| 	C.glGetShaderiv(shader, GL_COMPILE_STATUS, &success) | 	C.glGetShaderiv(shader, C.GL_COMPILE_STATUS, &success) | ||||||
| 	return success | 	return success | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -76,7 +61,7 @@ pub fn link_program(program int) { | ||||||
| 
 | 
 | ||||||
| pub fn get_program_link_status(program int) int { | pub fn get_program_link_status(program int) int { | ||||||
| 	success := 0 | 	success := 0 | ||||||
| 	C.glGetProgramiv(program, GL_LINK_STATUS, &success) | 	C.glGetProgramiv(program, C.GL_LINK_STATUS, &success) | ||||||
| 	return success | 	return success | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -115,7 +100,7 @@ pub fn active_texture(t int) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn bind_2d_texture(texture u32) { | pub fn bind_2d_texture(texture u32) { | ||||||
| 	C.glBindTexture(GL_TEXTURE_2D, texture) | 	C.glBindTexture(C.GL_TEXTURE_2D, texture) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn delete_texture(texture u32) { | pub fn delete_texture(texture u32) { | ||||||
|  | @ -137,14 +122,14 @@ pub fn buffer_data_f32(typ int, vertices []f32, draw_typ int) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn set_vbo(vbo u32, vertices []f32, draw_typ int) { | pub fn set_vbo(vbo u32, vertices []f32, draw_typ int) { | ||||||
| 	gl.bind_buffer(GL_ARRAY_BUFFER, vbo) | 	gl.bind_buffer(C.GL_ARRAY_BUFFER, vbo) | ||||||
| 	gl.buffer_data_f32(GL_ARRAY_BUFFER, vertices, draw_typ) | 	gl.buffer_data_f32(C.GL_ARRAY_BUFFER, vertices, draw_typ) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn set_ebo(ebo u32, indices []int, draw_typ int) { | pub fn set_ebo(ebo u32, indices []int, draw_typ int) { | ||||||
| 	gl.bind_buffer(GL_ELEMENT_ARRAY_BUFFER, ebo) | 	gl.bind_buffer(C.GL_ELEMENT_ARRAY_BUFFER, ebo) | ||||||
| 	// gl.buffer_data_int(GL_ELEMENT_ARRAY_BUFFER, indices, draw_typ)
 | 	// gl.buffer_data_int(GL_ELEMENT_ARRAY_BUFFER, indices, draw_typ)
 | ||||||
| 	gl.buffer_data_int(GL_ELEMENT_ARRAY_BUFFER, indices, draw_typ) | 	gl.buffer_data_int(C.GL_ELEMENT_ARRAY_BUFFER, indices, draw_typ) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // /////////////////////
 | // /////////////////////
 | ||||||
|  | @ -182,7 +167,7 @@ pub fn gen_buffer() u32 { | ||||||
| pub fn vertex_attrib_pointer(index, size int, typ int, normalized bool, _stride int, _ptr int) { | pub fn vertex_attrib_pointer(index, size int, typ int, normalized bool, _stride int, _ptr int) { | ||||||
| 	mut stride := _stride | 	mut stride := _stride | ||||||
| 	mut ptr := _ptr | 	mut ptr := _ptr | ||||||
| 	if typ == GL_FLOAT { | 	if typ == C.GL_FLOAT { | ||||||
| 		stride *= sizeof(f32) | 		stride *= sizeof(f32) | ||||||
| 		ptr *= sizeof(f32) | 		ptr *= sizeof(f32) | ||||||
| 	} | 	} | ||||||
|  | @ -190,7 +175,7 @@ pub fn vertex_attrib_pointer(index, size int, typ int, normalized bool, _stride | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn tex_param(key, val int) { | pub fn tex_param(key, val int) { | ||||||
| 	C.glTexParameteri(GL_TEXTURE_2D, key, val) | 	C.glTexParameteri(C.GL_TEXTURE_2D, key, val) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn enable(val int) { | pub fn enable(val int) { | ||||||
|  |  | ||||||
|  | @ -28,65 +28,9 @@ const ( | ||||||
| 	DECORATED = 2 | 	DECORATED = 2 | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| import const ( |  | ||||||
| 	GLFW_RESIZABLE |  | ||||||
| 	GLFW_DECORATED |  | ||||||
| 	GLFW_FLOATING  |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| import const ( |  | ||||||
| 	GLFW_KEY_SPACE |  | ||||||
| 	GLFW_KEY_A |  | ||||||
| 	GLFW_KEY_B |  | ||||||
| 	GLFW_KEY_P |  | ||||||
| 	GLFW_KEY_F |  | ||||||
| 	GLFW_KEY_M |  | ||||||
| 	GLFW_KEY_L |  | ||||||
| 	GLFW_KEY_V |  | ||||||
| 	GLFW_KEY_R |  | ||||||
| 	GLFW_KEY_D |  | ||||||
| 	GLFW_KEY_7 |  | ||||||
| 	GLFW_KEY_Z |  | ||||||
| 	GLFW_KEY_UP |  | ||||||
| 	GLFW_KEY_DOWN |  | ||||||
| 	GLFW_KEY_LEFT |  | ||||||
| 	GLFW_KEY_RIGHT |  | ||||||
| 	GLFW_KEY_BACKSPACE |  | ||||||
| 	GLFW_KEY_ENTER |  | ||||||
| 	GLFW_KEY_ESCAPE |  | ||||||
| 	GLFW_KEY_N |  | ||||||
| 	GLFW_KEY_PERIOD |  | ||||||
| 	GLFW_KEY_SLASH |  | ||||||
| 	GLFW_KEY_F5 |  | ||||||
| 	GLFW_KEY_F6 |  | ||||||
| 	GLFW_KEY_MINUS |  | ||||||
| 	GLFW_KEY_EQUAL |  | ||||||
| 	GLFW_KEY_C |  | ||||||
| 	GLFW_KEY_G |  | ||||||
| 	GLFW_KEY_I |  | ||||||
| 	GLFW_KEY_J |  | ||||||
| 	GLFW_KEY_E |  | ||||||
| 	GLFW_KEY_K |  | ||||||
| 	GLFW_KEY_O |  | ||||||
| 	GLFW_KEY_T |  | ||||||
| 	GLFW_KEY_H |  | ||||||
| 	GLFW_KEY_L |  | ||||||
| 	GLFW_KEY_N |  | ||||||
| 	GLFW_KEY_U |  | ||||||
| 	GLFW_KEY_X |  | ||||||
| 	GLFW_KEY_W |  | ||||||
| 	GLFW_KEY_Y |  | ||||||
| 	GLFW_KEY_Q |  | ||||||
| 	GLFW_KEY_RIGHT_BRACKET |  | ||||||
| 	GLFW_KEY_LEFT_BRACKET |  | ||||||
| 	GLFW_KEY_8 |  | ||||||
| 	GLFW_KEY_TAB |  | ||||||
| 	GLFW_KEY_COMMA |  | ||||||
| 	GLFW_KEY_QUESTION |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| const ( | const ( | ||||||
| 	KEY_ESCAPE     = 256 | 	KEY_ESCAPE     = 256 | ||||||
|  | 	key_space     = 32 | ||||||
| 	KEY_LEFT_SUPER = 343 | 	KEY_LEFT_SUPER = 343 | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -159,11 +103,11 @@ pub fn window_hint(key, val int) { | ||||||
| 
 | 
 | ||||||
| pub fn create_window(c WinCfg) *Window { | pub fn create_window(c WinCfg) *Window { | ||||||
| 	if c.borderless { | 	if c.borderless { | ||||||
| 		window_hint(GLFW_RESIZABLE, 0) | 		window_hint(C.GLFW_RESIZABLE, 0) | ||||||
| 		window_hint(GLFW_DECORATED, 0) | 		window_hint(C.GLFW_DECORATED, 0) | ||||||
| 	} | 	} | ||||||
| 	if c.always_on_top { | 	if c.always_on_top { | ||||||
| 		window_hint(GLFW_FLOATING, 1)  | 		window_hint(C.GLFW_FLOATING, 1) | ||||||
| 	} | 	} | ||||||
| 	cwindow := C.glfwCreateWindow(c.width, c.height, c.title.str, 0, 0) | 	cwindow := C.glfwCreateWindow(c.width, c.height, c.title.str, 0, 0) | ||||||
| 	if isnil(cwindow) { | 	if isnil(cwindow) { | ||||||
|  |  | ||||||
|  | @ -8,24 +8,6 @@ pub: | ||||||
| 	proto int | 	proto int | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| import const ( |  | ||||||
| 	AF_INET |  | ||||||
| 	AF_INET6 |  | ||||||
| 	AF_UNSPEC |  | ||||||
| 	SOCK_STREAM |  | ||||||
| 	SOCK_DGRAM |  | ||||||
| 	IPPROTO_UDP |  | ||||||
| 	SOL_SOCKET |  | ||||||
| 	SO_REUSEADDR |  | ||||||
| 	SO_REUSEPORT |  | ||||||
| 	INADDR_ANY |  | ||||||
| 	AI_PASSIVE |  | ||||||
| 	SHUT_RD |  | ||||||
| 	SHUT_WR |  | ||||||
| 	SHUT_RDWR |  | ||||||
| 	SD_BOTH |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| struct C.WSAData { | struct C.WSAData { | ||||||
| mut: | mut: | ||||||
| 	wVersion u16 | 	wVersion u16 | ||||||
|  | @ -84,7 +66,7 @@ pub fn socket(family int, _type int, proto int) ?Socket { | ||||||
| 	one:=1 | 	one:=1 | ||||||
| 	// This is needed so that there are no problems with reusing the
 | 	// This is needed so that there are no problems with reusing the
 | ||||||
| 	// same port after the application exits.
 | 	// same port after the application exits.
 | ||||||
| 	C.setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int))   | 	C.setsockopt(sockfd, C.SOL_SOCKET, C.SO_REUSEADDR, &one, sizeof(int)) | ||||||
| 	if sockfd == 0 { | 	if sockfd == 0 { | ||||||
| 		return error('socket: init failed') | 		return error('socket: init failed') | ||||||
| 	} | 	} | ||||||
|  | @ -98,7 +80,7 @@ pub fn socket(family int, _type int, proto int) ?Socket { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn socket_udp() ?Socket { | pub fn socket_udp() ?Socket { | ||||||
| 	return socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) | 	return socket(C.AF_INET, C.SOCK_DGRAM, C.IPPROTO_UDP) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // set socket options
 | // set socket options
 | ||||||
|  | @ -115,7 +97,7 @@ pub fn (s Socket) bind(port int) ?int { | ||||||
| 	mut addr := C.sockaddr_in{} | 	mut addr := C.sockaddr_in{} | ||||||
| 	addr.sin_family = s.family | 	addr.sin_family = s.family | ||||||
| 	addr.sin_port = C.htons(port) | 	addr.sin_port = C.htons(port) | ||||||
| 	addr.sin_addr.s_addr = C.htonl(INADDR_ANY) | 	addr.sin_addr.s_addr = C.htonl(C.INADDR_ANY) | ||||||
| 	size := 16 // sizeof(C.sockaddr_in)
 | 	size := 16 // sizeof(C.sockaddr_in)
 | ||||||
| 	res := int(C.bind(s.sockfd, &addr, size)) | 	res := int(C.bind(s.sockfd, &addr, size)) | ||||||
| 	if res < 0 { | 	if res < 0 { | ||||||
|  | @ -155,7 +137,7 @@ pub fn listen(port int) ?Socket { | ||||||
| 	$if debug { | 	$if debug { | ||||||
| 		println('net.listen($port)') | 		println('net.listen($port)') | ||||||
| 	} | 	} | ||||||
| 	s := socket(AF_INET, SOCK_STREAM, 0) or { | 	s := socket(C.AF_INET, C.SOCK_STREAM, 0) or { | ||||||
| 		return error(err) | 		return error(err) | ||||||
| 	} | 	} | ||||||
| 	bind_res := s.bind(port) or { | 	bind_res := s.bind(port) or { | ||||||
|  | @ -190,9 +172,9 @@ pub fn (s Socket) accept() ?Socket { | ||||||
| // connect to given addrress and port
 | // connect to given addrress and port
 | ||||||
| pub fn (s Socket) connect(address string, port int) ?int { | pub fn (s Socket) connect(address string, port int) ?int { | ||||||
| 	mut hints := C.addrinfo{} | 	mut hints := C.addrinfo{} | ||||||
| 	hints.ai_family = AF_UNSPEC | 	hints.ai_family = C.AF_UNSPEC | ||||||
| 	hints.ai_socktype = SOCK_STREAM | 	hints.ai_socktype = C.SOCK_STREAM | ||||||
| 	hints.ai_flags = AI_PASSIVE | 	hints.ai_flags = C.AI_PASSIVE | ||||||
| 
 | 
 | ||||||
| 	info := &C.addrinfo{!} | 	info := &C.addrinfo{!} | ||||||
| 	sport := '$port' | 	sport := '$port' | ||||||
|  | @ -209,7 +191,7 @@ pub fn (s Socket) connect(address string, port int) ?int { | ||||||
| 
 | 
 | ||||||
| // helper method to create socket and connect
 | // helper method to create socket and connect
 | ||||||
| pub fn dial(address string, port int) ?Socket { | pub fn dial(address string, port int) ?Socket { | ||||||
| 	s := socket(AF_INET, SOCK_STREAM, 0) or { | 	s := socket(C.AF_INET, C.SOCK_STREAM, 0) or { | ||||||
| 		return error(err) | 		return error(err) | ||||||
| 	} | 	} | ||||||
| 	res := s.connect(address, port) or { | 	res := s.connect(address, port) or { | ||||||
|  | @ -251,10 +233,10 @@ pub fn (s Socket) crecv( buffer byteptr, buffersize int ) int { | ||||||
| pub fn (s Socket) close() ?int { | pub fn (s Socket) close() ?int { | ||||||
| 	mut shutdown_res := 0 | 	mut shutdown_res := 0 | ||||||
| 	$if windows { | 	$if windows { | ||||||
| 		shutdown_res = C.shutdown(s.sockfd, SD_BOTH) | 		shutdown_res = C.shutdown(s.sockfd, C.SD_BOTH) | ||||||
| 	} | 	} | ||||||
| 	$else { | 	$else { | ||||||
| 		shutdown_res = C.shutdown(s.sockfd, SHUT_RDWR) | 		shutdown_res = C.shutdown(s.sockfd, C.SHUT_RDWR) | ||||||
| 	} | 	} | ||||||
| 	// TODO: should shutdown throw an error? close will
 | 	// TODO: should shutdown throw an error? close will
 | ||||||
| 	// continue even if shutdown failed
 | 	// continue even if shutdown failed
 | ||||||
|  |  | ||||||
|  | @ -18,10 +18,6 @@ pub: | ||||||
| 	vals []string | 	vals []string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| import const ( |  | ||||||
| 	CONNECTION_OK |  | ||||||
| )  |  | ||||||
| 
 |  | ||||||
| struct C.PGResult { } | struct C.PGResult { } | ||||||
| 
 | 
 | ||||||
| struct Config { | struct Config { | ||||||
|  | @ -41,7 +37,7 @@ pub fn connect(config pg.Config) DB { | ||||||
| 	conninfo := 'host=$config.host user=$config.user dbname=$config.dbname' | 	conninfo := 'host=$config.host user=$config.user dbname=$config.dbname' | ||||||
| 	conn:=C.PQconnectdb(conninfo.str) | 	conn:=C.PQconnectdb(conninfo.str) | ||||||
| 	status := C.PQstatus(conn) | 	status := C.PQstatus(conn) | ||||||
| 	if status != CONNECTION_OK {  | 	if status != C.CONNECTION_OK {  | ||||||
| 		error_msg := C.PQerrorMessage(conn)  | 		error_msg := C.PQerrorMessage(conn)  | ||||||
| 		eprintln('Connection to a PG database failed: ' + string(error_msg))  | 		eprintln('Connection to a PG database failed: ' + string(error_msg))  | ||||||
| 		exit(1)  | 		exit(1)  | ||||||
|  |  | ||||||
|  | @ -20,14 +20,6 @@ mut: | ||||||
| 	ext         string | 	ext         string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| import const ( |  | ||||||
| 	GL_RGBA |  | ||||||
| 	GL_RGB |  | ||||||
| 	GL_UNSIGNED_BYTE |  | ||||||
| 	GL_TEXTURE_2D |  | ||||||
| 	STBI_rgb_alpha |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| pub fn load(path string) Image { | pub fn load(path string) Image { | ||||||
| 	ext := path.all_after('.') | 	ext := path.all_after('.') | ||||||
| 	mut res := Image { | 	mut res := Image { | ||||||
|  | @ -35,14 +27,10 @@ pub fn load(path string) Image { | ||||||
| 		ext: ext | 		ext: ext | ||||||
| 		data: 0 | 		data: 0 | ||||||
| 	} | 	} | ||||||
| 	if ext == 'png' { | 	flag := if ext == 'png' { C.STBI_rgb_alpha } else { 0 } | ||||||
| 		res.data = C.stbi_load(path.str, &res.width, &res.height, &res.nr_channels, STBI_rgb_alpha) | 	res.data = C.stbi_load(path.str, &res.width, &res.height,	&res.nr_channels, flag) | ||||||
| 	} |  | ||||||
| 	else { |  | ||||||
| 		res.data = C.stbi_load(path.str, &res.width, &res.height, &res.nr_channels, 0) |  | ||||||
| 	} |  | ||||||
| 	if isnil(res.data) { | 	if isnil(res.data) { | ||||||
| 		println('stbi cant load') | 		println('stbi image failed to load') | ||||||
| 		exit(1) | 		exit(1) | ||||||
| 	} | 	} | ||||||
| 	return res | 	return res | ||||||
|  | @ -53,12 +41,12 @@ pub fn (img Image) free() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn (img Image) tex_image_2d() { | pub fn (img Image) tex_image_2d() { | ||||||
| 	mut rgb_flag := GL_RGB | 	mut rgb_flag := C.GL_RGB | ||||||
| 	if img.ext == 'png' { | 	if img.ext == 'png' { | ||||||
| 		rgb_flag = GL_RGBA | 		rgb_flag = C.GL_RGBA | ||||||
| 	} | 	} | ||||||
| 	C.glTexImage2D(GL_TEXTURE_2D, 0, rgb_flag, img.width, img.height, 0, rgb_flag, GL_UNSIGNED_BYTE, | 	C.glTexImage2D(C.GL_TEXTURE_2D, 0, rgb_flag, img.width, img.height, 0, | ||||||
| 	img.data) | 		rgb_flag, C.GL_UNSIGNED_BYTE,	img.data) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn set_flip_vertically_on_load(val bool) { | pub fn set_flip_vertically_on_load(val bool) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue