Ejemplo n.º 1
0
func (s *Sprite) Draw(x, y, angle, scale float32, blend bool) {
	gl.Enable(gl.TEXTURE_2D)
	gl.Disable(gl.COLOR_MATERIAL)
	if blend {
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.Enable(gl.BLEND)
	} else {
		gl.Disable(gl.BLEND)
		gl.BlendFunc(gl.ONE, gl.ZERO)
	}

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(x, y, 0)
	gl.Rotatef(angle*360/(2*math.Pi), 0, 0, 1)
	gl.Scalef(scale, scale, 1)
	s.tex.Bind(gl.TEXTURE_2D)
	gl.Begin(gl.QUADS)
	gl.Color3f(1, 1, 1)
	gl.TexCoord2d(0, 0)
	gl.Vertex3f(-0.5*s.width, -0.5*s.height, 0)
	gl.TexCoord2d(1, 0)
	gl.Vertex3f(0.5*s.width, -0.5*s.height, 0)
	gl.TexCoord2d(1, 1)
	gl.Vertex3f(0.5*s.width, 0.5*s.height, 0)
	gl.TexCoord2d(0, 1)
	gl.Vertex3f(-0.5*s.width, 0.5*s.height, 0)
	gl.End()
	gl.Disable(gl.TEXTURE_2D)
	gl.Disable(gl.BLEND)
}
Ejemplo n.º 2
0
// OpenWindow opens a new window with the given size.
func OpenWindow(w, h int) error {
	glfw.OpenWindowHint(glfw.WindowNoResize, 1)

	r, g, b := 0, 0, 0 // defaults
	a := 8             // 8-bit alpha channel
	d, s := 0, 0       // no depth or stencil buffers
	m := glfw.Windowed
	if err := glfw.OpenWindow(w, h, r, g, b, a, d, s, m); err != nil {
		return err
	}

	if gl.Init() != 0 {
		return errors.New("Failed to initialize OpenGL")
	}

	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, 0.0)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), 0, float64(-h), -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translated(0, float64(-h), 0)
	return nil
}
Ejemplo n.º 3
0
func (this *Window) initGL() {

	runtime.LockOSThread()

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

	gl.ShadeModel(gl.SMOOTH)
	gl.CullFace(gl.BACK)
	gl.FrontFace(gl.CCW)
	gl.Enable(gl.CULL_FACE)
	gl.Enable(gl.DEPTH_TEST)
	gl.Enable(gl.LIGHTING)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Enable(gl.TEXTURE_2D)
	gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
	var magFilter, minFilter = gl.LINEAR, gl.LINEAR
	if globals.CreateMipmaps {
		minFilter = gl.LINEAR_MIPMAP_LINEAR
	}
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter)
	gl.Enable(gl.NORMALIZE)
	gl.ClearColor(.1, .1, .1, 1)
	this.setGLViewport()
}
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: glfps.go Proyecto: shogg/glfps
func drawDigits(x, y int, digits []int8) {

	s := sdl.GetVideoSurface()
	lft, rgt, btm, top := 0.0, float64(s.W), float64(s.H), 0.0

	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()
	gl.Ortho(lft, rgt, btm, top, 0.0, 1.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	w := digitImages[0].Rect.Dx()
	for i := 0; i < len(digits); i++ {
		img := digitImages[digits[i]]
		drawImage(x-w*i-i, y, img)
	}

	gl.MatrixMode(gl.MODELVIEW)
	gl.PopMatrix()

	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
}
Ejemplo n.º 6
0
func (pen *Pen) lineTo(p Point) {

	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Enable(gl.LINE_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.Color4f(0.0, 0.0, 0.0, 0.1)

	gl.Begin(gl.LINES)

	for _, s := range pen.points {

		if s.x == 0 && s.y == 0 {
			continue
		}

		if p.distanceTo(s) < 20.0 {

			gl.Vertex2i(int(p.x), int(p.y))
			gl.Vertex2i(int(s.x), int(s.y))

		}

	}

	gl.End()

	pen.n = (pen.n + 1) % len(pen.points)
	pen.points[pen.n] = p

	pen.moveTo(p)

}
Ejemplo n.º 7
0
Archivo: main.go Proyecto: sycoso/glfw
func (pen *Pen) lineTo(x, y int) {
	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Enable(gl.LINE_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Color4f(0.0, 0.0, 0.0, 0.1)
	gl.Begin(gl.LINES)

	var p [2]int
	for i := range pen.points {
		p = pen.points[i]
		if p[0] == 0 && p[1] == 0 {
			continue
		}

		if distanceTo(x, y, p[0], p[1]) < 10.0 {
			gl.Vertex2i(x, y)
			gl.Vertex2i(p[0], p[1])
		}
	}

	gl.End()

	pen.n = (pen.n + 1) % len(pen.points)
	pen.points[pen.n][0] = x
	pen.points[pen.n][1] = y
	pen.moveTo(x, y)
}
Ejemplo n.º 8
0
func (this *Window) initGL() {
	gl.ShadeModel(gl.SMOOTH) //SMOOTH or FLAT
	gl.CullFace(gl.BACK)
	gl.FrontFace(gl.CCW)
	gl.Enable(gl.CULL_FACE)
	gl.Enable(gl.DEPTH_TEST)
	gl.Enable(gl.LIGHTING)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	/*gl.Enable(gl.FOG)
	gl.Fogi(gl.FOG_MODE, gl.EXP)
	gl.Fogfv(gl.FOG_COLOR, []float32{0.5,0.5,0.5,1.0})
	gl.Fogf(gl.FOG_DENSITY, 0.0035)
	gl.Hint(gl.FOG_HINT, gl.DONT_CARE)
	gl.Fogf(gl.FOG_START, 1.0)
	gl.Fogf(gl.FOG_END  , 5000.0)//*/
	gl.Enable(gl.TEXTURE_2D)
	gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE) //before: decal, std: modulate
	//gl.TexParameteri(gl.TEXTURE_2D, gl.GENERATE_MIPMAP, true) //mipmaps (dont use it!, its bad!)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)               //GL_LINEAR or GL_NEAREST, no mipmap here
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR) //*/
	gl.ClearColor(.1, .1, .1, 1)
	//gl.Enable(gl.PRIMITIVE_RESTART)
	//gl.PrimitiveRestartIndex()
	this.setGLViewport()
}
Ejemplo n.º 9
0
// general OpenGL initialization
func initGL() {
	LoadGLTexture("data/star.bmp")

	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE)
	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0.0, 0.0, 0.0, 0.5)
	gl.ClearDepth(1.0)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
}
Ejemplo n.º 10
0
func initGL() {
	gl.EnableClientState(gl.VERTEX_ARRAY)
	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0, 0, 0, 0)
	gl.ClearDepth(1)
	gl.DepthFunc(gl.LEQUAL)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
	gl.Enable(gl.DEPTH_TEST)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
}
Ejemplo n.º 11
0
func plot_list(list uint) {
	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.PointSize(1.0)
	gl.LoadIdentity()
	gl.Rotated(xrot, 1, 0, 0)
	gl.Rotated(yrot, 0, 1, 0)
	gl.Rotated(zrot, 0, 0, 1)
	gl.Scaled(scale, scale, scale)
	gl.Translated(xoff, yoff, zoff)
	gl.CallList(list)
	gl.Flush()
}
Ejemplo n.º 12
0
// Initialize OpenGL settings.
func glInit() {
	pos := []float32{5.0, 5.0, 10.0, 0.0}

	gl.Lightfv(gl.LIGHT0, gl.POSITION, pos)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Enable(gl.CULL_FACE)
	gl.Enable(gl.LIGHTING)
	gl.Enable(gl.LIGHT0)
	gl.Enable(gl.DEPTH_TEST)
	gl.Enable(gl.NORMALIZE)
	gl.Enable(gl.COLOR_MATERIAL)
	gl.ColorMaterial(gl.FRONT_AND_BACK, gl.AMBIENT_AND_DIFFUSE)
	gl.Enable(gl.LINE_SMOOTH)
	gl.Enable(gl.POINT_SMOOTH)
}
Ejemplo n.º 13
0
// general OpenGL initialization
func initGL() {
	gl.Enable(gl.TEXTURE_2D)
	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0.0, 0.0, 0.0, 0.5)
	gl.ClearDepth(1.0)
	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LEQUAL)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)

	// Setup the light
	gl.Lightfv(gl.LIGHT1, gl.AMBIENT, lightAmbient[:])   // ambient lighting
	gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, lightDiffuse[:])   // make it diffuse
	gl.Lightfv(gl.LIGHT1, gl.POSITION, lightPosition[:]) // and place it
	gl.Enable(gl.LIGHT1)                                 // and finally turn it on.

	gl.Color4f(1.0, 1.0, 1.0, 0.5)     // Full Brightness, 50% Alpha ( NEW )
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE) // Blending Function For Translucency Based On Source Alpha Value ( NEW )
}
Ejemplo n.º 14
0
// general OpenGL initialization
func initGL() {
	LoadGLTextures("data/mud.bmp")

	gl.Enable(gl.TEXTURE_2D)
	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0.0, 0.0, 0.0, 0.0)
	gl.ClearDepth(1.0)
	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LEQUAL)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)

	gl.Lightfv(gl.LIGHT1, gl.AMBIENT, lightAmbient[:])
	gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, lightDiffuse[:])
	gl.Lightfv(gl.LIGHT1, gl.POSITION, lightPosition[:])
	gl.Enable(gl.LIGHT1)

	gl.Color4f(1.0, 1.0, 1.0, 0.5)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE)
}
Ejemplo n.º 15
0
Archivo: main.go Proyecto: sycoso/glfw
func initGL() (err error) {
	if err = loadTextures(); err != nil {
		return
	}

	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0, 0, 0, 0)
	gl.ClearDepth(1)
	gl.DepthFunc(gl.LEQUAL)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.DEPTH_TEST)
	gl.Color4f(1, 1, 1, 0.5)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE)

	gl.Lightfv(gl.LIGHT1, gl.AMBIENT, ambient)
	gl.Lightfv(gl.LIGHT1, gl.AMBIENT, diffuse)
	gl.Lightfv(gl.LIGHT1, gl.POSITION, lightpos)
	gl.Enable(gl.LIGHT1)
	return
}
Ejemplo n.º 16
0
func special(key, x, y int) {
	switch key {
	case glut.KEY_F1:
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.Enable(gl.BLEND)
		gl.Enable(gl.LINE_SMOOTH)
		gl.Enable(gl.POINT_SMOOTH)
	case glut.KEY_F2:
		gl.Disable(gl.BLEND)
		gl.Disable(gl.LINE_SMOOTH)
		gl.Disable(gl.POINT_SMOOTH)
	case glut.KEY_UP:
		thrust = true
		thrustTime = glut.Get(glut.ELAPSED_TIME)
	case glut.KEY_LEFT:
		left = true
		leftTime = glut.Get(glut.ELAPSED_TIME)
	case glut.KEY_RIGHT:
		right = true
		rightTime = glut.Get(glut.ELAPSED_TIME)
	}
}
Ejemplo n.º 17
0
func initGame() {

	viewport.Zoomstd()
	viewport.Rotx(25)
	viewport.Roty(70)

	picker = NewPicker()

	sdl.Init(sdl.INIT_VIDEO)
	if ttf.Init() != 0 {
		panic("Could not initalize fonts")
	}

	sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1)
	screen := sdl.SetVideoMode(1024, 600, 32, sdl.OPENGL|sdl.RESIZABLE)

	if screen == nil {
		sdl.Quit()
		panic("Couldn't set GL video mode: " + sdl.GetError() + "\n")
	}

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

	sdl.WM_SetCaption("Amberfell", "amberfell")

	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	// gl.ShadeModel(gl.FLAT)

	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.ShadeModel(gl.SMOOTH)
	gl.Enable(gl.LIGHTING)
	gl.Enable(gl.LIGHT0)
	gl.Enable(gl.LIGHT1)

	gl.Enable(gl.COLOR_MATERIAL)

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	gl.ClearDepth(1.0)       // Depth Buffer Setup
	gl.Enable(gl.DEPTH_TEST) // Enables Depth Testing
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.FASTEST)

	gl.Enable(gl.TEXTURE_2D)
	//	LoadMapTextures()
	LoadPlayerTextures()
	LoadWolfTextures()
	InitItems()

	pauseFont = NewFont("res/Jura-DemiBold.ttf", 48, color.RGBA{255, 255, 255, 0})
	consoleFont = NewFont("res/Jura-DemiBold.ttf", 16, color.RGBA{255, 255, 255, 0})
	inventoryItemFont = NewFont("res/Jura-DemiBold.ttf", 14, color.RGBA{240, 240, 240, 0})

	textures[TEXTURE_PICKER] = loadTexture("res/dial.png")
	terrainTexture = loadTexture("res/tiles.png")
	itemsTexture = loadTexture("res/items.png")

	gVertexBuffer = NewVertexBuffer(10000, terrainTexture)
	gGuiBuffer = NewVertexBuffer(1000, terrainTexture)

	WolfModel = LoadModel("res/wolf.mm3d")

	TheWorld = NewWorld()

	ThePlayer = new(Player)
	ThePlayer.Init(0, PLAYER_START_X, PLAYER_START_Z)

	inventory = NewInventory()

	viewport.Reshape(int(screen.W), int(screen.H))
	PreloadChunks(400)

}
Ejemplo n.º 18
0
func (s *Sim) Draw() {

	//start := time.Now()

	// Init OpenGL
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Enable(gl.LINE_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.Begin(gl.POINTS)

	gl.PointSize(1)
	for x := int(0); x < int(300); x += 1 {
		for y := int(0); y < int(300); y += 1 {
			pot := s.potential(s.units[0], float64(x), float64(y))

			//r := math.Min(pot*2, 1)
			//g := math.Min(pot*2, 2)-1
			gl.Color4f(1-float32(pot), 1-float32(pot), 1-float32(pot), 1)
			gl.Vertex2i(x, y)
		}
	}

	gl.End()

	// Draw Units
	gl.Begin(gl.POINTS)
	for i, unit := range s.units {
		if i == 0 {
			gl.Color4f(1, 0, 0, 1)
			fmt.Println(unit.pos.X)
		} else {
			gl.Color4f(0, 1, 0, 1)
		}

		gl.Vertex2f(float32(unit.pos.X), float32(unit.pos.Y))
	}
	gl.End()

	// Nav mesh
	/*
		for e := s.nav.nodes.Front(); e != nil; e = e.Next() {
			nn := e.Value.(*NavNode)

			gl.Color4f(0, 0, 1, 0.2)

			if s.markedNodes[nn] {
				gl.Color4f(1, 0, 0, 0.2)
			}

			gl.Begin(gl.POLYGON)
			for _, pos := range nn.node.Points {
				if pos == nil {
					continue
				}

				gl.Vertex2f(float32(pos.X), float32(pos.Y))
			}
			gl.End()

			gl.Color4f(0, 0, 1, 1)
			gl.Begin(gl.LINE_LOOP)
			for _, pos := range nn.node.Points {
				if pos == nil {
					continue
				}

				gl.Vertex2f(float32(pos.X), float32(pos.Y))
			}
			gl.End()
		}
	*/
	// Draw Path
	if s.units[0].path != nil {
		gl.Begin(gl.LINE_STRIP)
		gl.Color4f(1, 0, 0, 0.2)
		for e := s.units[0].path.Front(); e != nil; e = e.Next() {
			pos := e.Value.(*geo.Vec)
			gl.Vertex2f(float32(pos.X), float32(pos.Y))
		}
		gl.End()
	}

	// Draw Links
	/*gl.Color4f(1, 0, 0, 1)
	gl.Begin(gl.LINES)
	for i, link := range nn.links {
		pt1 := nn.node.Points[i]
		pt2 := nn.node.Points[(i+1)%nn.node.Len()]
		lineCenter := &geo.Vec{(pt1.X+pt2.X)/2, (pt1.Y+pt2.Y)/2}

		center := link.node.Center()

		gl.Vertex2d(lineCenter.X, lineCenter.Y)
		gl.Vertex2d(center.X, center.Y)
	}
	gl.End()*/

	/*
		fps := 1/(float64(time.Since(start))/float64(time.Second))
		s.ui.fpsLabel2.SetLabel(fmt.Sprintf("%f", fps))
	*/
}
Ejemplo n.º 19
0
func testPlot(dimension, order int) {
	var (
		iterations float64   = 0
		start_t              = time.Now()
		split      time.Time = start_t
		total      time.Duration
		fps        float64 = 1.0

		new_attractor, redraw bool = true, true
		npoints               int  = 1e5

		coeffs []float64
		//offsets, offset_coeffs []float64
		start Matrix = MakeMatrix(1, int(math.Max(3, float64(dimension))))
		points, points2/*, points3*/ Matrix

	//attractor = gl.GenLists(1);
	)

	//offsets = make([]float64, ncoeffs(order))
	//offset_coeffs = make([]float64, ncoeffs(order))
	//coeffs = make([]float64, dimension + nCoeffs(order, dimension) * dimension)

	//for i := range offsets { offsets[i] += rand.Float64() }

	for handleEvents(&new_attractor, &redraw, &npoints) {

		xoff += xvel / fps
		yoff += yvel / fps
		zoff += zvel / fps
		xrot += xrotvel / fps
		yrot += yrotvel / fps
		zrot += zrotvel / fps
		scale += svel / fps

		if new_attractor {
			coeffs, start = find_map_with_L(dimension, order, 0.1, 0.4)
			redraw = true
			new_attractor = false
		}
		if redraw {
			points = MakePointMatrix(makeMapFn(dimension, order, coeffs), start, 500, npoints)
			points2 = MakeMatrix(npoints, points.Height())
			//points3 = MakeMatrix(npoints, points.Height())
			redraw = false
			fmt.Println("Redraw", npoints, "points")
		}

		//points2 = points
		//RotationXW(xwrot).Apply(points, points2)
		//RotationYW(xwrot + 0.25).Apply(points2, points3)
		//RotationZW(xwrot + 0.50).Apply(points3, points2)

		if dimension == 4 {
			RotationZW(xwrot).Apply(points, points2)
			xwrot += 0.05
			ApplyW(points2, points2)
		} else {
			points2 = points
		}

		gl.Enable(gl.BLEND)
		gl.Enable(gl.POINT_SMOOTH)
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

		gl.PointSize(1.0)
		gl.LoadIdentity()
		gl.Rotated(xrot, 1, 0, 0)
		gl.Rotated(yrot, 0, 1, 0)
		gl.Rotated(zrot, 0, 0, 1)
		gl.Scaled(scale, scale, scale)
		gl.Translated(xoff, yoff, zoff)

		gl.Color4d(1, 1, 1, 0.25)

		gl.EnableClientState(gl.VERTEX_ARRAY)
		if dimension > 3 {
			gl.VertexPointer(3, (dimension-3)*32, points2.FlatCols())
		} else {
			gl.VertexPointer(3, 0, points2.FlatCols())
		}
		gl.DrawArrays(gl.POINTS, 0, points2.Width())
		gl.DisableClientState(gl.VERTEX_ARRAY)

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

		iterations++
		if time.Since(split).Seconds() > 1.0 {
			total = time.Since(start_t)
			fps = iterations / total.Seconds()
			fmt.Println(iterations, "iterations in", total.Seconds(), "gives",
				fps, "fps")
			split = time.Now()
		}
	}
}
Ejemplo n.º 20
0
Archivo: gotris.go Proyecto: nsf/gotris
func main() {
	runtime.LockOSThread()
	flag.Parse()
	sdl.Init(sdl.INIT_VIDEO)
	defer sdl.Quit()

	sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1)

	if sdl.SetVideoMode(640, 480, 32, sdl.OPENGL) == nil {
		panic("sdl error")
	}

	sdl.WM_SetCaption("Gotris", "Gotris")
	sdl.EnableKeyRepeat(250, 45)

	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Viewport(0, 0, 640, 480)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, 640, 480, 0, -1, 1)

	gl.ClearColor(0, 0, 0, 0)

	//-----------------------------------------------------------------------------

	font, err := LoadFontFromFile("dejavu.font")
	if err != nil {
		panic(err)
	}

	rand.Seed(int64(sdl.GetTicks()))

	gs := NewGameSession(*initLevel, font)
	lastTime := sdl.GetTicks()
	ticker := time.NewTicker(10 * time.Millisecond)

	stop := make(chan byte, 1)
	go func() {
		for {
			switch e := (<-sdl.Events).(type) {
			case sdl.QuitEvent:
				stop <- 0
			case sdl.KeyboardEvent:
				if e.Type == sdl.KEYDOWN {
					running := gs.HandleKey(e.Keysym.Sym)
					if !running {
						stop <- 0
					}
					gs.update <- 0
				}
			}
		}
	}()
loop:
	for {
		select {
		case <-ticker.C:
			gs.update <- 0

		case <-gs.update:
			now := sdl.GetTicks()
			delta := now - lastTime
			lastTime = now

			gs.Update(delta)

			gl.Clear(gl.COLOR_BUFFER_BIT)
			font.Draw(5, 5, fmt.Sprintf("Level: %d | Score: %d", gs.Level, gs.Score))
			gs.Draw()
			gl.Color3ub(255, 255, 255)
			sdl.GL_SwapBuffers()

		case <-stop:
			break loop
		}
	}
}