示例#1
0
文件: main.go 项目: sycoso/glfw
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

	// Open window with FSAA samples (if possible).
	glfw.OpenWindowHint(glfw.FsaaSamples, 4)

	if err = glfw.OpenWindow(400, 400, 0, 0, 0, 0, 0, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.CloseWindow()

	glfw.SetWindowTitle("Aliasing Detector")
	glfw.SetSwapInterval(1)

	if samples := glfw.WindowParam(glfw.FsaaSamples); samples != 0 {
		fmt.Fprintf(os.Stdout, "Context reports FSAA is supported with %d samples\n", samples)
	} else {
		fmt.Fprintf(os.Stdout, "Context reports FSAA is unsupported\n")
	}

	gl.MatrixMode(gl.PROJECTION)
	glu.Perspective(0, 1, 0, 1)

	for glfw.WindowParam(glfw.Opened) == 1 {
		time := float32(glfw.Time())

		gl.Clear(gl.COLOR_BUFFER_BIT)

		gl.LoadIdentity()
		gl.Translatef(0.5, 0, 0)
		gl.Rotatef(time, 0, 0, 1)

		gl.Enable(GL_MULTISAMPLE_ARB)
		gl.Color3f(1, 1, 1)
		gl.Rectf(-0.25, -0.25, 0.25, 0.25)

		gl.LoadIdentity()
		gl.Translatef(-0.5, 0, 0)
		gl.Rotatef(time, 0, 0, 1)

		gl.Disable(GL_MULTISAMPLE_ARB)
		gl.Color3f(1, 1, 1)
		gl.Rectf(-0.25, -0.25, 0.25, 0.25)
		glfw.SwapBuffers()
	}
}
示例#2
0
文件: ca.go 项目: samnardoni/ca
func main() {
	var err error

	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}
	defer glfw.Terminate()

	if err = glfw.OpenWindow(Width, Height, 8, 8, 8, 8, 0, 8, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}
	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(Title)
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetKeyCallback(onKey)

	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0, 0, 0, 0)
	gl.ClearDepth(1)
	gl.Enable(gl.TEXTURE_2D)

	for running && glfw.WindowParam(glfw.Opened) == 1 {
		update()
		draw()
	}
}
示例#3
0
func GameLoop() {

	t := 0.0
	dt := 0.1

	CreateUniverse()

	camera.PositionCamera(0, 0, 1000, 900)

	for glfw.WindowParam(glfw.Opened) == 1 {

		t += dt

		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		gl.Clear(gl.DEPTH_BUFFER_BIT | gl.LIGHTING_BIT)

		for i := range universe.Systems {
			for j := range universe.Systems[i].Planets {
				BufferPlanet(universe.Systems[i].Planets[j])
				ai.PlanetOrbit(universe.Systems[i].Planets[j], t)
			}
			for j := range universe.Systems[i].Stars {
				BufferStar(universe.Systems[i].Stars[j])
				ai.StarStationary(universe.Systems[i].Stars[j], t)
			}
		}

		glfw.SwapBuffers()
	}
}
示例#4
0
文件: main.go 项目: vron/fm
func main() {
	log.Println("Starting")
	flag.Parse()

	runtime.GOMAXPROCS(4)

	initGLFW()
	initGL()

	initScene()

	initInput()

	glfw.SetWindowSizeCallback(resize)

	initLua()

	// Run the script file if we had one
	// TODO: Do this before accepting input from user...
	if fScript != "" {
		runFile(fScript)
	}

	for glfw.WindowParam(glfw.Opened) == 1 {
		display()
		glfw.SwapBuffers()
		time.Sleep(10 * time.Millisecond)
	}

}
示例#5
0
文件: main.go 项目: sycoso/glfw
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

	if err = glfw.OpenWindow(Width, Height, 8, 8, 8, 8, 0, 8, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(Title)
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetKeyCallback(onKey)

	initGL()

	running = true
	for running && glfw.WindowParam(glfw.Opened) == 1 {
		drawScene()
	}
}
示例#6
0
文件: glfw.go 项目: floffel03/gohorde
func main() {
	var running bool = true

	if err := glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

	if err := glfw.OpenWindow(appWidth, appHeight, 8, 8, 8, 8,
		24, 8, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}
	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(caption)

	if !horde3d.Init() {
		fmt.Println("Error starting Horde3D. Check Horde3d_log.html for details.")
		horde3d.DumpMessages()
		return
	}

	//horde3d.SetOption(horde3d.Options_DebugViewMode, 1)
	// Add resources
	//pipeline
	pipeRes = horde3d.AddResource(horde3d.ResTypes_Pipeline, "pipelines/hdr.pipeline.xml", 0)

	knightRes := horde3d.AddResource(horde3d.ResTypes_SceneGraph, "models/knight/knight.scene.xml", 0)

	//load resources paths separated by |
	horde3d.LoadResourcesFromDisk("../content")

	model := horde3d.RootNode.AddNodes(knightRes)
	model.SetTransform(0, 0, -30, 0, 0, 0, 0.1, 0.1, 0.1)

	// Add light source
	light := horde3d.RootNode.AddLightNode("Light1", 0, "LIGHTING", "SHADOWMAP")
	light.SetTransform(0, 20, 0, 0, 0, 0, 1, 1, 1)
	light.SetNodeParamF(horde3d.Light_RadiusF, 0, 50)

	//add camera
	cam = horde3d.RootNode.AddCameraNode("Camera", pipeRes)
	glfw.SetWindowSizeCallback(onResize)

	for running {

		horde3d.Render(cam)
		horde3d.FinalizeFrame()
		horde3d.DumpMessages()
		glfw.SwapBuffers()
		running = glfw.Key(glfw.KeyEsc) == 0 &&
			glfw.WindowParam(glfw.Opened) == 1
	}

	horde3d.Release()
}
示例#7
0
func main() {
	rand.Seed(time.Now().UnixNano())

	glfw.Init()
	defer glfw.Terminate()
	glfw.OpenWindow(Width, Height, 8, 8, 8, 8, 0, 8, glfw.Windowed)
	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle("Chipmunk demo")
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetKeyCallback(onKey)

	initGL()
	initScene()

	Running = true

	for Running && glfw.WindowParam(glfw.Opened) == 1 {
		drawScene()
		space.Step(1.0 / 20.0 / 3.0)
		space.Step(1.0 / 20.0 / 3.0)
		space.Step(1.0 / 20.0 / 3.0)
	}
}
示例#8
0
文件: main.go 项目: sycoso/glfw
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

	if err = glfw.OpenWindow(640, 480, 8, 8, 8, 8, 0, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.CloseWindow()

	glfw.SetWindowTitle("Draw")
	glfw.SetSwapInterval(1)
	glfw.SetKeyCallback(onKey)
	glfw.SetMouseButtonCallback(onMouseBtn)
	glfw.SetWindowSizeCallback(onResize)

	running = true
	for running && glfw.WindowParam(glfw.Opened) == 1 {
		if mouse[0] != 0 {
			pen.lineTo(glfw.MousePos())
		} else {
			pen.moveTo(glfw.MousePos())
		}

		glfw.SwapBuffers()
	}
}
示例#9
0
文件: window.go 项目: glenn-brown/vu
// Render draws the contents of the window, but no more than 30
// times per second.
func (w *Window) Render() {
	// Don't render more than 30 times per second.
	t := time.Now()
	if time.Since(w.lastRender).Seconds() < 1.0/30.0 {
		return
	}
	w.lastRender = t

	// Retrieve the view width and height, in pixels.
	params := make([]int32, 4)
	gl.GetIntegerv(gl.VIEWPORT, params)

	// Infer the rendering volume from the viewport size, so the
	// the rendering code can assume that the width of a pixel is
	// ~1.0.  This is important when rendering text.  This must
	// match the gl.Frustum configuration.
	width := float64(params[2])
	height := float64(params[3])
	depth := (width + height) / 2

	// Redraw the window, but not too often.
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	w.renderer.Render(width, height, depth)
	glfw.SwapBuffers()

	// Exit if the user presses escape or the window was closed.
	if glfw.Key(glfw.KeyEsc) != 0 || glfw.WindowParam(glfw.Opened) == 0 {
		os.Exit(0)
	}
}
示例#10
0
func main() {
	if err := glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "glfw: %s\n", err)
		return
	}
	defer glfw.Terminate()

	glfw.OpenWindowHint(glfw.WindowNoResize, 1)

	if err := glfw.OpenWindow(Width, Height, 0, 0, 0, 0, 0, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "glfw: %s\n", err)
		return
	}
	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(Title)

	if err := gl.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "gl: %s\n", err)
	}

	if err := initScene(); err != nil {
		fmt.Fprintf(os.Stderr, "init: %s\n", err)
		return
	}
	defer destroyScene()

	for glfw.WindowParam(glfw.Opened) == 1 {
		drawScene()
		glfw.SwapBuffers()
	}
}
示例#11
0
func main() {
	log.Printf("Starting glfw window")

	err := glfw.Init()
	if err != nil {
		log.Fatalf("Error while starting glfw library: %v", err)
	}
	defer glfw.Terminate()

	err = glfw.OpenWindow(256, 256, 8, 8, 8, 0, 0, 0, glfw.Windowed)
	if err != nil {
		log.Fatalf("Error while opening glfw window: %v", err)
	}
	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1) //vsync on

	glfw.SetWindowTitle("Colored Triangle")

	InitGL()

	glfw.SetWindowSizeCallback(func(w, h int) { InitGLWindow(w, h) })
	glfw.SetKeyCallback(func(key, state int) { HandleKey(key, state) })

	run := true
	for run && glfw.WindowParam(glfw.Opened) == 1 {
		select {
		case exitCode := <-exit:
			log.Printf("Received exit code: %d", exitCode)
			run = false
		default:
			Draw()
		}
	}
}
示例#12
0
func main() {
	flag.Parse()

	Load(flag.Args())

	Init(800, 600, *flag_smooth, *flag_multisample, true)
	InitInputHandlers()
	defer glfw.CloseWindow()
	defer glfw.Terminate()

	start := time.Now()
	frames := 0

	Viewpos[2] = -20

	for glfw.WindowParam(glfw.Opened) == 1 { // window open
		Render()
		frames++
		if Wantscrot {
			Screenshot()
			Wantscrot = false
		}
		glfw.WaitEvents()
	}

	fps := int((float64(frames) / float64(time.Since(start))) * float64(time.Second))
	log.Println("average FPS:", fps)
}
示例#13
0
文件: main.go 项目: andrebq/wfobj
func main() {
	globalState.Mouse = make(map[int]bool)
	flag.Parse()
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	if len(flag.Args()) == 0 {
		old := flag.Usage
		flag.Usage = func() {
			old()
			fmt.Fprintf(os.Stderr, "You MUST pass the name of the file to view\n")
		}
		flag.Usage()
		return
	}

	mesh, err = wfobj.LoadMeshFromFile(flag.Args()[0])
	if err != nil {
		flag.Usage()
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

	if err = glfw.OpenWindow(Width, Height, 8, 8, 8, 8, 0, 8, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(Title)
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetKeyCallback(onKey)
	glfw.SetCharCallback(onChar)
	glfw.SetMouseWheelCallback(onWheel)
	glfw.SetMouseButtonCallback(onMouseButton)
	glfw.SetMousePosCallback(onMousePos)

	initGL()

	running = true
	for running && glfw.WindowParam(glfw.Opened) == 1 {
		handleInput()
		drawScene()
	}
}
示例#14
0
文件: live.go 项目: shenyp09/mx3
func Live(in_ nimble.ChanN) {
	go func() {
		in := in_.NewReader()

		Frame = new(dump.Frame)
		Frame.Components = in.NComp()
		Frame.MeshSize = in.Mesh().Size()
		Frame.MeshStep = in.Mesh().CellSize()
		Crop2 = Frame.MeshSize
		ncell := in.Mesh().NCell()
		n := ncell * in.NComp()
		Frame.Data = make([]float32, n)

		Init(800, 600, true, 2, true)
		InitInputHandlers()
		defer glfw.CloseWindow()
		defer glfw.Terminate()
		Viewpos[2] = -20

		wantframe := new(atomicbool)
		wantframe.set(true)

		go func() {
			gpu.LockCudaThread()
			for {
				data := in.ReadNext(ncell)
				if wantframe.get() {
					for i, d := range data {
						d.Device().CopyDtoH(Frame.Data[i*ncell : (i+1)*ncell])
					}
					wantframe.set(false)
				}
				in.ReadDone()
			}
		}()

		for glfw.WindowParam(glfw.Opened) == 1 { // window open
			Render()
			if Wantscrot {
				Screenshot()
				Wantscrot = false
			}
			if wantframe.get() == false {
				PreRender(Frame)
				wantframe.set(true)
			}
		}
	}()
}
示例#15
0
文件: main.go 项目: andrebq/glfw
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	// Ensure glfw is cleanly terminated on exit.
	defer glfw.Terminate()

	if err = glfw.OpenWindow(256, 256, 8, 8, 8, 0, 0, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	// Ensure window is cleanly closed on exit.
	defer glfw.CloseWindow()

	// Enable vertical sync on cards that support it.
	glfw.SetSwapInterval(1)

	// Set window title
	glfw.SetWindowTitle("Simple GLFW window")

	// Hook some events to demonstrate use of callbacks.
	// These are not necessary if you don't need them.
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetWindowCloseCallback(onClose)
	glfw.SetMouseButtonCallback(onMouseBtn)
	glfw.SetMouseWheelCallback(onMouseWheel)
	glfw.SetKeyCallback(onKey)
	glfw.SetCharCallback(onChar)

	// Start loop
	running := true
	for running {
		// OpenGL rendering goes here.

		// Swap front and back rendering buffers. This also implicitly calls
		// glfw.PollEvents(), so we have valid key/mouse/joystick states after
		// this. This behavior can be disabled by calling glfw.Disable with the
		// argument glfw.AutoPollEvents. You must be sure to manually call
		// PollEvents() or WaitEvents() in this case.
		glfw.SwapBuffers()

		// Break out of loop when Escape key is pressed, or window is closed.
		running = glfw.Key(glfw.KeyEsc) == 0 && glfw.WindowParam(glfw.Opened) == 1
	}
}
示例#16
0
func (o *OpenGl) Init() {
	if err := glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "glfw: %s\n", err)
		return
	}
	defer glfw.Terminate()

	if err := glfw.OpenWindow(o.width, o.height, 0, 0, 0, 0, 16, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "glfw: %s\n", err)
		return
	}
	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(o.title)

	if err := gl.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "gl: %s\n", err)
	}

	glfw.SetKeyCallback(glfw.KeyHandler(o.keyboard))
	glfw.SetMouseButtonCallback(glfw.MouseButtonHandler(o.mouseClick))
	glfw.SetMousePosCallback(glfw.MousePosHandler(o.mouseMove))
	glfw.SetMouseWheelCallback(glfw.MouseWheelHandler(o.mouseWheel))

	if err := o.initScene(); err != nil {
		fmt.Fprintf(os.Stderr, "init: %s\n", err)
		return
	}

	for glfw.WindowParam(glfw.Opened) == 1 {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

		if o.display3d != nil {
			o.set3dView()
			o.display3d()
		}
		if o.display2d != nil {
			o.set2dView()
			o.display2d()
		}

		glfw.SwapBuffers()
		time.Sleep(20 * time.Millisecond)
		//<-o.redisplay
	}
}
示例#17
0
文件: bspview.go 项目: jayschwa/groke
func main() {
	flag.Parse()

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}

		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	if err := readModel(); err != nil {
		log.Fatal(err)
	}

	if err := glfw.Init(); err != nil {
		log.Fatal(err)
	}
	defer glfw.Terminate()

	glfw.OpenWindowHint(glfw.WindowNoResize, 1)

	if err := glfw.OpenWindow(Width, Height, 0, 0, 0, 0, 16, 0, glfw.Windowed); err != nil {
		log.Fatal(err)
		return
	}
	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(Title)
	glfw.SetKeyCallback(onKey)

	if err := gl.Init(); err != nil {
		log.Fatal(err)
	}

	initScene()
	defer destroyScene()

	for glfw.WindowParam(glfw.Opened) == 1 {
		applyMove()
		drawScene()
		glfw.SwapBuffers()
	}
}
示例#18
0
func main() {

	// Setup the window

	if err := glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "glfw: %s\n", err)
		return
	}
	// Close glfw at the end of main()
	defer glfw.Terminate()

	// Set window properties
	glfw.OpenWindowHint(glfw.WindowNoResize, 0)
	//glfw.OpenWindowHint(glfw.OpenGLForwardCompat, gl.TRUE)
	glfw.OpenWindowHint(glfw.OpenGLDebugContext, gl.TRUE)

	// Actually open the window
	if err := glfw.OpenWindow(initial_width, initial_height, 0, 0, 0, 0, 16, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "glfw: %s\n", err)
		return
	}

	// Close the window at the end of main()
	defer glfw.CloseWindow()

	// Only swap buffer once/ draw cycle (30 or 60 fps)
	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(Title)

	// Apply those settings
	if err := gl.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "gl: %s\n", err)
	}

	// While glfw.Opened is 1 (the window is open), keep swapping buffers
	for glfw.WindowParam(glfw.Opened) == 1 {

		glfw.SwapBuffers()
	}

	setCallbacks()

	// Initialize the openGL settings
	Initialize()
}
示例#19
0
文件: scene.go 项目: andrebq/tinygl
func main() {
	log.Printf("Starting glfw window")

	err := glfw.Init()
	if err != nil {
		log.Fatalf("Error while starting glfw library: %v", err)
	}
	defer glfw.Terminate()

	err = glfw.OpenWindow(256, 256, 8, 8, 8, 0, 0, 0, glfw.Windowed)
	if err != nil {
		log.Fatalf("Error while opening glfw window: %v", err)
	}
	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1) //vsync on

	glfw.SetWindowTitle("Colored Triangle")

	InitGL()

	glfw.SetWindowSizeCallback(func(w, h int) { InitGLWindow(w, h) })
	glfw.SetKeyCallback(func(key, state int) { HandleKey(key, state) })

	// create a mesh with 3 vertices (a triangle)
	m := &Mesh{make([]*Vector, 3)}
	m.V[0] = &Vector{0, 1, 0, color.NRGBA{1, 0, 0, 0}}
	m.V[1] = &Vector{-1, -1, 0, color.NRGBA{0, 1, 0, 0}}
	m.V[2] = &Vector{1, -1, 0, color.NRGBA{0, 0, 1, 0}}

	run := true
	for run && glfw.WindowParam(glfw.Opened) == 1 {
		select {
		case exitCode := <-exit:
			log.Printf("Received exit code: %d", exitCode)
			run = false
		default:
			Draw(m)
		}
	}
}
示例#20
0
func main() {
	fmt.Println("OpenGL Programming/Modern OpenGL Introduction")
	fmt.Println("Tutorial taken from http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Introduction")

	var err error
	err = glfw.Init()
	if err != nil {
		fmt.Printf("GLFW: %s\n", err)
		return
	}
	defer glfw.Terminate()

	glfw.OpenWindowHint(glfw.OpenGLVersionMajor, 3)
	glfw.OpenWindowHint(glfw.OpenGLVersionMinor, 3)
	glfw.OpenWindowHint(glfw.OpenGLProfile, 1)

	err = glfw.OpenWindow(ScreenWidth, ScreenHeight, 0, 0, 0, 0, 0, 0, glfw.Windowed)
	if err != nil {
		fmt.Printf("GLFW: %s\n", err)
		return
	}
	defer glfw.CloseWindow()

	glfw.SetWindowTitle(WindowTitle)

	// Init extension loading
	err = gl.Init()
	if err != nil {
		fmt.Printf("Init OpenGL extension loading failed with %s.\n", err)
	}

	initResources()

	// Render loop
	for glfw.WindowParam(glfw.Opened) == 1 {
		display()
	}

	// Free resources
	free()
}
示例#21
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
	}

}
示例#22
0
文件: main.go 项目: skelterjohn/glfw
func main() {
	var err os.Error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}

	// Ensure glfw is cleanly terminated on exit.
	defer glfw.Terminate()

	if err = glfw.OpenWindow(300, 300, 0, 0, 0, 0, 0, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}

	// Ensure window is cleanly closed on exit.
	defer glfw.CloseWindow()

	// Enable vertical sync on cards that support it.
	glfw.SetSwapInterval(1)

	// Set window title
	glfw.SetWindowTitle("Simple GLFW window")

	running := true
	for running {
		// OpenGL rendering goes here.

		// Swap front and back rendering buffers. This also implicitly calls
		// glfw.PollEvents(), so we have valid key/mouse/joystick states after
		// this. This behavior can be disabled by calling glfw.Disable with the
		// argument glfw.AutoPollEvents. You must be sure to manually call
		// PollEvents() or WaitEvents() in this case.
		glfw.SwapBuffers()

		// Break out of loop when Escape key is pressed, or window is closed.
		running = glfw.Key(glfw.KeyEsc) == 0 && glfw.WindowParam(glfw.Opened) == 1
	}
}
示例#23
0
文件: main.go 项目: dskinner/cell
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()

	if *flagListRules {
		for _, name := range automata.Rulers() {
			fmt.Println(name)
		}
		return
	}

	if err := glfw.Init(); err != nil {
		log.Fatal(err)
	}
	defer glfw.Terminate()

	glfw.OpenWindowHint(glfw.WindowNoResize, 1)

	if err := glfw.OpenWindow(Width, Height, 0, 0, 0, 0, 0, 0, glfw.Windowed); err != nil {
		log.Fatal(err)
	}
	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(Title)

	if err := gl.Init(); err != nil {
		log.Fatal(err)
	}

	initScene()
	defer destroyScene()

	for glfw.WindowParam(glfw.Opened) == 1 {
		drawScene()
		glfw.SwapBuffers()
	}
}
示例#24
0
文件: main.go 项目: andrebq/wfobj
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}
	path, err := gas.Abs("github.com/andrebq/wfobj/testdata/complex/complex.obj")
	if err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}
	mesh, err = wfobj.LoadMeshFromFile(path)
	if err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

	if err = glfw.OpenWindow(Width, Height, 8, 8, 8, 8, 0, 8, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(Title)
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetKeyCallback(onKey)

	initGL()

	running = true
	for running && glfw.WindowParam(glfw.Opened) == 1 {
		drawScene()
	}
}
示例#25
0
func (w *window) OpenGLContextVersion() (major int, minor int) {
	major = glfw.WindowParam(glfw.OpenGLVersionMajor)
	minor = glfw.WindowParam(glfw.OpenGLVersionMinor)
	return
}
示例#26
0
func (w *window) OpenGLForwardCompat() bool {
	return glfw.WindowParam(glfw.OpenGLForwardCompat) == 1
}
示例#27
0
文件: main.go 项目: vova616/mater
func main() {
	log.SetFlags(log.Lshortfile)

	//parse flags
	flag.Parse()

	if flags.cpuprofile != "" {
		f, err := os.Create(flags.cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	loadSettingsFile()
	Settings.Paused = flags.startPaused

	if flags.buildExamples {
		allExamples()
		return
	}

	wx, wy := 800, 600

	//initialize opengl & glfw
	{
		//init glfw
		if err := glfw.Init(); err != nil {
			log.Printf("Error initializing glfw: %v\n", err)
			return
		}
		defer glfw.Terminate()

		//set window hints
		glfw.OpenWindowHint(glfw.WindowNoResize, 1)

		//create the window
		if err := glfw.OpenWindow(wx, wy, 8, 8, 8, 8, 0, 8, glfw.Windowed); err != nil {
			log.Printf("Error opening Window: %v\n", err)
			return
		}
		defer glfw.CloseWindow()

		//init opengl
		if gl.Init() != 0 {
			panic("gl error")
		}

		//glfw config
		{
			glfw.SetSwapInterval(1)
			glfw.SetWindowTitle("mater test")
		}

		//set additional opengl stuff
		{
			gl.ClearColor(0, 0, 0, 0)
			gl.Enable(gl.BLEND)
			//gl.BlendFunc (gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
			gl.Enable(gl.TEXTURE_2D)
		}
	}

	//setup scene related stuff
	{
		//create empty space
		space = collision.NewSpace()
	}

	//reload settings so they take effect
	reloadSettings()
	saveSettingsFile()

	//set callbacks
	{
		glfw.SetWindowSizeCallback(OnResize)
		glfw.SetKeyCallback(OnKey)
	}

	//init debug console
	console.Init()

	//load savefile passed from the commandline if any
	if flags.file != "" {
		err := loadSpace(flags.file)
		Settings.Paused = true
		if err != nil {
			panic(err)
		}
	}

	//if set to true once a second
	printFPS := false

	//fix timestep to given fps
	const expectedFps = 30.0
	const expectedFrameTime = 1.0 / expectedFps

	//the time at the start of the last frame
	lastTime := 0.0

	acc := 0.0
	updateAcc := 0.0

	frameCount := 0
	updateFrameCount := 0

	fps := 0
	updateFps := 0

	Settings.Running = true

	for Settings.Running && glfw.WindowParam(glfw.Opened) == 1 {
		time := glfw.Time()
		//get the time elapsed since the last frame
		dt := time - lastTime
		lastTime = time

		//advance framecount and accumulators
		frameCount++
		acc += dt
		updateAcc += dt

		//execute console commands if any
		select {
		case command := <-console.Command:
			console.ExecuteCommand(command)
		default:
		}

		//update the scene at a fixed timestep
		for updateAcc >= expectedFrameTime {
			updateFrameCount++

			//if one second has passed update the fps and reset the framecount
			if acc > 1 {
				updateFps = updateFrameCount
				updateFrameCount = 0
			}

			//only update if not paused or if set to advance a single frame
			if !Settings.Paused || Settings.SingleStep {
				space.Step(expectedFrameTime)
				Settings.SingleStep = false
			}

			updateAcc -= expectedFrameTime
		}

		//draw debug data
		Draw()

		glfw.SwapBuffers()

		//if one second has passed update the fps and reset the framecount
		if acc > 1 {
			fps = frameCount
			frameCount = 0
			if printFPS {
				fmt.Printf("---\n")
				fmt.Printf("FPS: %v\n", fps)
				fmt.Printf("Update FPS: %v\n", updateFps)
				fmt.Printf("Average frametime: %v\n", acc/float64(fps))
				fmt.Printf("---\n")
			}
			acc -= 1
		}
	}
}
示例#28
0
func (w *window) OpenGLDebugContext() bool {
	return glfw.WindowParam(glfw.OpenGLDebugContext) == 1
}
示例#29
0
func (w *window) OpenGLProfile() int {
	return glfw.WindowParam(glfw.OpenGLProfile)
}
示例#30
0
文件: main.go 项目: drasich/malus
func main() {
	if err := glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "glfw: %s\n", err)
		return
	}
	defer glfw.Terminate()

	glfw.OpenWindowHint(glfw.WindowNoResize, gl.TRUE)

	if err := glfw.OpenWindow(Width, Height, 0, 0, 0, 0, 32, 32, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "glfw: %s\n", err)
		return
	}
	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(Title)

	if err := gl.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "gl: %s\n", err)
	}

	var scene ry.Scene
	if err := scene.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "init: %s\n", err)
		return
	}
	defer scene.Destroy()

	var player, wall ry.Object
	wall.Init()
	player.Init()
	player.Position.Z = -7
	player.Position.X = 3
	player.Orientation = ry.QuatAngleAxis(-45*ry.DegToRad, ry.Vec3{0, 0, 1})

	cc := newControlComponent(&player)
	mesh := ry.NewMeshComponent("model/tex.bin", &player)
	mesh.Init()
	player.AddComponent(*cc)
	player.Mesh = mesh

	mesh2 := ry.NewMeshComponent("model/tex.bin", &wall)
	mesh2.Init()
	wall.Mesh = mesh2
	wall.Position.Z = -10
	box := ry.NewBoxComponent(ry.Vec3{0, 0, 0}, ry.Vec3{10, 10, 10})
	wall.Box = box
	wall.Orientation = ry.QuatAngleAxis(-90*ry.DegToRad, ry.Vec3{0, 0, 1})

	scene.AddObject(&player)
	scene.AddObject(&wall)

	//plane := ry.Plane{ry.Vec3{0,0,0}, ry.Vec3{1,1,0}}
	ray := ry.Ray{ry.Vec3{15, -5, -5}, ry.Vec3{-100, 0, 0}}

	/*
	   b, hv := ry.IntersectionRayPlane(ray, plane)
	   if b {
	     fmt.Println("hv : ", hv)
	   } else { fmt.Println("no collision : ", hv) }
	*/

	//aabox := ry.AABox{ry.Vec3{0,0,0}, ry.Vec3{10,10,10}}
	//hit, _, pos, nor := ry.IntersectionRayAABox(ray, aabox)
	hit, _, pos, nor := ry.IntersectionRayObject(ray, &wall)
	if hit {
		fmt.Println("pos and normal : ", pos, nor)
	} else {
		fmt.Println("no intersection with box")

	}

	last_time = time.Now()
	for glfw.WindowParam(glfw.Opened) == 1 && !exit {
		/*
		   objects, positions := ry.LaunchRay( ry.Vec3{0,0,0}, ry.Vec3{0,0,-1}, 100, scene.Objects)

		    if objects != nil {
		      fmt.Println("collision with one or more objects", positions[0])
		    }
		*/

		scene.Update()
		scene.Draw()
		glfw.SwapBuffers()
		since := time.Since(last_time).Seconds()
		if since > 0.02 {
			fmt.Println("frame under 50fps:", since)
		}
		last_time = time.Now()
	}
}