v
v copied to clipboard
[1] 1340 segmentation fault
V version: V 0.1.18
OS: Windows 10 msys2
What did you do?
import (
gl
glfw
time
)
fn main() {
glfw.init()
win_cfg := glfw.WinCfg{
width:500,
height:500,
title:'trangle',
}
window := glfw.create_window(win_cfg)
window.make_context_current()
gl.init_glad()
gl.viewport(0,0,500,500)
shader := gl.new_shader('text')
vertices := [
-0.5, -0.5, 0.0, // left
0.5, -0.5, 0.0, // right
0.0, 0.5, 0.0 // top
]
vbo := gl.gen_buffer()
gl.bind_vao(vbo)
gl.bind_buffer(C.GL_ARRAY_BUFFER,vbo)
gl.buffer_data(C.GL_ARRAY_BUFFER,vertices.len,&vertices,C.GL_STATIC_DRAW)
gl.vertex_attrib_pointer(0,3,C.GL_FLOAT,false,0,0)
gl.enable_vertex_attrib_array(0)
gl.bind_buffer(C.GL_ARRAY_BUFFER,vbo)
gl.bind_vao(u32(0))
for !window.should_close() {
gl.clear_color(255, 255, 255,1)
gl.clear()
shader.use()
gl.bind_vao(vbo)
gl.draw_arrays(C.GL_TRIANGLES, 0, 3)
window.swap_buffers()
glfw.poll_events()
time.sleep_ms(100)
}
}
the code compiled ok,but error when runing,it is ok on mac.
What did you expect to see?
show a window
What did you see instead?
close with error "[1] 1340 segmentation fault".
On Arch Linux, with the latest commit (https://github.com/vlang/v/commit/7fc678c96178a357f287d31dd8293d40763f1e5a), this does not occur. The code does show an empty window.
Sorry,I has made a mistake. after recheck the code. now it can show an emtpy window on window 10.
import (
gl
glfw
time
)
fn main() {
glfw.init()
win_cfg := glfw.WinCfg{
width:500,
height:500,
title:'triangle',
}
window := glfw.create_window(win_cfg)
window.make_context_current()
gl.init_glad()
gl.viewport(0,0,500,500)
shader := gl.new_shader('text')
vertices := [
-0.5, -0.5, 0.0, // left
0.5, -0.5, 0.0, // right
0.0, 0.5, 0.0 // top
]
vbo := gl.gen_buffer()
vao := gl.gen_vertex_array()
gl.bind_vao(vao)
gl.bind_buffer(C.GL_ARRAY_BUFFER,vbo)
gl.buffer_data(C.GL_ARRAY_BUFFER,vertices.len * 4,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(C.GL_ARRAY_BUFFER,u32(0))
gl.bind_vao(u32(0))
for !window.should_close() {
gl.clear_color(255, 255, 255,1)
gl.clear()
shader.use()
gl.bind_vao(vao)
gl.draw_arrays(C.GL_TRIANGLES, 0, 3)
window.swap_buffers()
glfw.poll_events()
time.sleep_ms(100)
}
}
I am glad to see that you figured it out! Good luck!