Ejemplo n.º 1
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()
	}
}
Ejemplo n.º 2
0
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()
}
Ejemplo n.º 3
0
func display() {
	// Clear the background as white
	gl.ClearColor(1.0, 1.0, 1.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// Use the GLSL program
	program.Use()

	uniformTexture.Uniform1i(0)

	attributeCoord3d.EnableArray()
	vboCubeVertices.Bind(gl.ARRAY_BUFFER)
	attributeCoord3d.AttribPointerOffset(3, gl.FLOAT, false, 0, 0)

	texture.Bind(gl.TEXTURE_2D)

	attributeTexCoord.EnableArray()
	vboCubeTexCoords.Bind(gl.ARRAY_BUFFER)
	attributeTexCoord.AttribPointerOffset(2, gl.FLOAT, false, 0, 0)

	iboCubeElements.Bind(gl.ELEMENT_ARRAY_BUFFER)
	//size := []int32{0}
	//gl.GetBufferParameteriv(gl.ELEMENT_ARRAY_BUFFER, gl.BUFFER_SIZE, size)
	gl.DrawElementsOffset(gl.TRIANGLES, len(cubeElements), gl.UNSIGNED_SHORT, 0)

	attributeCoord3d.DisableArray()
	attributeTexCoord.DisableArray()

	// Display the result
	glfw.SwapBuffers()
}
Ejemplo n.º 4
0
func main() {
	glfw.Init()
	defer glfw.Terminate()

	glfw.OpenWindow(640, 480, 8, 8, 8, 8, 0, 0, glfw.Windowed)
	defer glfw.CloseWindow()

	glfw.SetWindowTitle("Tile test")
	glfw.Enable(glfw.StickyKeys)
	glfw.SetSwapInterval(1)
	glfw.SetKeyCallback(inputCallback)

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, GridWidth, GridHeight, 0, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.Disable(gl.DEPTH_TEST)
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	initResources()
	initWorld()

	for Running {
		if (time.Since(DT).Nanoseconds() / 1000000) > 15 { //don't loop faster than every 15ms
			DT = time.Now()
			gl.Clear(gl.COLOR_BUFFER_BIT)
			player.update()
			renderScene()
			glfw.SwapBuffers()
		}
	}
}
Ejemplo n.º 5
0
Archivo: main.go Proyecto: sycoso/glfw
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.LoadIdentity()
	gl.Translatef(-1.5, 0, -6)
	gl.Rotatef(trisAngle, 0, 1, 0)

	gl.Begin(gl.TRIANGLES)
	gl.Color3f(1, 0, 0)
	gl.Vertex3f(0, 1, 0)
	gl.Color3f(0, 1, 0)
	gl.Vertex3f(-1, -1, 0)
	gl.Color3f(0, 0, 1)
	gl.Vertex3f(1, -1, 0)
	gl.End()

	gl.LoadIdentity()
	gl.Translatef(1.5, 0, -6)
	gl.Rotatef(quadAngle, 1, 0, 0)
	gl.Color3f(0.5, 0.5, 1.0)

	gl.Begin(gl.QUADS)
	gl.Vertex3f(-1, 1, 0)
	gl.Vertex3f(1, 1, 0)
	gl.Vertex3f(1, -1, 0)
	gl.Vertex3f(-1, -1, 0)
	gl.End()

	trisAngle += 0.2
	quadAngle -= 0.15

	glfw.SwapBuffers()
}
Ejemplo n.º 6
0
func display() {
	// Clear the background as white
	gl.ClearColor(1.0, 1.0, 1.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	// Use the GLSL program
	gl.UseProgram(program)

	gl.BindBuffer(gl.ARRAY_BUFFER, vboTriangle)
	gl.EnableVertexAttribArray(attributeCoord2d)

	// Describe our vertices array to OpenGL (it can't guess its format automatically)
	gl.VertexAttribPointer(attributeCoord2d, 2, gl.FLOAT, gl.FALSE, 0, gl.Pointer(nil))

	gl.EnableVertexAttribArray(attributeColor)
	gl.BindBuffer(gl.ARRAY_BUFFER, vboTriangleColors)
	gl.VertexAttribPointer(attributeColor, 3, gl.FLOAT, gl.FALSE, 0, gl.Pointer(nil))

	// Push each element in buffer_vertices to the vertex shader
	gl.DrawArrays(gl.TRIANGLES, 0, 3)

	gl.DisableVertexAttribArray(attributeCoord2d)
	gl.DisableVertexAttribArray(attributeColor)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0) // Unbind

	// Display the result
	glfw.SwapBuffers()
}
Ejemplo n.º 7
0
func display() {
	// Clear the background as white
	gl.ClearColor(1.0, 1.0, 1.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	// Use the GLSL program
	program.Use()

	uniformMTransform.UniformMatrix4fv(1, false, matrix)

	vboTriangle.Bind(gl.ARRAY_BUFFER)

	attributeCoord3d.EnableArray()
	// Describe our vertices array to OpenGL (it can't guess its format automatically)
	attributeCoord3d.AttribPointerOffset(3, gl.FLOAT, false, 6*4, 0)

	attributeColor.EnableArray()
	attributeColor.AttribPointerOffset(3, gl.FLOAT, false, 6*4, 3*4)

	// Push each element in buffer_vertices to the vertex shader
	gl.DrawArrays(gl.TRIANGLES, 0, 3)

	attributeCoord3d.DisableArray()
	attributeColor.DisableArray()

	// Display the result
	glfw.SwapBuffers()
}
Ejemplo n.º 8
0
func display() {
	// Clear the background as white
	gl.ClearColor(1.0, 1.0, 1.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	// Use the GLSL program
	program.Use()

	// Faster fade in and out than in the wikibook
	curFade := math.Sin(glfw.Time())

	uniformFade.Uniform1f(float32(curFade))

	vboTriangle.Bind(gl.ARRAY_BUFFER)

	attributeCoord2d.EnableArray()
	// Describe our vertices array to OpenGL (it can't guess its format automatically)
	attributeCoord2d.AttribPointerOffset(2, gl.FLOAT, false, 5*4, 0)

	attributeColor.EnableArray()
	attributeColor.AttribPointerOffset(3, gl.FLOAT, false, 5*4, 2*4)

	// Push each element in buffer_vertices to the vertex shader
	gl.DrawArrays(gl.TRIANGLES, 0, 3)

	attributeCoord2d.DisableArray()
	attributeColor.DisableArray()

	// Display the result
	glfw.SwapBuffers()
}
Ejemplo n.º 9
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()
	}
}
Ejemplo n.º 10
0
// 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)
	}
}
Ejemplo n.º 11
0
Archivo: main.go Proyecto: 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()
	}
}
Ejemplo n.º 12
0
Archivo: main.go Proyecto: 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)
	}

}
Ejemplo n.º 13
0
func Render() {
	UpdateViewpos()
	ClearScene()
	gl.Begin(gl.QUADS)
	for i := range polys {
		polys[i].Render()
	}
	gl.End()
	glfw.SwapBuffers()
}
Ejemplo n.º 14
0
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Color3f(1, 1, 1)
	drawShapes(space)

	glfw.SwapBuffers()
}
Ejemplo n.º 15
0
Archivo: main.go Proyecto: 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()
	}
}
Ejemplo n.º 16
0
func PostFrame() {
	for _, l := range lines {
		doDrawLine(l)
	}
	for _, ent := range ents {
		doDrawEnt(ent)
	}
	lines = lines[0:0]
	ents = ents[0:0]

	glfw.SwapBuffers()
}
Ejemplo n.º 17
0
Archivo: main.go Proyecto: 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
	}
}
Ejemplo n.º 18
0
func loop() {
	e := initTriangleShaders()

	if e != nil {
		log.Fatalln(e.Error())
	}

	for esc {
		gl.ClearColor(0.0, 0.0, 0.0, 0.0)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		drawTriangle()
		glfw.SwapBuffers()
		timeSince()
	}
}
Ejemplo n.º 19
0
// Render stuff
func Draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.LoadIdentity()

	gl.Translatef(-1.5, 0, -6)
	gl.Begin(gl.TRIANGLES)
	gl.Color3f(1, 0, 0)
	gl.Vertex3f(0, 1, 0)
	gl.Color3f(0, 1, 0)
	gl.Vertex3f(-1, -1, 0)
	gl.Color3f(0, 0, 1)
	gl.Vertex3f(1, -1, 0)
	gl.End()

	glfw.SwapBuffers()
}
Ejemplo n.º 20
0
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()
	}
}
Ejemplo n.º 21
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
	}
}
Ejemplo n.º 22
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()
}
Ejemplo n.º 23
0
func draw() {

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

	gl.PushMatrix()
	gl.Rotated(view_rotx, 1.0, 0.0, 0.0)
	gl.Rotated(view_roty, 0.0, 1.0, 0.0)
	gl.Rotated(view_rotz, 0.0, 0.0, 1.0)

	gl.PushMatrix()
	gl.Translated(-3.0, -2.0, 0.0)
	gl.Rotated(angle, 0.0, 0.0, 1.0)
	gl.CallList(gear1)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(3.1, -2.0, 0.0)
	gl.Rotated(-2.0*angle-9.0, 0.0, 0.0, 1.0)
	gl.CallList(gear2)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(-3.1, 4.2, 0.0)
	gl.Rotated(-2.0*angle-25.0, 0.0, 0.0, 1.0)
	gl.CallList(gear3)
	gl.PopMatrix()

	gl.PopMatrix()

	glfw.SwapBuffers()

	Frames++
	{
		t := glfw.Time()
		if t-T0 >= 5 {
			seconds := (t - T0)
			fps := float64(Frames) / seconds
			print(Frames, " frames in ", int(seconds), " seconds = ", int(fps), " FPS\n")
			T0 = t
			Frames = 0
		}
	}
}
Ejemplo n.º 24
0
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.LoadIdentity()

	gl.Translatef(0, 0, -20+globalState.MousePos.Z*globalState.speed)

	gl.Rotatef(globalState.Rot.X, 1, 0, 0)
	gl.Rotatef(globalState.Rot.Y, 0, 1, 0)
	gl.Rotatef(globalState.Rot.Z, 0, 0, 1)

	if globalState.speed != 1 {
		gl.Scalef(globalState.speed, globalState.speed, globalState.speed)
	}

	gl.Begin(gl.QUADS)
	for i, _ := range mesh.Faces {
		if colors, ok := faceColor[i]; ok {
			gl.Color3f(colors[0], colors[1], colors[2])
		} else {
			faceColor[i] = make([]float32, 3)
			faceColor[i][0] = rand.Float32()
			faceColor[i][1] = rand.Float32()
			faceColor[i][2] = rand.Float32()
			gl.Color3f(faceColor[i][0], faceColor[i][1], faceColor[i][2])
		}

		face := &mesh.Faces[i]
		for j, _ := range face.Vertices {
			var v *wfobj.Vertex
			if len(face.Normals) > 0 {
				v = &face.Normals[j]
				gl.Normal3f(v.X, v.Y, v.Z)
			}
			v = &face.Vertices[j]
			gl.Vertex3f(v.X, v.Y, v.Z)
		}
	}
	gl.End()

	glfw.SwapBuffers()
}
Ejemplo n.º 25
0
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
	}
}
Ejemplo n.º 26
0
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.LoadIdentity()
	gl.Translatef(1.5, 0, -6)
	gl.Rotatef(quadAngle, 1, 1, 1)

	gl.Begin(gl.QUADS)
	for i, _ := range mesh.Faces {
		gl.Color3f(rand.Float32(), rand.Float32(), rand.Float32())
		face := &mesh.Faces[i]
		for j, _ := range face.Vertices {
			v := &face.Vertices[j]
			gl.Vertex3f(v.X, v.Y, v.Z)
		}
	}
	gl.End()

	quadAngle -= 0.15

	glfw.SwapBuffers()
}
Ejemplo n.º 27
0
Archivo: ca.go Proyecto: samnardoni/ca
func draw() {
	for y := 0; y < Size; y++ {
		for x := 0; x < Size; x++ {

			var color uint8
			if grid.Front()[y][x] {
				color = 0x00
			} else {
				color = 0xFF
			}

			pixels[(y*Size+x)*3+0] = color
			pixels[(y*Size+x)*3+1] = color
			pixels[(y*Size+x)*3+2] = color

		}
	}

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

	gl.TexImage2D(gl.TEXTURE_2D, 0, 3, Size, Size, 0, gl.RGB, gl.UNSIGNED_BYTE, pixels)

	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

	gl.Begin(gl.QUADS)
	gl.TexCoord2f(0.0, 1.0)
	gl.Vertex3f(-1.0, -1.0, 0.0)
	gl.TexCoord2f(1.0, 1.0)
	gl.Vertex3f(1.0, -1.0, 0.0)
	gl.TexCoord2f(1.0, 0.0)
	gl.Vertex3f(1.0, 1.0, 0.0)
	gl.TexCoord2f(0.0, 0.0)
	gl.Vertex3f(-1.0, 1.0, 0.0)
	gl.End()

	glfw.SwapBuffers()
}
Ejemplo n.º 28
0
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()
	}
}
Ejemplo n.º 29
0
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// Food
	for coord, _ := range food {
		gl.LoadIdentity()
		gl.Scalef(0.05, 0.05, 1)
		gl.Translatef(float32(coord.x)-5, float32(coord.y)-5, -1)

		gl.Begin(gl.QUADS)
		gl.Color3f(0.5, float32(coord.x)/10, float32(coord.y)/10)
		gl.Vertex3f(0.25, 0.75, 0)
		gl.Vertex3f(0.75, 0.75, 0)
		gl.Color3f(0.3, float32(coord.x)/10-0.2, float32(coord.y)/10-0.2)
		gl.Vertex3f(0.75, 0.25, 0)
		gl.Vertex3f(0.25, 0.25, 0)
		gl.End()
	}

	//Snake
	for _, coord := range snake.coords {
		gl.LoadIdentity()
		gl.Scalef(0.05, 0.05, 1)
		gl.Translatef(float32(coord.x)-5, float32(coord.y)-5, -1)

		gl.Begin(gl.QUADS)
		gl.Color3f(float32(coord.y)/10, float32(coord.x)/10, 0.5)
		gl.Vertex3f(0, 1, 0)
		gl.Vertex3f(1, 1, 0)
		gl.Color3f(float32(coord.y)/10-0.2, float32(coord.x)/10-0.2, 0.3)
		gl.Vertex3f(1, 0, 0)
		gl.Vertex3f(0, 0, 0)
		gl.End()
	}

	glfw.SwapBuffers()
}
Ejemplo n.º 30
0
func (v *Video) Render() {
	runtime.LockOSThread()

	for running {
		select {
		case val := <-v.tick:
			slice := make([]uint8, len(val)*3)
			for i := 0; i < len(val); i = i + 1 {
				slice[i*3+0] = (uint8)((val[i] >> 16) & 0xff)
				slice[i*3+1] = (uint8)((val[i] >> 8) & 0xff)
				slice[i*3+2] = (uint8)((val[i]) & 0xff)
			}

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

			v.tex.Bind(gl.TEXTURE_2D)
			gl.TexImage2D(gl.TEXTURE_2D, 0, 3, 256, 240, 0, gl.RGB, gl.UNSIGNED_BYTE, slice)
			gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
			gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

			gl.Begin(gl.QUADS)
			gl.TexCoord2f(0.0, 1.0)
			gl.Vertex3f(-1.0, -1.0, 0.0)
			gl.TexCoord2f(1.0, 1.0)
			gl.Vertex3f(1.0, -1.0, 0.0)
			gl.TexCoord2f(1.0, 0.0)
			gl.Vertex3f(1.0, 1.0, 0.0)
			gl.TexCoord2f(0.0, 0.0)
			gl.Vertex3f(-1.0, 1.0, 0.0)
			gl.End()

			glfw.SwapBuffers()
			v.fpsmanager.FramerateDelay()
		}
	}
}