mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
remove "import const" everywhere
This commit is contained in:
parent
dcfc9eb1a1
commit
f61b14584a
@ -135,7 +135,7 @@ fn main() {
|
||||
})
|
||||
ft: 0
|
||||
}
|
||||
game.gg.window.set_user_ptr(game) // TODO remove this when `window_user_ptr:` works
|
||||
game.gg.window.set_user_ptr(game) // TODO remove this when `window_user_ptr:` works
|
||||
game.init_game()
|
||||
game.gg.window.onkeydown(key_down)
|
||||
go game.run() // Run the game loop in a new thread
|
||||
@ -374,7 +374,7 @@ fn key_down(wnd voidptr, key, code, action, mods int) {
|
||||
switch key {
|
||||
case glfw.KEY_ESCAPE:
|
||||
glfw.set_should_close(wnd, true)
|
||||
case GLFW_KEY_SPACE:
|
||||
case glfw.key_space:
|
||||
if game.state == .running {
|
||||
game.state = .paused
|
||||
} else if game.state == .paused {
|
||||
|
@ -8,10 +8,6 @@ import math
|
||||
|
||||
#include <sys/syscall.h>
|
||||
|
||||
import const(
|
||||
SYS_getrandom
|
||||
)
|
||||
|
||||
// const (
|
||||
// SYS_getrandom = 278 // AArch65
|
||||
// SYS_getrandom = 384 // ARM
|
||||
@ -47,5 +43,5 @@ fn _getrandom(bytes_needed int, buffer voidptr) int {
|
||||
if bytes_needed > ReadBatchSize {
|
||||
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
|
||||
|
||||
// import const (
|
||||
// kSecRandomDefault
|
||||
// errSecSuccess
|
||||
// )
|
||||
|
||||
const (
|
||||
kSecRandomDefault = 0
|
||||
errSecSuccess = 0
|
||||
)
|
||||
|
||||
pub fn read(bytes_needed int) ?[]byte {
|
||||
mut buffer := malloc(bytes_needed)
|
||||
status := C.SecRandomCopyBytes(kSecRandomDefault, bytes_needed, buffer)
|
||||
if status != errSecSuccess {
|
||||
status := C.SecRandomCopyBytes(0, bytes_needed, buffer)
|
||||
if status != 0 {
|
||||
return ReadError
|
||||
}
|
||||
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,
|
||||
0, C.GL_RED, C.GL_UNSIGNED_BYTE, face.glyph.bitmap.buffer)
|
||||
// Set texture options
|
||||
C.glTexParameteri(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(GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_LINEAR)
|
||||
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_WRAP_S, C.GL_CLAMP_TO_EDGE)
|
||||
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_WRAP_T, C.GL_CLAMP_TO_EDGE)
|
||||
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)
|
||||
fgleft := face.glyph.bitmap_left
|
||||
fgtop := face.glyph.bitmap_top
|
||||
@ -146,7 +146,7 @@ pub fn new_context(cfg gg.Cfg) *Context {
|
||||
gl.viewport(0, 0, width, height)
|
||||
*/
|
||||
// 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)
|
||||
shader := gl.new_shader('text')
|
||||
shader.use()
|
||||
@ -209,10 +209,10 @@ pub fn new_context(cfg gg.Cfg) *Context {
|
||||
println('new gg text context vao=$vao')
|
||||
vbo := gl.gen_buffer()
|
||||
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);
|
||||
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);
|
||||
// gl.bind_buffer(GL_ARRAY_BUFFER, uint(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
|
||||
C.glBindTexture(C.GL_TEXTURE_2D, ch.texture_id)
|
||||
// Update content of VBO memory
|
||||
gl.bind_buffer(GL_ARRAY_BUFFER, ctx.vbo)
|
||||
gl.bind_buffer(C.GL_ARRAY_BUFFER, ctx.vbo)
|
||||
// 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
|
||||
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)
|
||||
// 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)
|
||||
|
168
vlib/gg/gg.v
168
vlib/gg/gg.v
@ -5,30 +5,22 @@
|
||||
module gg
|
||||
|
||||
import stbi
|
||||
import glm
|
||||
import glm
|
||||
import gl
|
||||
import gx
|
||||
import os
|
||||
import glfw
|
||||
import glfw
|
||||
|
||||
struct Vec2 {
|
||||
pub:
|
||||
pub:
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
import const (
|
||||
GL_STATIC_DRAW
|
||||
GL_FLOAT
|
||||
GL_FALSE
|
||||
GL_UNSIGNED_INT
|
||||
GL_INT
|
||||
)
|
||||
|
||||
pub fn vec2(x, y int) Vec2 {
|
||||
res := Vec2 {
|
||||
x: x
|
||||
y: y
|
||||
x: x
|
||||
y: y
|
||||
}
|
||||
return res
|
||||
}
|
||||
@ -41,19 +33,19 @@ pub fn init() {
|
||||
|
||||
|
||||
struct Cfg {
|
||||
pub:
|
||||
pub:
|
||||
width int
|
||||
height int
|
||||
use_ortho bool
|
||||
use_ortho bool
|
||||
retina bool
|
||||
|
||||
|
||||
font_size int
|
||||
font_path string
|
||||
create_window bool
|
||||
window_user_ptr voidptr
|
||||
window_title string
|
||||
always_on_top bool
|
||||
scale int
|
||||
create_window bool
|
||||
window_user_ptr voidptr
|
||||
window_title string
|
||||
always_on_top bool
|
||||
scale int
|
||||
}
|
||||
|
||||
struct GG {
|
||||
@ -68,29 +60,29 @@ struct GG {
|
||||
line_vbo u32
|
||||
vbo u32
|
||||
scale int // retina = 2 , normal = 1
|
||||
pub mut:
|
||||
window *glfw.Window
|
||||
render_fn fn()
|
||||
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 {
|
||||
mut window := &glfw.Window{!}
|
||||
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
|
||||
always_on_top: cfg.always_on_top
|
||||
title: cfg.window_title
|
||||
width: cfg.width
|
||||
height: cfg.height
|
||||
ptr: cfg.window_user_ptr
|
||||
always_on_top: cfg.always_on_top
|
||||
})
|
||||
window.make_context_current()
|
||||
init()
|
||||
}
|
||||
init()
|
||||
}
|
||||
shader := gl.new_shader('simple')
|
||||
shader.use()
|
||||
if cfg.use_ortho {
|
||||
if cfg.use_ortho {
|
||||
projection := glm.ortho(0, cfg.width, cfg.height, 0)
|
||||
shader.set_mat4('projection', projection)
|
||||
}
|
||||
@ -113,15 +105,15 @@ pub fn new_context(cfg Cfg) *GG {
|
||||
//gl.bind_buffer(GL_ARRAY_BUFFER, VBO)
|
||||
//gl.enable_vertex_attrib_array(0)
|
||||
//gl.vertex_attrib_pointer(0, 4, GL_FLOAT, false, 4, 0)
|
||||
todo_remove_me(cfg, scale)
|
||||
todo_remove_me(cfg, scale)
|
||||
return &GG {
|
||||
shader: shader
|
||||
width: cfg.width
|
||||
height: cfg.height
|
||||
vao: vao
|
||||
vbo: vbo
|
||||
window: window
|
||||
|
||||
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),
|
||||
@ -133,25 +125,25 @@ pub fn new_context(cfg Cfg) *GG {
|
||||
//return ctx
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
pub fn (gg &GG) render_loop() bool {
|
||||
for !gg.window.show_close() {
|
||||
gg.render_fn()
|
||||
for !gg.window.show_close() {
|
||||
gg.render_fn()
|
||||
gg.window.swap_buffers()
|
||||
glfw.wait_events()
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn clear(color gx.Color) {
|
||||
pub fn clear(color gx.Color) {
|
||||
gl.clear()
|
||||
gl.clear_color(255, 255, 255, 255)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (gg &GG) render() {
|
||||
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')
|
||||
@ -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),
|
||||
// and then configure vertex attributes(s).
|
||||
gl.bind_vao(ctx.vao)
|
||||
gl.set_vbo(ctx.vbo, vertices, GL_STATIC_DRAW)
|
||||
gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 3, 0)
|
||||
gl.set_vbo(ctx.vbo, vertices, C.GL_STATIC_DRAW)
|
||||
gl.vertex_attrib_pointer(0, 3, C.GL_FLOAT, false, 3, 0)
|
||||
gl.enable_vertex_attrib_array(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,
|
||||
@ -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.
|
||||
// gl.bind_vertex_array(uint(0))
|
||||
// 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) {
|
||||
@ -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,
|
||||
] !
|
||||
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
|
||||
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)
|
||||
// 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)
|
||||
// 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.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) {
|
||||
@ -214,9 +206,9 @@ pub fn (ctx &GG) draw_rect(x, y, w, h f32, c gx.Color) {
|
||||
ctx.draw_rect2(x, y, w, h, c)
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
fn (ctx mut GG) init_rect_vao() {
|
||||
|
||||
|
||||
ctx.rect_vao = gl.gen_vertex_array()
|
||||
ctx.rect_vbo = gl.gen_buffer()
|
||||
vertices := [
|
||||
@ -230,11 +222,11 @@ fn (ctx mut GG) init_rect_vao() {
|
||||
1, 2, 3// second triangle
|
||||
] !
|
||||
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()
|
||||
// ///////
|
||||
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) {
|
||||
C.glDeleteBuffers(1, &ctx.vao)
|
||||
@ -244,9 +236,9 @@ pub fn (ctx &GG) draw_rect2(x, y, w, h f32, c gx.Color) {
|
||||
ctx.shader.set_int('has_texture', 0)
|
||||
// 4--1
|
||||
// 3--2
|
||||
$if linux {
|
||||
$if linux {
|
||||
// y += h
|
||||
}
|
||||
}
|
||||
vertices := [
|
||||
x + w, y, 0,
|
||||
x + w, y + h, 0,
|
||||
@ -258,20 +250,20 @@ pub fn (ctx &GG) draw_rect2(x, y, w, h f32, c gx.Color) {
|
||||
1, 2, 3// second triangle
|
||||
] !
|
||||
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()
|
||||
// ///////
|
||||
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.bind_vao(ctx.rect_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)
|
||||
}
|
||||
|
||||
fn todo_remove_me(cfg Cfg, scale int) {
|
||||
fn todo_remove_me(cfg Cfg, scale int) {
|
||||
// Can only have text in ortho mode
|
||||
if !cfg.use_ortho {
|
||||
return
|
||||
@ -279,8 +271,8 @@ fn todo_remove_me(cfg Cfg, scale int) {
|
||||
mut width := cfg.width * scale
|
||||
mut height := cfg.height * scale
|
||||
font_size := cfg.font_size * scale
|
||||
gl.enable(GL_BLEND)
|
||||
//# glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
gl.enable(C.GL_BLEND)
|
||||
//# glBlendFunc(C.GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
shader := gl.new_shader('text')
|
||||
shader.use()
|
||||
projection := glm.ortho(0, width, 0, height)// 0 at BOT
|
||||
@ -291,18 +283,18 @@ fn todo_remove_me(cfg Cfg, scale int) {
|
||||
//println('new gg text context VAO=$VAO')
|
||||
vbo := gl.gen_buffer()
|
||||
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.vertex_attrib_pointer(0, 4, GL_FLOAT, false, 4, 0)
|
||||
gl.vertex_attrib_pointer(0, 4, C.GL_FLOAT, false, 4, 0)
|
||||
}
|
||||
|
||||
fn update() {
|
||||
// # ui__post_empty_event();
|
||||
}
|
||||
|
||||
pub fn post_empty_event() {
|
||||
glfw.post_empty_event()
|
||||
}
|
||||
pub fn post_empty_event() {
|
||||
glfw.post_empty_event()
|
||||
}
|
||||
|
||||
pub fn (c GG) circle(x, y, r int) {
|
||||
}
|
||||
@ -372,7 +364,7 @@ pub fn create_image(file string) u32 {
|
||||
img := stbi.load(file)
|
||||
gl.bind_2d_texture(texture)
|
||||
img.tex_image_2d()
|
||||
gl.generate_mipmap(GL_TEXTURE_2D)
|
||||
gl.generate_mipmap(C.GL_TEXTURE_2D)
|
||||
img.free()
|
||||
// println('gg end')
|
||||
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)
|
||||
vertices := [f32(x), f32(y), f32(x2), f32(y2)] !
|
||||
gl.bind_vao(ctx.vao)
|
||||
gl.set_vbo(ctx.vbo, vertices, GL_STATIC_DRAW)
|
||||
gl.vertex_attrib_pointer(0, 2, GL_FLOAT, false, 2, 0)
|
||||
gl.set_vbo(ctx.vbo, vertices, C.GL_STATIC_DRAW)
|
||||
gl.vertex_attrib_pointer(0, 2, C.GL_FLOAT, false, 2, 0)
|
||||
gl.enable_vertex_attrib_array(0)
|
||||
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) {
|
||||
@ -425,18 +417,18 @@ pub fn (ctx &GG) draw_image(x, y, w, h f32, tex_id u32) {
|
||||
// VAO := gl.gen_vertex_array()
|
||||
// VBO := gl.gen_buffer()
|
||||
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()
|
||||
gl.set_ebo(ebo, indices, GL_STATIC_DRAW)
|
||||
gl.vertex_attrib_pointer(0, 3, GL_FLOAT, false, 8, 0)
|
||||
gl.set_ebo(ebo, indices, C.GL_STATIC_DRAW)
|
||||
gl.vertex_attrib_pointer(0, 3, C.GL_FLOAT, false, 8, 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.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.bind_2d_texture(u32(tex_id))
|
||||
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) {
|
||||
|
@ -9,15 +9,6 @@ import gx
|
||||
import glm
|
||||
|
||||
// import darwin
|
||||
import const (
|
||||
GL_VERTEX_SHADER
|
||||
GL_FRAGMENT_SHADER
|
||||
GL_ARRAY_BUFFER
|
||||
GL_TRIANGLES
|
||||
GL_CULL_FACE
|
||||
GL_BLEND
|
||||
GL_LINES
|
||||
)
|
||||
|
||||
struct Shader {
|
||||
program_id int
|
||||
@ -43,7 +34,7 @@ uniform sampler2D text;
|
||||
uniform vec3 textColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
{
|
||||
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r);
|
||||
color = vec4(textColor, 1.0) * sampled;
|
||||
} '
|
||||
@ -51,11 +42,11 @@ void main()
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aColor;
|
||||
layout (location = 2) in vec2 aTexCoord;
|
||||
layout (location = 2) in vec2 aTexCoord;
|
||||
|
||||
|
||||
out vec3 ourColor;
|
||||
out vec2 TexCoord;
|
||||
out vec2 TexCoord;
|
||||
|
||||
uniform mat4 projection;
|
||||
|
||||
@ -64,8 +55,8 @@ void main() {
|
||||
// gl_Position = vec4(aPos, 1.0);
|
||||
|
||||
ourColor = aColor;
|
||||
//TexCoord = vec2(aTexCoord.x, aTexCoord.y);
|
||||
TexCoord = aTexCoord;
|
||||
//TexCoord = vec2(aTexCoord.x, aTexCoord.y);
|
||||
TexCoord = aTexCoord;
|
||||
}
|
||||
'
|
||||
SIMPLE_FRAG = '#version 330 core
|
||||
@ -73,30 +64,30 @@ void main() {
|
||||
out vec4 FragColor;
|
||||
uniform vec3 color;
|
||||
|
||||
uniform bool has_texture;
|
||||
uniform bool has_texture;
|
||||
|
||||
in vec3 ourColor;
|
||||
in vec2 TexCoord;
|
||||
|
||||
uniform sampler2D ourTexture;
|
||||
|
||||
|
||||
|
||||
void main() {
|
||||
// FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||
// FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
if (has_texture) {
|
||||
if (has_texture) {
|
||||
FragColor = texture(ourTexture, TexCoord);
|
||||
|
||||
} else {
|
||||
|
||||
} else {
|
||||
FragColor = vec4(color, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
)
|
||||
|
||||
pub fn new_shader(name string) Shader {
|
||||
// TODO This is not used, remove
|
||||
mut dir := ''
|
||||
// TODO This is not used, remove
|
||||
mut dir := ''
|
||||
// Already have absolute path
|
||||
if name.starts_with('/') {
|
||||
dir = ''
|
||||
@ -118,7 +109,7 @@ pub fn new_shader(name string) Shader {
|
||||
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.compile_shader(vertex_shader)
|
||||
if gl.shader_compile_status(vertex_shader) == 0 {
|
||||
@ -130,7 +121,7 @@ pub fn new_shader(name string) Shader {
|
||||
}
|
||||
// fragment shader
|
||||
// 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.compile_shader(fragment_shader)
|
||||
if gl.shader_compile_status(fragment_shader) == 0 {
|
||||
|
47
vlib/gl/gl.v
47
vlib/gl/gl.v
@ -4,24 +4,9 @@
|
||||
|
||||
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
|
||||
#include "glad.h"
|
||||
#flag @VROOT/thirdparty/glad/glad.o
|
||||
#flag @VROOT/thirdparty/glad/glad.o
|
||||
|
||||
pub fn init_glad() {
|
||||
ok := C.gladLoadGL()
|
||||
@ -40,7 +25,7 @@ pub fn clear_color(r, g, b, a int) {
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -61,7 +46,7 @@ pub fn compile_shader(shader int) {
|
||||
|
||||
pub fn shader_compile_status(shader int) int {
|
||||
success := 0
|
||||
C.glGetShaderiv(shader, GL_COMPILE_STATUS, &success)
|
||||
C.glGetShaderiv(shader, C.GL_COMPILE_STATUS, &success)
|
||||
return success
|
||||
}
|
||||
|
||||
@ -76,7 +61,7 @@ pub fn link_program(program int) {
|
||||
|
||||
pub fn get_program_link_status(program int) int {
|
||||
success := 0
|
||||
C.glGetProgramiv(program, GL_LINK_STATUS, &success)
|
||||
C.glGetProgramiv(program, C.GL_LINK_STATUS, &success)
|
||||
return success
|
||||
}
|
||||
|
||||
@ -115,7 +100,7 @@ pub fn active_texture(t int) {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -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) {
|
||||
gl.bind_buffer(GL_ARRAY_BUFFER, vbo)
|
||||
gl.buffer_data_f32(GL_ARRAY_BUFFER, vertices, draw_typ)
|
||||
gl.bind_buffer(C.GL_ARRAY_BUFFER, vbo)
|
||||
gl.buffer_data_f32(C.GL_ARRAY_BUFFER, vertices, draw_typ)
|
||||
}
|
||||
|
||||
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(C.GL_ELEMENT_ARRAY_BUFFER, indices, draw_typ)
|
||||
}
|
||||
|
||||
// /////////////////////
|
||||
@ -166,7 +151,7 @@ pub fn use_program(program int) {
|
||||
pub fn gen_vertex_array() u32 {
|
||||
vao := u32(0)
|
||||
C.glGenVertexArrays(1, &vao)
|
||||
return vao
|
||||
return vao
|
||||
}
|
||||
|
||||
pub fn enable_vertex_attrib_array(n int) {
|
||||
@ -176,13 +161,13 @@ pub fn enable_vertex_attrib_array(n int) {
|
||||
pub fn gen_buffer() u32 {
|
||||
vbo := u32(0)
|
||||
C.glGenBuffers(1, &vbo)
|
||||
return vbo
|
||||
return vbo
|
||||
}
|
||||
|
||||
pub fn vertex_attrib_pointer(index, size int, typ int, normalized bool, _stride int, _ptr int) {
|
||||
mut stride := _stride
|
||||
mut ptr := _ptr
|
||||
if typ == GL_FLOAT {
|
||||
pub fn vertex_attrib_pointer(index, size int, typ int, normalized bool, _stride int, _ptr int) {
|
||||
mut stride := _stride
|
||||
mut ptr := _ptr
|
||||
if typ == C.GL_FLOAT {
|
||||
stride *= 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) {
|
||||
C.glTexParameteri(GL_TEXTURE_2D, key, val)
|
||||
C.glTexParameteri(C.GL_TEXTURE_2D, key, val)
|
||||
}
|
||||
|
||||
pub fn enable(val int) {
|
||||
|
@ -6,8 +6,8 @@ module glfw
|
||||
|
||||
import gl
|
||||
|
||||
#flag -I @VROOT/thirdparty/glfw
|
||||
#flag -L @VROOT/thirdparty/glfw
|
||||
#flag -I @VROOT/thirdparty/glfw
|
||||
#flag -L @VROOT/thirdparty/glfw
|
||||
|
||||
// Debugging a custom build
|
||||
//-#flag darwin -L/var/tmp/glfw/src/
|
||||
@ -17,7 +17,7 @@ import gl
|
||||
|
||||
#flag darwin -lglfw
|
||||
#flag linux -lglfw
|
||||
#flag windows -lglfw3
|
||||
#flag windows -lglfw3
|
||||
#include <GLFW/glfw3.h>
|
||||
// #flag darwin -framework Carbon
|
||||
// #flag darwin -framework Cocoa
|
||||
@ -28,65 +28,9 @@ const (
|
||||
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 (
|
||||
KEY_ESCAPE = 256
|
||||
key_space = 32
|
||||
KEY_LEFT_SUPER = 343
|
||||
)
|
||||
|
||||
@ -106,7 +50,7 @@ struct WinCfg {
|
||||
is_modal int
|
||||
is_browser bool
|
||||
url string
|
||||
always_on_top bool
|
||||
always_on_top bool
|
||||
}
|
||||
|
||||
// data *C.GLFWwindow
|
||||
@ -134,10 +78,10 @@ type clickpubfn fn (window voidptr, button, action, mods int)
|
||||
|
||||
pub fn init() {
|
||||
C.glfwInit()
|
||||
C.glfwWindowHint(C.GLFW_CONTEXT_VERSION_MAJOR, 3)
|
||||
C.glfwWindowHint(C.GLFW_CONTEXT_VERSION_MINOR, 3)
|
||||
C.glfwWindowHint(C.GLFW_OPENGL_FORWARD_COMPAT, C.GL_TRUE)
|
||||
C.glfwWindowHint(C.GLFW_OPENGL_PROFILE, C.GLFW_OPENGL_CORE_PROFILE)
|
||||
C.glfwWindowHint(C.GLFW_CONTEXT_VERSION_MAJOR, 3)
|
||||
C.glfwWindowHint(C.GLFW_CONTEXT_VERSION_MINOR, 3)
|
||||
C.glfwWindowHint(C.GLFW_OPENGL_FORWARD_COMPAT, C.GL_TRUE)
|
||||
C.glfwWindowHint(C.GLFW_OPENGL_PROFILE, C.GLFW_OPENGL_CORE_PROFILE)
|
||||
}
|
||||
|
||||
pub fn (w &Window) destroy() {
|
||||
@ -159,14 +103,14 @@ pub fn window_hint(key, val int) {
|
||||
|
||||
pub fn create_window(c WinCfg) *Window {
|
||||
if c.borderless {
|
||||
window_hint(GLFW_RESIZABLE, 0)
|
||||
window_hint(GLFW_DECORATED, 0)
|
||||
window_hint(C.GLFW_RESIZABLE, 0)
|
||||
window_hint(C.GLFW_DECORATED, 0)
|
||||
}
|
||||
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)
|
||||
if isnil(cwindow) {
|
||||
if isnil(cwindow) {
|
||||
println('failed to create glfw window')
|
||||
C.glfwTerminate()
|
||||
}
|
||||
@ -248,7 +192,7 @@ pub fn get_time() f64 {
|
||||
}
|
||||
|
||||
pub fn key_pressed(wnd voidptr, key int) bool {
|
||||
return int(C.glfwGetKey(wnd, key)) == C.GLFW_PRESS
|
||||
return int(C.glfwGetKey(wnd, key)) == C.GLFW_PRESS
|
||||
}
|
||||
|
||||
pub fn (w &Window) get_clipboard_text() string {
|
||||
@ -279,15 +223,15 @@ pub fn (w &Window) set_user_ptr(ptr voidptr) {
|
||||
|
||||
struct C.GLFWvidmode {
|
||||
width int
|
||||
height int
|
||||
}
|
||||
height int
|
||||
}
|
||||
|
||||
pub fn C.glfwGetVideoMode() *C.GLFWvidmode
|
||||
|
||||
pub fn get_monitor_size() Size {
|
||||
//# GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||
mode := C.glfwGetVideoMode(C.glfwGetPrimaryMonitor())
|
||||
return Size{mode.width, mode.height}
|
||||
mode := C.glfwGetVideoMode(C.glfwGetPrimaryMonitor())
|
||||
return Size{mode.width, mode.height}
|
||||
}
|
||||
|
||||
pub fn (size Size) str() string {
|
||||
|
@ -8,24 +8,6 @@ pub:
|
||||
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 {
|
||||
mut:
|
||||
wVersion u16
|
||||
@ -81,10 +63,10 @@ pub fn socket(family int, _type int, proto int) ?Socket {
|
||||
}
|
||||
|
||||
sockfd := C.socket(family, _type, proto)
|
||||
one:=1
|
||||
// This is needed so that there are no problems with reusing the
|
||||
// same port after the application exits.
|
||||
C.setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int))
|
||||
one:=1
|
||||
// This is needed so that there are no problems with reusing the
|
||||
// same port after the application exits.
|
||||
C.setsockopt(sockfd, C.SOL_SOCKET, C.SO_REUSEADDR, &one, sizeof(int))
|
||||
if sockfd == 0 {
|
||||
return error('socket: init failed')
|
||||
}
|
||||
@ -98,7 +80,7 @@ pub fn socket(family int, _type int, proto int) ?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
|
||||
@ -115,7 +97,7 @@ pub fn (s Socket) bind(port int) ?int {
|
||||
mut addr := C.sockaddr_in{}
|
||||
addr.sin_family = s.family
|
||||
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)
|
||||
res := int(C.bind(s.sockfd, &addr, size))
|
||||
if res < 0 {
|
||||
@ -127,14 +109,14 @@ pub fn (s Socket) bind(port int) ?int {
|
||||
// put socket into passive mode and wait to receive
|
||||
pub fn (s Socket) listen() ?int {
|
||||
backlog := 128
|
||||
res := int(C.listen(s.sockfd, backlog))
|
||||
res := int(C.listen(s.sockfd, backlog))
|
||||
if res < 0 {
|
||||
return error('socket: listen failed')
|
||||
}
|
||||
$if debug {
|
||||
println('listen res = $res')
|
||||
}
|
||||
return res
|
||||
return res
|
||||
}
|
||||
|
||||
// put socket into passive mode with user specified backlog and wait to receive
|
||||
@ -155,7 +137,7 @@ pub fn listen(port int) ?Socket {
|
||||
$if debug {
|
||||
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)
|
||||
}
|
||||
bind_res := s.bind(port) or {
|
||||
@ -190,9 +172,9 @@ pub fn (s Socket) accept() ?Socket {
|
||||
// connect to given addrress and port
|
||||
pub fn (s Socket) connect(address string, port int) ?int {
|
||||
mut hints := C.addrinfo{}
|
||||
hints.ai_family = AF_UNSPEC
|
||||
hints.ai_socktype = SOCK_STREAM
|
||||
hints.ai_flags = AI_PASSIVE
|
||||
hints.ai_family = C.AF_UNSPEC
|
||||
hints.ai_socktype = C.SOCK_STREAM
|
||||
hints.ai_flags = C.AI_PASSIVE
|
||||
|
||||
info := &C.addrinfo{!}
|
||||
sport := '$port'
|
||||
@ -209,7 +191,7 @@ pub fn (s Socket) connect(address string, port int) ?int {
|
||||
|
||||
// helper method to create socket and connect
|
||||
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)
|
||||
}
|
||||
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 {
|
||||
mut shutdown_res := 0
|
||||
$if windows {
|
||||
shutdown_res = C.shutdown(s.sockfd, SD_BOTH)
|
||||
shutdown_res = C.shutdown(s.sockfd, C.SD_BOTH)
|
||||
}
|
||||
$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
|
||||
// continue even if shutdown failed
|
||||
@ -276,14 +258,14 @@ pub fn (s Socket) close() ?int {
|
||||
return 0
|
||||
}
|
||||
|
||||
const (
|
||||
const (
|
||||
MAX_READ = 400
|
||||
)
|
||||
)
|
||||
pub fn (s Socket) write(str string) {
|
||||
line := '$str\r\n'
|
||||
C.write(s.sockfd, line.str, line.len)
|
||||
}
|
||||
|
||||
|
||||
pub fn (s Socket) read_line() string {
|
||||
mut res := ''
|
||||
for {
|
||||
@ -307,7 +289,7 @@ pub fn (s Socket) read_line() string {
|
||||
}
|
||||
// println('resp len=$numbytes')
|
||||
buf[n] = `\0`
|
||||
// C.printf('!!buf= "%s" n=%d\n', buf,n)
|
||||
// C.printf('!!buf= "%s" n=%d\n', buf,n)
|
||||
line := string(buf)
|
||||
res += line
|
||||
// Reached a newline. That's an end of an IRC message
|
||||
@ -324,4 +306,4 @@ pub fn (s Socket) read_line() string {
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -18,10 +18,6 @@ pub:
|
||||
vals []string
|
||||
}
|
||||
|
||||
import const (
|
||||
CONNECTION_OK
|
||||
)
|
||||
|
||||
struct C.PGResult { }
|
||||
|
||||
struct Config {
|
||||
@ -41,7 +37,7 @@ pub fn connect(config pg.Config) DB {
|
||||
conninfo := 'host=$config.host user=$config.user dbname=$config.dbname'
|
||||
conn:=C.PQconnectdb(conninfo.str)
|
||||
status := C.PQstatus(conn)
|
||||
if status != CONNECTION_OK {
|
||||
if status != C.CONNECTION_OK {
|
||||
error_msg := C.PQerrorMessage(conn)
|
||||
eprintln('Connection to a PG database failed: ' + string(error_msg))
|
||||
exit(1)
|
||||
|
@ -20,14 +20,6 @@ mut:
|
||||
ext string
|
||||
}
|
||||
|
||||
import const (
|
||||
GL_RGBA
|
||||
GL_RGB
|
||||
GL_UNSIGNED_BYTE
|
||||
GL_TEXTURE_2D
|
||||
STBI_rgb_alpha
|
||||
)
|
||||
|
||||
pub fn load(path string) Image {
|
||||
ext := path.all_after('.')
|
||||
mut res := Image {
|
||||
@ -35,14 +27,10 @@ pub fn load(path string) Image {
|
||||
ext: ext
|
||||
data: 0
|
||||
}
|
||||
if ext == 'png' {
|
||||
res.data = C.stbi_load(path.str, &res.width, &res.height, &res.nr_channels, STBI_rgb_alpha)
|
||||
}
|
||||
else {
|
||||
res.data = C.stbi_load(path.str, &res.width, &res.height, &res.nr_channels, 0)
|
||||
}
|
||||
flag := if ext == 'png' { C.STBI_rgb_alpha } else { 0 }
|
||||
res.data = C.stbi_load(path.str, &res.width, &res.height, &res.nr_channels, flag)
|
||||
if isnil(res.data) {
|
||||
println('stbi cant load')
|
||||
println('stbi image failed to load')
|
||||
exit(1)
|
||||
}
|
||||
return res
|
||||
@ -53,12 +41,12 @@ pub fn (img Image) free() {
|
||||
}
|
||||
|
||||
pub fn (img Image) tex_image_2d() {
|
||||
mut rgb_flag := GL_RGB
|
||||
mut rgb_flag := C.GL_RGB
|
||||
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,
|
||||
img.data)
|
||||
C.glTexImage2D(C.GL_TEXTURE_2D, 0, rgb_flag, img.width, img.height, 0,
|
||||
rgb_flag, C.GL_UNSIGNED_BYTE, img.data)
|
||||
}
|
||||
|
||||
pub fn set_flip_vertically_on_load(val bool) {
|
||||
|
Loading…
Reference in New Issue
Block a user