func main() { ret := glfw.Init() print(ret) ret = glfw.OpenWindow(300, 300, 0, 0, 0, 0, 0, 0, glfw.WINDOW) print(ret) if gl.Init() != 0 { panic("glew error") } running := true for running { gl.Begin(gl.TRIANGLES) gl.Vertex3f(0, 0, 0) gl.Vertex3f(0, 1, 0) gl.Vertex3f(1, 1, 0) gl.End() glfw.SwapBuffers() running = glfw.GetKey(glfw.KEY_ESC) == 0 && glfw.GetWindowParam(glfw.OPENED) != 0 } }
func main() { // We need to lock the goroutine to one thread due time.Ticker runtime.LockOSThread() var err os.Error err = glfw.Init() if err != nil { fmt.Printf("GLFW: %s\n", err) return } defer glfw.Terminate() // You could probably change the required versions down glfw.OpenWindowHint(glfw.OpenGLVersionMajor, 3) glfw.OpenWindowHint(glfw.OpenGLVersionMinor, 3) glfw.OpenWindowHint(glfw.OpenGLProfile, 1) // Open Window with 8 bit Alpha err = glfw.OpenWindow(ScreenWidth, ScreenHeight, 0, 0, 0, 8, 0, 0, glfw.Windowed) if err != nil { fmt.Printf("GLFW: %s\n", err) return } defer glfw.CloseWindow() glfw.SetWindowTitle(WindowTitle) major, minor, rev := glfw.GLVersion() if major < 3 { fmt.Printf("Error your graphic card does not support OpenGL 3.3\n Your GL-Version is: %d, %d, %d\n", major, minor, rev) fmt.Println("You can try to lower the settings in glfw.OpenWindowHint(glfw.OpenGLVersionMajor/Minor.") } initStatus := gl.Init() // Init glew if initStatus != 0 { fmt.Printf("Error-code: %d Init-Status: %d\n", gl.GetError(), initStatus) } // Enable transparency in OpenGL gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) initResources() // We are limiting the calls to display() (frames per second) to 60. This prevents the 100% cpu usage. ticker := time.NewTicker(int64(second) / 60) // max 60 fps for { <-ticker.C move := float32(math.Sin(glfw.Time())) angle := float32(glfw.Time()) matrix = math3d.MakeTranslationMatrix(move, 0.0, 0.0) matrix = matrix.Multiply(math3d.MakeZRotationMatrix(angle)).Transposed() display() } // Free resources free() runtime.UnlockOSThread() }
func main() { sdl.Init(sdl.INIT_VIDEO) var screen = sdl.SetVideoMode(640, 480, 32, sdl.OPENGL) if screen == nil { panic("sdl error") } if gl.Init() != 0 { panic("glew error") } pen := Pen{} gl.MatrixMode(gl.PROJECTION) gl.Viewport(0, 0, gl.GLsizei(screen.W), gl.GLsizei(screen.H)) gl.LoadIdentity() gl.Ortho(0, gl.GLdouble(screen.W), gl.GLdouble(screen.H), 0, -1.0, 1.0) gl.ClearColor(1, 1, 1, 0) gl.Clear(gl.COLOR_BUFFER_BIT) var running = true for running { e := &sdl.Event{} for e.Poll() { switch e.Type { case sdl.QUIT: running = false break case sdl.KEYDOWN: running = false break case sdl.MOUSEMOTION: me := e.MouseMotion() if me.State != 0 { pen.lineTo(Point{int(me.X), int(me.Y)}) } else { pen.moveTo(Point{int(me.X), int(me.Y)}) } break } } sdl.GL_SwapBuffers() sdl.Delay(25) } sdl.Quit() }
func main() { sdl.Init(sdl.INIT_VIDEO) var screen = sdl.SetVideoMode(640, 480, 32, sdl.OPENGL) if screen == nil { panic("sdl error") } if gl.Init() != 0 { panic("gl error") } pen := Pen{} gl.MatrixMode(gl.PROJECTION) gl.Viewport(0, 0, int(screen.W), int(screen.H)) gl.LoadIdentity() gl.Ortho(0, float64(screen.W), float64(screen.H), 0, -1.0, 1.0) gl.ClearColor(1, 1, 1, 0) gl.Clear(gl.COLOR_BUFFER_BIT) var running = true for running { for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() { switch ev := e.(type) { case *sdl.QuitEvent: running = false case *sdl.KeyboardEvent: if ev.Keysym.Sym == sdl.K_ESCAPE { running = false } case *sdl.MouseMotionEvent: if ev.State != 0 { pen.lineTo(Point{int(ev.X), int(ev.Y)}) } else { pen.moveTo(Point{int(ev.X), int(ev.Y)}) } } } sdl.GL_SwapBuffers() sdl.Delay(25) } sdl.Quit() }
func main() { var err os.Error err = glfw.Init() if err != nil { fmt.Printf("GLFW: %s\n", err) return } defer glfw.Terminate() glfw.OpenWindowHint(glfw.WindowNoResize, 1) glfw.OpenWindowHint(glfw.OpenGLDebugContext, 1) // You could probably change the required versions down glfw.OpenWindowHint(glfw.OpenGLVersionMajor, 3) glfw.OpenWindowHint(glfw.OpenGLVersionMinor, 3) glfw.OpenWindowHint(glfw.OpenGLProfile, 1) // Open Window with 8 bit Alpha err = glfw.OpenWindow(ScreenWidth, ScreenHeight, 0, 0, 0, 8, 0, 0, glfw.Windowed) if err != nil { fmt.Printf("GLFW: %s\n", err) return } defer glfw.CloseWindow() glfw.SetWindowTitle(WindowTitle) major, minor, rev := glfw.GLVersion() if major < 3 { fmt.Printf("Error your graphic card does not support OpenGL 3.3\n Your GL-Version is: %d, %d, %d\n", major, minor, rev) fmt.Println("You can try to lower the settings in glfw.OpenWindowHint(glfw.OpenGLVersionMajor/Minor.") } initStatus := gl.Init() // Init glew if initStatus != 0 { fmt.Printf("Error-code: %d Init-Status: %d\n", gl.GetError(), initStatus) } // Enable transparency in OpenGL gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) initResources() for { display() } // Free resources free() }
func SetupVideo() { if sdl.Init(sdl.INIT_VIDEO) < 0 { panic("Couldn't initialize sdl") } w := WinW h := WinH var screen = sdl.SetVideoMode(w, h, 32, SDL_FLAGS) // var screen = sdl.SetVideoMode(w, h, 32, sdl.OPENGLBLIT | sdl.DOUBLEBUF | sdl.HWSURFACE) // var screen = sdl.SetVideoMode(w, h, 32, sdl.OPENGL) if screen == nil { panic("sdl error") } if ttf.Init() != 0 { panic("ttf init error") } if gl.Init() != 0 { panic("Couldn't init gl") } ResizeWindow(screen.W, screen.H) gl.ClearColor(0, 0, 0, 0) // gl.ClearColor(1, 1, 1, 0) gl.ClearDepth(1.0) gl.DepthFunc(gl.LEQUAL) gl.Enable(gl.DEPTH_TEST) gl.ShadeModel(gl.SMOOTH) gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST) /* if gl.Init() != 0 { panic("glew error") } */ // gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT ) // gl.Clear(gl.COLOR_BUFFER_BIT) // initGL // gl.Ortho(0, gl.GLdouble(screen.W), gl.GLdouble(screen.H), 0, -1.0, 1.0) }
func main() { flag.Parse() var done bool var err os.Error if err = glfw.Init(); err != nil { fmt.Fprintf(os.Stderr, "[e] %v\n", err) return } defer glfw.Terminate() if err = glfw.OpenWindow(300, 300, 0, 0, 0, 0, 0, 0, glfw.Windowed); err != nil { fmt.Fprintf(os.Stderr, "[e] %v\n", err) return } if gl.Init() != 0 { panic("gl error") } defer glfw.CloseWindow() glfw.SetWindowTitle("gears") glfw.SetWindowSizeCallback(reshape) init_() reshape(300, 300) done = false for !done { idle() draw() done = glfw.Key(glfw.KeyEsc) != 0 || glfw.WindowParam(glfw.Opened) == 0 } }
func main() { runtime.LockOSThread() flag.Parse() buildPalette() sdl.Init(sdl.INIT_VIDEO) defer sdl.Quit() sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1) if sdl.SetVideoMode(512, 512, 32, sdl.OPENGL) == nil { panic("sdl error") } if gl.Init() != 0 { panic("gl error") } sdl.WM_SetCaption("Gomandel", "Gomandel") gl.Enable(gl.TEXTURE_2D) gl.Viewport(0, 0, 512, 512) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, 512, 512, 0, -1, 1) gl.ClearColor(0, 0, 0, 0) //----------------------------------------------------------------------------- var dndDragging bool = false var dndStart Point var dndEnd Point var tex gl.Texture var tc TexCoords var lastProgress int initialRect := Rect{-1.5, -1.5, 3, 3} rect := initialRect rc := new(MandelbrotRequest) rc.MakeRequest(512, 512, rect) rc.WaitFor(Small, &tex, &tc) running := true e := new(sdl.Event) for running { for e.Poll() { switch e.Type { case sdl.QUIT: running = false case sdl.MOUSEBUTTONDOWN: dndDragging = true sdl.GetMouseState(&dndStart.X, &dndStart.Y) dndEnd = dndStart case sdl.MOUSEBUTTONUP: dndDragging = false sdl.GetMouseState(&dndEnd.X, &dndEnd.Y) if e.MouseButton().Button == 3 { rect = initialRect } else { rect = rectFromSelection(dndStart, dndEnd, 512, 512, rect) tc = texCoordsFromSelection(dndStart, dndEnd, 512, 512, tc) } // make request rc.MakeRequest(512, 512, rect) case sdl.MOUSEMOTION: if dndDragging { sdl.GetMouseState(&dndEnd.X, &dndEnd.Y) } } } // if we're waiting for a result, check if it's ready p := rc.Update(&tex, &tc) if p != -1 { lastProgress = p } gl.Clear(gl.COLOR_BUFFER_BIT) tex.Bind(gl.TEXTURE_2D) drawQuad(0, 0, 512, 512, tc.TX, tc.TY, tc.TX2, tc.TY2) gl.BindTexture(gl.TEXTURE_2D, 0) if dndDragging { drawSelection(dndStart, dndEnd) } drawProgress(512, 512, lastProgress, rc.Pending) sdl.GL_SwapBuffers() } }
func main() { flag.Parse() var done bool var keys []uint8 sdl.Init(sdl.INIT_VIDEO) var screen = sdl.SetVideoMode(300, 300, 16, sdl.OPENGL|sdl.RESIZABLE) if screen == nil { sdl.Quit() panic("Couldn't set 300x300 GL video mode: " + sdl.GetError() + "\n") } if gl.Init() != 0 { panic("gl error") } sdl.WM_SetCaption("Gears", "gears") init_() reshape(int(screen.W), int(screen.H)) done = false for !done { idle() for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() { switch e.(type) { case *sdl.ResizeEvent: re := e.(*sdl.ResizeEvent) screen = sdl.SetVideoMode(int(re.W), int(re.H), 16, sdl.OPENGL|sdl.RESIZABLE) if screen != nil { reshape(int(screen.W), int(screen.H)) } else { panic("we couldn't set the new video mode??") } break case *sdl.QuitEvent: done = true break } } keys = sdl.GetKeyState() if keys[sdl.K_ESCAPE] != 0 { done = true } if keys[sdl.K_UP] != 0 { view_rotx += 5.0 } if keys[sdl.K_DOWN] != 0 { view_rotx -= 5.0 } if keys[sdl.K_LEFT] != 0 { view_roty += 5.0 } if keys[sdl.K_RIGHT] != 0 { view_roty -= 5.0 } if keys[sdl.K_z] != 0 { if (sdl.GetModState() & sdl.KMOD_RSHIFT) != 0 { view_rotz -= 5.0 } else { view_rotz += 5.0 } } draw() } sdl.Quit() return }
func main() { filename = flag.String("file", "testbed/data/dude.dat", "enter filename path") cx = flag.Int("cx", 300, "enter x-coordinate center") cy = flag.Int("cy", 500, "enter y-coordinate center") zoom = flag.Float64("zoom", 2, "enter zoom") flag.Parse() fmt.Println("opening...", *filename) f, err := os.Open(*filename) if f == nil { fmt.Fprintf(os.Stderr, "cat: can't open %s: error %s\n", *filename, err) os.Exit(1) } d, _ := ioutil.ReadAll(f) line := strings.SplitAfter(string(d), "\n") j := 0 for i := 0; i < len(line); i++ { if len(line[i]) <= 2 { break } j++ } var polyline = make(p2t.PointArray, j) for i := 0; i < j; i++ { line[i] = strings.TrimRight(line[i], "\r\n") num := strings.Split(line[i], " ") n1, err1 := strconv.Atof64(num[0]) n2, err2 := strconv.Atof64(num[1]) if err1 != nil || err2 != nil { fmt.Fprintf(os.Stderr, "cat: can't open %s: error %s\n", *filename, err) os.Exit(1) } polyline[i] = &p2t.Point{X: n1, Y: n2} } f.Close() left = -Width / float64(*zoom) right = Width / float64(*zoom) bottom = -Height / float64(*zoom) top = Height / float64(*zoom) last_time := time.Nanoseconds() p2t.Init(polyline) var triangles p2t.TriArray = p2t.Triangulate() dt := time.Nanoseconds() - last_time fmt.Printf("Elapsed time : %f ms\n", float64(dt)*1e-6) //var mesh p2t.TriArray = p2t.Mesh() sdl.Init(sdl.INIT_VIDEO) var screen = sdl.SetVideoMode(Width, Height, 16, sdl.OPENGL|sdl.RESIZABLE) if screen == nil { sdl.Quit() panic("Couldn't set GL video mode: " + sdl.GetError() + "\n") } sdl.WM_SetCaption("Pol2tri - testbed", "poly2tri") if gl.Init() != 0 { panic("gl error") } initGL() done := false for !done { for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() { switch e.(type) { case *sdl.ResizeEvent: re := e.(*sdl.ResizeEvent) screen = sdl.SetVideoMode(int(re.W), int(re.H), 16, sdl.OPENGL|sdl.RESIZABLE) if screen != nil { reshape(int(screen.W), int(screen.H)) } else { panic("we couldn't set the new video mode??") } break case *sdl.QuitEvent: done = true break } } keys := sdl.GetKeyState() if keys[sdl.K_ESCAPE] != 0 { done = true } resetZoom() draw(triangles) } sdl.Quit() return }
func main() { // We need to lock the goroutine to one thread due time.Ticker runtime.LockOSThread() var err os.Error err = glfw.Init() if err != nil { fmt.Printf("GLFW: %s\n", err) return } defer glfw.Terminate() // You could probably change the required versions down glfw.OpenWindowHint(glfw.OpenGLVersionMajor, 3) glfw.OpenWindowHint(glfw.OpenGLVersionMinor, 3) glfw.OpenWindowHint(glfw.OpenGLProfile, 1) // Open Window with 8 bit Alpha err = glfw.OpenWindow(ScreenWidth, ScreenHeight, 0, 0, 0, 8, 8, 0, glfw.Windowed) if err != nil { fmt.Printf("GLFW: %s\n", err) return } defer glfw.CloseWindow() glfw.SetWindowTitle(WindowTitle) glfw.SetWindowSizeCallback(onResize) major, minor, rev := glfw.GLVersion() if major < 3 { fmt.Printf("Error your graphic card does not support OpenGL 3.3\n Your GL-Version is: %d, %d, %d\n", major, minor, rev) fmt.Println("You can try to lower the settings in glfw.OpenWindowHint(glfw.OpenGLVersionMajor/Minor.") } initStatus := gl.Init() // Init glew if initStatus != 0 { fmt.Printf("Error-code: %d Init-Status: %d\n", gl.GetError(), initStatus) } // Enable transparency in OpenGL gl.Enable(gl.BLEND) gl.Enable(gl.DEPTH_TEST) //gl.DepthFunc(gl.LESS) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) initResources() // We are limiting the calls to display() (frames per second) to 60. This prevents the 100% cpu usage. ticker := time.NewTicker(int64(second) / 60) // max 60 fps for { <-ticker.C angle := float32(glfw.Time()) anim := math3d.MakeYRotationMatrix(angle) model := math3d.MakeTranslationMatrix(0, 0, -4) view := math3d.MakeLookAtMatrix(math3d.Vector3{0, 2, 0}, math3d.Vector3{0, 0, -4}, math3d.Vector3{0, 1, 0}) projection := math3d.MakePerspectiveMatrix(45, float32(ScreenWidth)/float32(ScreenHeight), 0.1, 10.0) matrix = math3d.MakeIdentity().Multiply(projection).Multiply(view).Multiply(model).Multiply(anim) program.Use() uniformMTransform.UniformMatrix4fv(1, false, matrix.Transposed()) display() } // Free resources free() runtime.UnlockOSThread() }
func main() { //ABSPTest() //return glfw.Init(800, 600) InitPhysics() world := new(World) world.Init() world.GameObjects = new(list.List) player := MakeMan(Vec3{10, 20, 10}) world.Add(player) world.Add(ropetest(Vec3{0, 40, 0}, 4, 4)) world.Add(treeThing(Vec3{20, 20, 20}, 3)) world.Add(MakePlayer(Vec3{-20, 20, 0}).Body) world.Add(MakePlayer(Vec3{-20, 50, 0}).Body) world.Add(MakePlayer(Vec3{-20, 70, 0}).Body) world.Add(MakePlayer(Vec3{-20, 90, 0}).Body) world.Add(MakePlayer(Vec3{-20, 110, 0}).Body) /*for i := 0; i < 100; i++ { world.Add(SetPlayerAnimation(MakePlayer(Vec3{float32(int(i%10))*50,0,float32(i*2) - 200})).Body) }*/ world.Add(NewGameObj(Vec3{0, -20, 0}, Vec3{10000, 10, 10000}, Vec3{0, 0.5, 0.1}, float32(math.Inf(1)), 10, nil)) //world.Add(SetPlayerAnimation(MakePlayer(Vec3{-20,120,0})).Body) qtn := new(ABSPNode) qtn.Root = qtn //qtn.Position = Vec3{-10000,-10000,-10000} //qtn.Size = Vec3{20000,20000,20000} for i := world.GameObjects.Front(); i != nil; i = i.Next() { gobj := i.Value.(*GameObj) all := gobj.GetSubs() for i := 0; i < len(all); i++ { qtn.Insert(all[i]) } } world.GameObjectTree = qtn fmt.Println("Total:", len(qtn.Data)) qtn.Divide() cols := 0 qtn.cd(func(obj1, obj2 SPData) { cols += 1 }) fmt.Println(cols) //qtn.Traverse(0) //return gl.Init() vs := gl.CreateShader(gl.VERTEX_SHADER) vs.Source( LoadFileToString("s1.vert")) vs.Compile() fs := gl.CreateShader(gl.FRAGMENT_SHADER) fs.Source(LoadFileToString("s1.frag")) fs.Compile() pg := gl.CreateProgram() pg.AttachShader(vs) pg.AttachShader(fs) pg.Link() pg.Validate() pg.Use() fmt.Println("**Shader log**") fmt.Println(fs.GetInfoLog()) fmt.Println(vs.GetInfoLog()) fmt.Println(pg.GetInfoLog()) fmt.Println("******END*****") gl.ClearColor(0.5, 0.5, 1, 0) gl.Enable(gl.DEPTH_TEST) gl.Enable(gl.BLEND) gl.Enable(gl.POLYGON_SMOOTH) gl.Hint(gl.POLYGON_SMOOTH_HINT, gl.NICEST) var t float64 t = float64(time.Nanoseconds()) / 1000000000 cam1 := Camera{player, 100, Vec3{0, 0, 0}} glfw.AddListener(func(m glfw.MouseMoveEvent) { cam1.Angle.X = float32(m.X-400) / 400 * 3.14 * 2 cam1.Angle.Y = float32(m.Y-300) / 300 * 3.14 * 2 //player.Rotation = Vec3{cam1.Angle.X,cam1.Angle.Y,0} }) glfw.AddListener(func(mw glfw.MouseWheelEvent) { cam1.Distance = 100 + float32(mw.Pos*mw.Pos*mw.Pos) }) world.CompilePhysicsObjects() for it := 0; it < 10000; it += 1 { cam1.Setup() dt := float32(0.005) t = float64(float64(time.Nanoseconds()) / 1000000000) UpdatePositions(world.PhysicsObjects, dt) UpdateModelStates(world.PhysicsObjects) UpdateCollisions(world.GameObjectTree, dt) UpdateModelStates(world.PhysicsObjects) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) DrawWorld(world.GameObjects, dt, pg) glfw.SwapBuffers() pt := float64(float64(time.Nanoseconds()) / 1000000000) sleeptime := (float64(dt) - (pt - t)) * 10e8 fmt.Println("Sleep for:", sleeptime) time.Sleep(int64(sleeptime)) } }