示例#1
0
文件: main.go 项目: jayschwa/examples
// initGL initializes GLFW and OpenGL.
func initGL() error {
	err := glfw.Init()
	if err != nil {
		return err
	}

	err = glfw.OpenWindow(AtlasSize, AtlasSize, 8, 8, 8, 8, 0, 0, glfw.Windowed)
	if err != nil {
		glfw.Terminate()
		return err
	}

	glfw.SetWindowTitle("Texture atlas example")
	glfw.SetSwapInterval(1)
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetKeyCallback(onKey)

	gl.Init()
	if err = glh.CheckGLError(); err != nil {
		return err
	}

	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.ClearColor(0.2, 0.2, 0.23, 1.0)
	return nil
}
示例#2
0
文件: main.go 项目: jayschwa/examples
// initGL initializes GLFW and OpenGL.
func initGL() error {
	err := glfw.Init()
	if err != nil {
		return err
	}

	glfw.OpenWindowHint(glfw.FsaaSamples, 4)

	err = glfw.OpenWindow(512, 512, 8, 8, 8, 8, 0, 0, glfw.Windowed)
	if err != nil {
		glfw.Terminate()
		return err
	}

	glfw.SetWindowTitle("Meshbuffer 2D example")
	glfw.SetSwapInterval(1)
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetKeyCallback(onKey)

	gl.Init()
	if err = glh.CheckGLError(); err != nil {
		return err
	}

	gl.Disable(gl.DEPTH_TEST)
	gl.Enable(gl.MULTISAMPLE)
	gl.Disable(gl.LIGHTING)
	gl.Enable(gl.COLOR_MATERIAL)
	gl.ClearColor(0.2, 0.2, 0.23, 1.0)
	return nil
}
示例#3
0
文件: gl.go 项目: jteeuwen/dcpu
// initGL initializes GLFW and OpenGL.
func initGL(c *cpu.CPU, width, height int) error {
	err := glfw.Init()
	if err != nil {
		return err
	}

	glfw.OpenWindowHint(glfw.WindowNoResize, 1)

	err = glfw.OpenWindow(width, height, 8, 8, 8, 8, 8, 0, glfw.Windowed)
	if err != nil {
		glfw.Terminate()
		return err
	}

	glfw.SetWindowTitle("DCPU")
	glfw.SetSwapInterval(1)
	glfw.SetWindowSizeCallback(onResize)

	gl.Init()
	err = glh.CheckGLError()
	if err != nil {
		return err
	}

	gl.Disable(gl.LIGHTING)
	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, 1)
	return err
}
示例#4
0
func (r *RenderTarget) resetGlStates() {
	// Define the default OpenGL states
	gl.Disable(gl.CULL_FACE)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.ALPHA_TEST)
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.MatrixMode(gl.MODELVIEW)
	gl.EnableClientState(gl.VERTEX_ARRAY)
	gl.EnableClientState(gl.COLOR_ARRAY)
	gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
	r.glStatesSet = true

	// Apply the default SFML states
	r.applyBlendMode(BlendAlpha)
	r.applyTransform(IdentityTransform())
	r.applyTexture(nil)
	/*if (Shader::isAvailable()){
		r.applyShader(nil)
	}*/
	r.useVertexCache = false

	// Set the default view
	r.SetView(r.View())
}
示例#5
0
文件: main.go 项目: jayschwa/examples
// initGL initializes GLFW and OpenGL.
func initGL() error {
	err := glfw.Init()
	if err != nil {
		return err
	}

	err = glfw.OpenWindow(640, 480, 8, 8, 8, 8, 0, 0, glfw.Windowed)
	if err != nil {
		glfw.Terminate()
		return err
	}

	glfw.SetWindowTitle("go-gl/gltext: Bitmap font example")
	glfw.SetSwapInterval(1)
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetKeyCallback(onKey)

	errno := gl.Init()
	if errno != gl.NO_ERROR {
		str, err := glu.ErrorString(errno)
		if err != nil {
			return fmt.Errorf("Unknown openGL error: %d", errno)
		}
		return fmt.Errorf(str)
	}

	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.ClearColor(0.2, 0.2, 0.23, 0.0)
	return nil
}
示例#6
0
文件: main.go 项目: andrebq/exp
func initGL() error {
	gl.Init()
	if err := glh.CheckGLError(); err != nil {
		return err
	}

	gl.Disable(gl.DEPTH_TEST)
	gl.Enable(gl.MULTISAMPLE)
	gl.Disable(gl.LIGHTING)
	gl.Enable(gl.COLOR_MATERIAL)
	gl.ClearColor(0, 0, 0, 1)

	return nil
}
示例#7
0
func (v *Video) Reshape(width int, height int) {
	x_offset := 0
	y_offset := 0

	r := ((float64)(height)) / ((float64)(width))

	if r > 0.9375 { // Height taller than ratio
		h := (int)(math.Floor((float64)(0.9375 * (float64)(width))))
		y_offset = (height - h) / 2
		height = h
	} else if r < 0.9375 { // Width wider
		var scrW, scrH float64
		if ppu.OverscanEnabled {
			scrW = 240.0
			scrH = 224.0
		} else {
			scrW = 256.0
			scrH = 240.0
		}

		w := (int)(math.Floor((float64)((scrH / scrW) * (float64)(height))))
		x_offset = (width - w) / 2
		width = w
	}

	gl.Viewport(x_offset, y_offset, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(-1, 1, -1, 1, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Disable(gl.DEPTH_TEST)
}
示例#8
0
//Draws all the sprites in the supplied slice
func (sheet SpriteSheet) Draw(sprites []*Sprite) {
	gl.Enable(gl.TEXTURE_2D)
	sheet.texture.Bind(gl.TEXTURE_2D)

	for _, sprite := range sprites {
		gl.Begin(gl.TRIANGLE_STRIP)
		{
			gl.TexCoord2f(sprite.left, sprite.bottom)
			gl.Vertex2f(sprite.X, sprite.Y)

			gl.TexCoord2f(sprite.left, sprite.top)
			gl.Vertex2f(sprite.X, sprite.Y+sprite.H)

			gl.TexCoord2f(sprite.right, sprite.bottom)
			gl.Vertex2f(sprite.X+sprite.W, sprite.Y)

			gl.TexCoord2f(sprite.right, sprite.top)
			gl.Vertex2f(sprite.X+sprite.W, sprite.Y+sprite.H)
		}
		gl.End()
	}

	sheet.texture.Unbind(gl.TEXTURE_2D)
	gl.Disable(gl.TEXTURE_2D)
}
func Init() {

	runtime.LockOSThread()

	// Initialize GLFW

	var err error

	if err = glfw.Init(); err != nil {
		log.Fatalf("%v\n", err)
		return
	}

	err = glfw.OpenWindow(SCREEN_WIDTH, SCREEN_HEIGHT,
		0, 0, 0, 0, 0, 0, glfw.Windowed)

	if err != nil {
		log.Fatalf("%v\n", err)
		return
	}

	glfw.SetWindowTitle("Mandelbrot")
	glfw.SetSwapInterval(1)

	glfw.SetWindowSizeCallback(onResize)
	glfw.SetWindowCloseCallback(onClose)
	glfw.SetMouseButtonCallback(onMouseBtn)
	glfw.SetMouseWheelCallback(onMouseWheel)
	glfw.SetKeyCallback(onKey)
	glfw.SetCharCallback(onChar)

	// Initialize OpenGL
	gl.Disable(gl.DEPTH_TEST)
	gl.ClearColor(0, 0, 0, 0)
}
示例#10
0
func onKey(key, state int) {
	switch key {
	case glfw.KeyEsc:
		running = false
	case 76: // L
		if state == 1 {
			if light = !light; !light {
				gl.Disable(gl.LIGHTING)
			} else {
				gl.Enable(gl.LIGHTING)
			}
		}
	case 70: // F
		if state == 1 {
			if filter++; filter >= len(textures) {
				filter = 0
			}
		}
	case glfw.KeyPageup:
		z -= 0.2
	case glfw.KeyPagedown:
		z += 0.2
	case glfw.KeyUp:
		speed[0] -= 0.1
	case glfw.KeyDown:
		speed[0] += 0.1
	case glfw.KeyLeft:
		speed[1] -= 0.1
	case glfw.KeyRight:
		speed[1] += 0.1
	}
}
示例#11
0
文件: skia.go 项目: phaikawl/gosui
//DrawElementsInArea is used for redrawing
func (b *Backend) DrawElementsInArea(l gs.DrawPriorityList, area image.Rectangle) {
	gl.Enable(gl.SCISSOR_TEST)
	gl.Scissor(area.Min.X, area.Min.Y, area.Dx(), area.Dy())
	for _, o := range l {
		o.Draw(b)
	}
	gl.Disable(gl.SCISSOR_TEST)
}
示例#12
0
// Binds the framebuffer for drawing.
func (fb *Framebuffer) Bind() {
	fb.Buffer.Bind()
	gl.Viewport(0, 0, fb.Width, fb.Height)
	gl.Enable(gl.TEXTURE_2D)
	gl.Disable(gl.DEPTH_TEST)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Enable(gl.BLEND)
}
示例#13
0
func main() {
	_ = fmt.Sprint()

	if !glfw.Init() {
		panic("Can't init glfw!")
	}
	defer glfw.Terminate()

	// antialiasing
	//glfw.WindowHint(glfw.Samples, 4)

	window, err = glfw.CreateWindow(WindowWidth, WindowHeight, "Mozaik", nil, nil)
	if err != nil {
		panic(err)
	}
	defer window.Destroy()

	// Ensure thread context
	window.MakeContextCurrent()
	//glfw.SwapInterval(1)

	window.SetKeyCallback(keyCb)
	window.SetMouseButtonCallback(mouseCb)

	gl.Init()
	gl.ClearColor(0.9, 0.85, 0.46, 0.0)
	// useless in 2D
	gl.Disable(gl.DEPTH_TEST)
	// antialiasing
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Enable(gl.LINE_SMOOTH)

	for i := int32(32); i < 72; i++ {
		font := loadFonts(i)
		defer font.Release()
		fonts = append(fonts, font)
	}

	// Compute window radius
	windowRadius = math.Sqrt(math.Pow(WindowHeight, 2) + math.Pow(WindowWidth, 2))

	// Use window coordinates
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, WindowWidth, WindowHeight, 0, 0, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	g = NewGame()

	g.Start()
	go eventLoop(g)
	go renderLoop(g)
	Main()
	g.Stop()
}
示例#14
0
文件: main.go 项目: pwaller/examples
func main() {
	err := initGL()
	if err != nil {
		log.Printf("InitGL: %v", err)
		return
	}

	defer glfw.Terminate()

	mb := createBuffer()
	defer mb.Release()

	// Perform the rendering.
	var angle float32
	for glfw.WindowParam(glfw.Opened) > 0 {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		gl.LoadIdentity()
		gl.Translatef(0, 0, -6)
		gl.Rotatef(angle, 1, 1, 1)

		// Render a solid cube at half the scale.
		gl.Scalef(0.2, 0.2, 0.2)
		gl.Enable(gl.COLOR_MATERIAL)
		gl.Enable(gl.POLYGON_OFFSET_FILL)
		gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)
		mb.Render(gl.QUADS)

		// Render wireframe cubes, with incremental size.
		gl.Disable(gl.COLOR_MATERIAL)
		gl.Disable(gl.POLYGON_OFFSET_FILL)
		gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE)

		for i := 0; i < 50; i++ {
			scale := 0.004*float32(i) + 1.0
			gl.Scalef(scale, scale, scale)
			mb.Render(gl.QUADS)
		}

		angle += 0.5
		glfw.SwapBuffers()
	}
}
示例#15
0
文件: main.go 项目: pwaller/examples
func onKey(key, state int) {
	switch key {
	case glfw.KeyEsc:
		running = false
	case 'L':
		if state == 1 {
			if light = !light; !light {
				gl.Disable(gl.LIGHTING)
			} else {
				gl.Enable(gl.LIGHTING)
			}
		}
	case 'F':
		if state == 1 {
			if filter++; filter >= len(textures) {
				filter = 0
			}
		}
	case 'B': // B
		if state == 1 {
			if blend = !blend; blend {
				gl.Enable(gl.BLEND)
				gl.Disable(gl.DEPTH_TEST)
			} else {
				gl.Disable(gl.BLEND)
				gl.Enable(gl.DEPTH_TEST)
			}
		}
	case glfw.KeyPageup:
		z -= 0.2
	case glfw.KeyPagedown:
		z += 0.2
	case glfw.KeyUp:
		speed[0] -= 0.1
	case glfw.KeyDown:
		speed[0] += 0.1
	case glfw.KeyLeft:
		speed[1] -= 0.1
	case glfw.KeyRight:
		speed[1] += 0.1
	}
}
示例#16
0
文件: main.go 项目: hsalokor/examples
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		log.Fatalf("%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 {
		log.Fatalf("%v\n", err)
		return
	}

	defer glfw.CloseWindow()

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

	if samples := glfw.WindowParam(glfw.FsaaSamples); samples != 0 {
		fmt.Printf("Context reports FSAA is supported with %d samples\n", samples)
	} else {
		fmt.Printf("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()
	}
}
示例#17
0
文件: render.go 项目: james4k/exp
func (w *Window) renderInit() {
	//bounds := w.body.Bounds()
	gl.Disable(gl.MULTISAMPLE)
	gl.Enable(gl.DEPTH_TEST)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)
	//gl.Viewport(0, 0, bounds.Max.X, bounds.Max.Y)
	gl.ClearDepth(1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)
}
示例#18
0
func OnKey(key, state int) {
	if state != glfw.KeyPress {
		return
	}
	if key == 'C' {
		if culling = !culling; culling {
			gl.Enable(gl.CULL_FACE)
		} else {
			gl.Disable(gl.CULL_FACE)
		}
	}
}
示例#19
0
文件: window.go 项目: phaikawl/gosui
func setupGL(w, h int) {
	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), float64(h), 0, 0, 1)

	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(1, 1, 1, 0)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Disable(gl.DEPTH_TEST)
	gl.Hint(gl.LINE_SMOOTH_HINT|gl.LINE_SMOOTH_HINT, gl.NICEST)
}
示例#20
0
func (s *Display) drawFrame(screenData *types.Screen) {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Disable(gl.DEPTH_TEST)
	gl.PointSize(float32(s.ScreenSizeMultiplier) + 1.0)
	gl.Begin(gl.POINTS)
	for y := 0; y < SCREEN_HEIGHT; y++ {
		for x := 0; x < SCREEN_WIDTH; x++ {
			var pixel types.RGB = screenData[y][x]
			gl.Color3ub(pixel.Red, pixel.Green, pixel.Blue)
			gl.Vertex2i(x*s.ScreenSizeMultiplier, y*s.ScreenSizeMultiplier)
		}
	}

	gl.End()
	glfw.SwapBuffers()
}
func (self *OpenGLRenderer) renderOne(operation render.RenderOperation, renderState RenderState) {
	mesh := operation.Mesh
	material := operation.Material
	transform := operation.Transform

	// No attributes? no loaded or empty? Better way to handle this than spamming
	// the console?
	if mesh.VertexArrayObj == nil {
		log.Println("WARNING: Trying to render an invalid mesh", mesh)
		return
	}

	vertexArrayObj := mesh.VertexArrayObj.(gl.VertexArray)
	vertexArrayObj.Bind()

	material.Shader.Program.Use()
	material.Shader.Program.SetUniformMatrix(
		"modelViewProjection",
		renderState.ViewProjection.Times(transform),
	)

	if material.Texture != nil {
		glTexture := material.Texture.Id.(gl.Texture)
		gl.ActiveTexture(gl.TEXTURE0)

		if !material.IsCubeMap {
			glTexture.Bind(gl.TEXTURE_2D)
			defer glTexture.Unbind(gl.TEXTURE_2D)
			material.Shader.Program.SetUniformUnit("textureSampler", 0)
		} else {
			gl.Disable(gl.DEPTH_TEST)
			defer gl.Enable(gl.DEPTH_TEST)

			glTexture.Bind(gl.TEXTURE_CUBE_MAP)
			defer glTexture.Unbind(gl.TEXTURE_CUBE_MAP)
			material.Shader.Program.SetUniformUnit("cubeMap", 0)
		}
	}

	if len(mesh.IndexList) == 0 {
		gl.DrawArrays(gl.TRIANGLES, 0, len(mesh.VertexList)*3)
	} else {
		gl.DrawElements(gl.TRIANGLES, len(mesh.IndexList), gl.UNSIGNED_INT, nil)
	}
}
示例#22
0
文件: main.go 项目: nzlov/examples
// initGL initializes GLFW and OpenGL.
func initGL() error {
	err := glfw.Init()
	if err != nil {
		return err
	}

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

	err = glfw.OpenWindow(512, 512, 8, 8, 8, 8, 32, 0, glfw.Windowed)
	if err != nil {
		glfw.Terminate()
		return err
	}

	glfw.SetWindowTitle("Meshbuffer 3D example")
	glfw.SetSwapInterval(1)
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetKeyCallback(onKey)

	gl.Init()
	if err = glh.CheckGLError(); err != nil {
		return err
	}

	gl.Enable(gl.DEPTH_TEST)
	gl.Enable(gl.MULTISAMPLE)
	gl.Disable(gl.LIGHTING)

	//gl.ClearColor(0.2, 0.2, 0.23, 1.0)
	gl.ClearColor(0, 0, 0, 1.0)
	gl.ShadeModel(gl.SMOOTH)
	gl.LineWidth(2)
	gl.ClearDepth(1)
	gl.DepthFunc(gl.LEQUAL)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
	gl.ColorMaterial(gl.FRONT_AND_BACK, gl.AMBIENT_AND_DIFFUSE)
	return nil
}
示例#23
0
文件: main.go 项目: nzlov/examples
func main() {
	err := initGL()
	if err != nil {
		log.Printf("InitGL: %v", err)
		return
	}

	defer glfw.Terminate()

	mb := createBuffer()
	defer mb.Release()

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

	f, err := os.Create("test.mpeg")
	if err != nil {
		log.Panicf("Unable to open output file: %q", err)
	}

	im := image.NewRGBA(image.Rect(0, 0, 512, 512))
	e, err := ffmpeg.NewEncoder(ffmpeg.CODEC_ID_H264, im, f)
	if err != nil {
		log.Panicf("Unable to start encoder: %q", err)
	}

	// Perform the rendering.
	var angle float64
	for glfw.WindowParam(glfw.Opened) > 0 {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		gl.LoadIdentity()
		gl.Translatef(0, 0, -6)
		gl.Rotated(angle/10, 0, 1, 0)
		gl.Rotated(angle, 1, 1, 1)

		// Render a solid cube at half the scale.
		gl.Scalef(0.1, 0.1, 0.1)
		gl.Enable(gl.COLOR_MATERIAL)
		gl.Enable(gl.POLYGON_OFFSET_FILL)
		gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)
		mb.Render(gl.QUADS)

		// Render wireframe cubes, with incremental size.
		gl.Disable(gl.COLOR_MATERIAL)
		gl.Disable(gl.POLYGON_OFFSET_FILL)
		gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)

		for i := 0; i < 1000; i++ {
			ifl := float64(i)
			scale := 0.000005*ifl + 1.0 + 0.01*math.Sin(angle/10+ifl/10)
			gl.Scaled(scale, scale, scale)
			gl.Rotated((ifl+angle)/1000, 1, 1, 1)
			gl.Rotated((ifl+angle)/1100, -1, 1, 1)

			mb.Render(gl.QUADS)
		}

		glh.ClearAlpha(1)
		glh.CaptureRGBA(im)

		err := e.WriteFrame()
		if err != nil {
			panic(err)
		}

		angle += 0.5
		//glh.CaptureToPng("test.png")
		glfw.SwapBuffers()
	}
	e.Close()
}
示例#24
0
文件: statshud.go 项目: pwaller/mema
func InitStatsHUD() {
	plots := chart.ScatterChart{Title: "", Options: glchart.DarkStyle}
	start := time.Now()

	l := float64(start.UnixNano())
	r := float64(start.Add(2 * time.Second).UnixNano())

	plots.XRange.Fixed(l, r, 1e9)
	plots.YRange.Fixed(0.1, 100, 10)

	plots.XRange.TicSetting.Tics, plots.YRange.TicSetting.Tics = 1, 1
	plots.XRange.TicSetting.Mirror, plots.YRange.TicSetting.Mirror = 2, 2
	plots.XRange.TicSetting.Grid, plots.YRange.TicSetting.Grid = 2, 2

	plots.YRange.ShowZero = true

	//plots.XRange.Log = true
	//plots.YRange.Log = true

	plots.Key.Pos, plots.Key.Cols = "obc", 3

	plots.XRange.TicSetting.Format = func(f float64) string {
		t := time.Unix(int64(f)/1e9, int64(f)%1e9)
		return fmt.Sprintf("%.3v", time.Since(t))
	}

	memhelper.GetMaxRSS()

	var gpufree float64

	gpupoll := gpuinfo.PollGPUMemory()
	go func() {
		for gpustatus := range gpupoll {
			gpufree = float64(memhelper.ByteSize(gpustatus.Free()) * memhelper.MiB)
		}
	}()

	statistics := &Statistics{}
	statistics.Add(&plots, "GPU Free", "#FF9F00", func() float64 { return gpufree })
	statistics.Add(&plots, "SpareRAM()", "#ff0000", func() float64 { return float64(SpareRAM() * 1e6) })
	statistics.Add(&plots, "MaxRSS", "#FFE240", func() float64 { return float64(memhelper.GetMaxRSS()) })
	statistics.Add(&plots, "Heap Idle", "#33ff33", func() float64 { return float64(memstats.HeapIdle) })
	statistics.Add(&plots, "Alloc", "#FF6600", func() float64 { return float64(memstats.Alloc) })
	statistics.Add(&plots, "Heap Alloc", "#006699", func() float64 { return float64(memstats.HeapAlloc) })
	statistics.Add(&plots, "Sys", "#996699", func() float64 { return float64(memstats.Sys) })
	statistics.Add(&plots, "System Free", "#3333ff", func() float64 { return float64(SystemFree()) })
	statistics.Add(&plots, "nBlocks x 1e6", "#FFCC00", func() float64 { return float64(nblocks * 1e6) })
	statistics.Add(&plots, "nDrawn x 1e6", "#9C8AA5", func() float64 { return float64(blocks_rendered * 1e6) })

	go func() {
		top := 0.

		i := -1
		for {
			time.Sleep(250 * time.Millisecond)
			max := statistics.Update()
			if max > top {
				top = max
			}
			i++
			if i%4 != 0 {
				continue
			}

			segment := float64(1e9)
			if time.Since(start) > 10*time.Second {
				segment = 5e9
			}
			if time.Since(start) > 1*time.Minute {
				segment = 30e9
			}

			// Update axis limits
			nr := float64(time.Now().Add(2 * time.Second).UnixNano())
			plots.XRange.Fixed(l, nr, segment)
			plots.YRange.Fixed(-1e9, top*1.1, 500e6)
		}
	}()

	const pw, ph = 640, 480

	scalex, scaley := 0.4, 0.5

	chart_gfxcontext := glchart.New(pw, ph, "", 10, color.RGBA{})

	StatsHUD = func() {
		glh.With(glh.Matrix{gl.PROJECTION}, func() {
			gl.LoadIdentity()
			gl.Translated(1-scalex, scaley-1, 0)
			gl.Scaled(scalex, scaley, 1)
			gl.Ortho(0, pw, ph, 0, -1, 1)
			gl.Translated(0, -50, 0)

			glh.With(glh.Attrib{gl.ENABLE_BIT}, func() {
				gl.Disable(gl.DEPTH_TEST)
				glh.With(&Timer{Name: "Chart"}, func() {
					plots.Plot(chart_gfxcontext)
				})
			})
		})
	}

	// TODO: figure out why this is broken
	DumpStatsHUD = func() {
		s2f, _ := os.Create("statshud-dump.svg")
		mysvg := svg.New(s2f)
		mysvg.Start(1600, 800)
		mysvg.Rect(0, 0, 2000, 800, "fill: #ffffff")
		sgr := svgg.New(mysvg, 2000, 800, "Arial", 18,
			color.RGBA{0xff, 0xff, 0xff, 0xff})
		sgr.Begin()

		plots.Plot(sgr)

		sgr.End()
		mysvg.End()
		s2f.Close()
		log.Print("Saved statshud-dump.svg")
	}

	//log.Print("InitStatsHUD()")
}
func (self *OpenGLRenderer) FinishRender() {
	gl.Disable(gl.DEPTH_TEST)
}
示例#26
0
文件: lem1802.go 项目: jteeuwen/dcpu
// Render renders the LEM1802 contents.
func (d *LEM1802Display) Render() {
	var tex [4]float32
	var addr, x, y int
	var fg, bg, blink, char byte

	mem := d.dev.Buffer()
	if len(mem) == 0 {
		return
	}

	palette := d.dev.Palette()
	border := d.dev.Border()
	clr_ut := d.quads_ut.Colors().Data().([]byte)
	clr_t := d.quads_t.Colors().Data().([]byte)
	tex_t := d.quads_t.TexCoords().Data().([]float32)

	// Set background/border color.
	r, g, b := lem1802.RGB(palette[border])
	setColor(clr_ut, r, g, b)
	clr_ut = clr_ut[12:]

	for y = 0; y < lem1802.CellsPerCol; y++ {
		for x = 0; x < lem1802.CellsPerRow; x++ {
			fg, bg, blink, char = lem1802.Decode(mem[addr])
			addr++

			// Swap foreground and background colours if this
			// character has the blink bit set, and the current
			// blink state is 1.
			if blink == 1 && atomic.LoadUint32(&d.blinkState) == 1 {
				fg = bg
			}

			// Update glyph background color.
			r, g, b := lem1802.RGB(palette[bg])
			setColor(clr_ut, r, g, b)
			clr_ut = clr_ut[12:]

			// Update glyph foreground color and tex coords.
			r, g, b = lem1802.RGB(palette[fg])
			setColor(clr_t, r, g, b)
			clr_t = clr_t[12:]

			tex = d.glyphs[char]
			tex_t[0] = tex[0]
			tex_t[1] = tex[1]
			tex_t[2] = tex[2]
			tex_t[3] = tex[1]
			tex_t[4] = tex[2]
			tex_t[5] = tex[3]
			tex_t[6] = tex[0]
			tex_t[7] = tex[3]
			tex_t = tex_t[8:]
		}
	}

	// Ensure these buffers are re-comitted to the GPU,
	// because we have just changed their contents.
	d.quads_ut.Colors().Invalidate()
	d.quads_t.Colors().Invalidate()
	d.quads_t.TexCoords().Invalidate()

	gl.PushAttrib(gl.ENABLE_BIT)
	{
		gl.Disable(gl.DEPTH_TEST)
		gl.Disable(gl.TEXTURE_2D)
		gl.Enable(gl.COLOR_MATERIAL)
		gl.Enable(gl.BLEND)
		gl.LoadIdentity()

		// Render border and glyph backgrounds.
		d.quads_ut.Render(gl.QUADS)

		// Render glyphs.
		gl.Enable(gl.TEXTURE_2D)
		d.atlas.Bind(gl.TEXTURE_2D)
		d.quads_t.Render(gl.QUADS)
		d.atlas.Unbind(gl.TEXTURE_2D)
	}
	gl.PopAttrib()
}
示例#27
0
文件: block.go 项目: pwaller/mema
func (block *Block) Draw(start, N int64, detailed bool) {
	if block.tex == nil {
		block.RequestTexture()
	}

	switch detailed {
	case true:
		block.detail_needed = true
		if block.vertex_data == nil {
			// Hey, we need vertices but don't have them! Let's fix that..
			block.RequestVertices()
		}
	default:
		block.detail_needed = false
	}

	width := uint64(len(block.display_active_pages)) * *PAGE_SIZE
	if width == 0 {
		width = 1
	}

	vc := glh.NewMeshBuffer(glh.RenderArrays,
		glh.NewPositionAttr(2, gl.FLOAT, gl.STATIC_DRAW),
		glh.NewPositionAttr(4, gl.UNSIGNED_INT, gl.STATIC_DRAW),
	)

	colors := make([]int32, 0)
	positions := make([]float32, 0)

	// var vc glh.ColorVertices

	if *pageboundaries {
		// boundary_color := color.RGBA{64, 64, 64, 255}

		// If we try and draw too many of these, X will hang
		if width / *PAGE_SIZE < 10000 {
			for p := uint64(0); p <= width; p += *PAGE_SIZE {
				x := float32(p) / float32(width)
				x = (x - 0.5) * 4

				colors = append(colors, 64, 64, 64, 255)
				positions = append(positions, x, float32(N))

				// vc.Add(glh.ColorVertex{boundary_color, glh.Vertex{x, 0}})
				// vc.Add(glh.ColorVertex{boundary_color, glh.Vertex{x, float32(N)}})
			}
		}
	}

	var border_color [4]float64

	gl.LineWidth(1)
	glh.With(&Timer{Name: "DrawPartial"}, func() {
		var x1, y1, x2, y2 float64
		glh.With(glh.Matrix{gl.MODELVIEW}, func() {
			// TODO: A little less co-ordinate insanity?
			gl.Translated(0, -2, 0)
			gl.Scaled(1, 4/float64(*nback), 1)
			gl.Translated(0, -float64(start), 0)

			x1, y1 = glh.ProjToWindow(-2, 0)
			x2, y2 = glh.ProjToWindow(-2+WIDTH, float64(N))

		})
		border_color = [4]float64{1, 1, 1, 1}

		glh.With(glh.Matrix{gl.MODELVIEW}, func() {
			gl.Translated(0, -2, 0)
			gl.Scaled(1, 4/float64(*nback), 1)
			gl.Translated(0, -float64(start), 0)

			// Page boundaries
			// TODO: Use different blending scheme on textured quads so that the
			//       lines show through
			glh.With(glh.Attrib{gl.ENABLE_BIT}, func() {
				gl.Disable(gl.LINE_SMOOTH)
				// vc.Draw(gl.LINES)
				vc.Render(gl.LINES)
			})
		})

		if block.tex != nil && (!detailed || block.vertex_data == nil) {
			border_color = [4]float64{0, 0, 1, 1}
			glh.With(glh.WindowCoords{Invert: true}, func() {
				gl.Color4f(1, 1, 1, 1)
				// Render textured block quad
				glh.With(block.tex, func() {
					glh.DrawQuadd(x1, y1, x2-x1, y2-y1)
				})
				glh.With(glh.Primitive{gl.LINES}, func() {
					glh.Squared(x1, y1, x2-x1, y2-y1)
				})
			})
			if block.vertex_data != nil && !block.detail_needed {
				// TODO: figure out when we can unload
				// Hey, we can unload you, because you are not needed
				block.vertex_data = nil
			}

		}
		if detailed && block.vertex_data != nil {
			glh.With(glh.Matrix{gl.MODELVIEW}, func() {
				// TODO: A little less co-ordinate insanity?
				gl.Translated(0, -2, 0)
				gl.Scaled(1, 4/float64(*nback), 1)
				gl.Translated(0, -float64(start), 0)

				gl.PointSize(2)
				block.vertex_data.Render(gl.POINTS)
			})
		}

		glh.With(glh.WindowCoords{Invert: true}, func() {
			// Block boundaries
			gl.Color4dv(&border_color)

			gl.LineWidth(1)
			glh.With(glh.Primitive{gl.LINE_LOOP}, func() {
				glh.Squared(x1, y1, x2-x1, y2-y1)
			})
		})
	})
}
示例#28
0
文件: font.go 项目: nobonobo/gltext
// Printf draws the given string at the specified coordinates.
// It expects the string to be a single line. Line breaks are not
// handled as line breaks and are rendered as glyphs.
//
// In order to render multi-line text, it is up to the caller to split
// the text up into individual lines of adequate length and then call
// this method for each line seperately.
func (f *Font) Printf(x, y float32, fs string, argv ...interface{}) error {
	indices := []rune(fmt.Sprintf(fs, argv...))

	if len(indices) == 0 {
		return nil
	}

	// Runes form display list indices.
	// For this purpose, they need to be offset by -FontConfig.Low
	low := f.Config.Low
	for i := range indices {
		indices[i] -= low
	}

	var vp [4]int32
	gl.GetIntegerv(gl.VIEWPORT, vp[:])

	gl.PushAttrib(gl.TRANSFORM_BIT)
	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()
	gl.Ortho(float64(vp[0]), float64(vp[2]), float64(vp[1]), float64(vp[3]), 0, 1)
	gl.PopAttrib()

	gl.PushAttrib(gl.LIST_BIT | gl.CURRENT_BIT | gl.ENABLE_BIT | gl.TRANSFORM_BIT)
	{
		gl.MatrixMode(gl.MODELVIEW)
		gl.Disable(gl.LIGHTING)
		gl.Disable(gl.DEPTH_TEST)
		gl.Enable(gl.BLEND)
		gl.Enable(gl.TEXTURE_2D)

		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
		f.Texture.Bind(gl.TEXTURE_2D)

		var mv [16]float32
		gl.GetFloatv(gl.MODELVIEW_MATRIX, mv[:])

		gl.PushMatrix()
		{
			gl.LoadIdentity()

			mgw := float32(f.maxGlyphWidth)
			mgh := float32(f.maxGlyphHeight)

			switch f.Config.Dir {
			case LeftToRight, TopToBottom:
				gl.Translatef(x, float32(vp[3])-y-mgh, 0)
			case RightToLeft:
				gl.Translatef(x-mgw, float32(vp[3])-y-mgh, 0)
			}

			gl.MultMatrixf(&mv)
			gl.CallLists(len(indices), gl.UNSIGNED_INT, indices)
		}
		gl.PopMatrix()
		f.Texture.Unbind(gl.TEXTURE_2D)
	}
	gl.PopAttrib()

	gl.PushAttrib(gl.TRANSFORM_BIT)
	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
	gl.PopAttrib()
	return glh.CheckGLError()
}
示例#29
0
文件: main.go 项目: TheOnly92/gexic
func main() {
	sys := Make()
	sys.Startup()
	defer sys.Shutdown()
	// InitQueue()

	sys.CreateWindow(1024, 768, "Gexic")
	gl.ClearColor(1, 1, 1, 0.)
	initGL()

	prevSelectPos = []int{0, 0, 0}

	// PurgeQueue()
	// genHexMap()
	hexMap2 = GenHexMap()
	// for matches := checkHexMap(); len(matches) > 0; matches = checkHexMap() {
	// 	removeHexAndGenNew(matches)
	// }
	glfw.SetMouseButtonCallback(MouseButtonCallback)
	glfw.SetCharCallback(charCallback)
	glfw.SetMousePosCallback(MousePosCallback)
	currExX = -1
	currExY = -1

	for sys.CheckExitMainLoop() {
		start := glfw.Time()
		wait := float64(1) / float64(30)
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		gl.Enable(gl.TEXTURE_2D)
		gl.Enable(gl.BLEND)
		gl.Disable(gl.DEPTH_TEST)
		// renderHexMap()
		wallpaper.Bind(gl.TEXTURE_2D)
		gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.REPLACE)
		gl.Begin(gl.QUADS)
		gl.TexCoord2f(0, 0)
		gl.Vertex2i(0, 0)
		gl.TexCoord2f(0, 1)
		gl.Vertex2i(0, 768)
		gl.TexCoord2f(1, 1)
		gl.Vertex2i(1024, 768)
		gl.TexCoord2f(1, 0)
		gl.Vertex2i(1024, 0)
		gl.End()
		hexMap2.Render()
		hexRotate.AnimateAndExecute()
		hexShrink.AnimateAndExecute()
		hexFall.AnimateAndExecute()
		if !mouse.locked {
			x, y := mouse.GetXY()
			hexMap2.CalcClosestCenter(x, y)
		}
		gl.Flush()
		gl.Disable(gl.TEXTURE_2D)
		gl.Disable(gl.BLEND)
		sys.Refresh()
		diff := glfw.Time() - start
		if diff < wait {
			glfw.Sleep(wait - diff)
		}
	}
}
示例#30
0
文件: main.go 项目: TheOnly92/gexic
func renderHexMap() {
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.Disable(gl.DEPTH_TEST)
	wallpaper.Bind(gl.TEXTURE_2D)
	gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.REPLACE)
	gl.Begin(gl.QUADS)
	gl.TexCoord2f(0, 0)
	gl.Vertex2i(0, 0)
	gl.TexCoord2f(0, 1)
	gl.Vertex2i(0, 768)
	gl.TexCoord2f(1, 1)
	gl.Vertex2i(1024, 768)
	gl.TexCoord2f(1, 0)
	gl.Vertex2i(1024, 0)
	gl.End()
	gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.DECAL)
	gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.PushMatrix()
	gl.Translatef(80, 80, 0)
	for x := 0; x < 10; x++ {
		maxy := 8
		topy := 19
		if x%2 == 1 {
			maxy = 9
			topy = 0
		}
		starty := 0
		for y := starty; y < maxy; y++ {
			if currExX > -1 && currExY > -1 && starRotate {
				if y == currExY && x == currExX || y == currExY+1 && x == currExX || y == currExY-1 && x == currExX || currExX%2 == 0 && ((currExX == x-1 || currExX == x+1) && currExY == y-1 || (currExX == x-1 || currExX == x+1) && currExY == y) || currExX%2 == 1 && ((currExX == x-1 || currExX == x+1) && currExY == y || (currExX == x-1 || currExX == x+1) && currExY == y+1) {
					continue
				}
			} else if timesToRotate > 0 {
				// if y == currExY && x == currExX || currExX%2 == 0 && (x == currExX+1 && y == currExY || x == currExX+1 && y == currExY+1) || currExX%2 == 1 && (x == currExX+1 && y == currExY || x == currExX+1 && y == currExY-1) {
				// 	continue
				// }
				found := false
				for _, v := range selectedHex {
					if y == v[1] && x == v[0] {
						found = true
						break
					}
				}
				if found {
					continue
				}
			}
			found := false
			for _, v := range currentMatches {
				if scale > 0 && v[0] == x && v[1] == y || scale <= 0 && v[0] == x && v[1] >= y {
					found = true
					break
				}
			}
			for _, v := range starMatches {
				if starAlpha > 0 && v[0] == x && v[1] == y || starAlpha <= 0 && v[0] == x && v[1] >= y {
					found = true
					break
				}
			}
			if found || len(currStarCenter) > 0 && currStarCenter[0] == x && currStarCenter[1] == y {
				continue
			}
			gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			drawHex(x*33, topy+y*38, hexMap[x][y], 1)
		}
	}
	gl.PopMatrix()
	if len(currentMatches) > 0 || len(starMatches) > 0 {
		mouseLock = true
		if len(currentMatches) > 0 && scale > 0 {
			scale -= 0.1
			for _, v := range currentMatches {
				gl.PushMatrix()
				topy := 19
				if v[0]%2 == 1 {
					topy = 0
				}
				gl.Translatef(float32(v[0]*33+102), float32(v[1]*38+topy+94), 0)
				gl.Scalef(scale, scale, 1)
				gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
				drawHex(-22, -14, hexMap[v[0]][v[1]], 1)
				gl.PopMatrix()
			}
		} else if len(starMatches) > 0 && starAlpha > 0 {
			starAlpha -= 0.05
			// starAlpha = 0.7
			starScale += 0.05
			// starScale = 1.4
			gl.PushMatrix()
			topy := 19
			pm := 0
			if currStarCenter[0]%2 == 1 {
				topy = 0
				pm = -1
			}
			gl.Translatef(float32(currStarCenter[0]*33+102), float32(currStarCenter[1]*38+topy+94), 0)
			drawHex(-22, -14, 6, 1)
			gl.PopMatrix()
			gl.PushMatrix()
			gl.Translatef(float32(currStarCenter[0]*33+102), float32(currStarCenter[1]*38+topy+94), 0)
			gl.Scalef(starScale, starScale, 1)
			drawHex(-22, -14-HEX_HEIGHT, hexMap[currStarCenter[0]][currStarCenter[1]-1], starAlpha)
			drawHex(-22, -20+HEX_HEIGHT, hexMap[currStarCenter[0]][currStarCenter[1]+1], starAlpha)
			drawHex(-52, -36, hexMap[currStarCenter[0]-1][currStarCenter[1]+pm], starAlpha)
			drawHex(-52, -40+HEX_HEIGHT, hexMap[currStarCenter[0]-1][currStarCenter[1]+pm+1], starAlpha)
			drawHex(8, -36, hexMap[currStarCenter[0]+1][currStarCenter[1]+pm], starAlpha)
			drawHex(8, -40+HEX_HEIGHT, hexMap[currStarCenter[0]+1][currStarCenter[1]+pm+1], starAlpha)
			gl.PopMatrix()
		} else {
			if fallticks == 0 {
				animateFall = make([]*freefall, 0)
				for x := 0; x < 10; x++ {
					topy := 19
					if x%2 == 1 {
						topy = 0
					}
					fromy := -1
					for _, v := range currentMatches {
						if v[0] != x {
							continue
						}
						if v[1] > fromy {
							fromy = v[1]
						}
					}
					for _, v := range starMatches {
						if v[0] != x {
							continue
						}
						if v[1] > fromy {
							fromy = v[1]
						}
					}
					if fromy == -1 {
						continue
					}
					for y := fromy; y >= 0; y-- {
						found := false
						for _, v := range currentMatches {
							if v[0] == x && v[1] == y {
								found = true
								break
							}
						}
						for _, v := range starMatches {
							if v[0] == x && v[1] == y {
								found = true
								break
							}
						}
						if found {
							continue
						}
						animateFall = append(animateFall, &freefall{x, y, getFallTargetY(x, y), math.Pow(float64(y), 2)/16 + 0.5})
						gl.PushMatrix()
						gl.Translatef(float32(x*33+102), float32(y*38+topy+94), 0)
						gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
						drawHex(-22, -14, hexMap[x][y], 1)
						gl.PopMatrix()
					}
				}
				fallticks++
			} else {
				stillFalling := 0
				for _, v := range animateFall {
					topy := 19
					if v.x%2 == 1 {
						topy = 0
					}
					newy := v.accel * math.Pow(float64(fallticks), 2) / 2
					gl.PushMatrix()
					gl.Translatef(float32(v.x*33+102), float32(math.Min(float64(v.y*38+topy+94)+newy, float64(v.targetY*38+topy+94))), 0)
					gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
					drawHex(-22, -14, hexMap[v.x][v.y], 1)
					gl.PopMatrix()
					if float64(v.y*38+topy+94)+newy < float64(v.targetY*38+topy+94) {
						stillFalling++
					}
				}
				fallticks++
				if stillFalling == 0 {
					starScale = 1
					starAlpha = 0
					removeHexAndGenNew(currentMatches)
					makeStarAndGenNew(starMatches)
					currentMatches = checkHexMap()
					starMatches = checkHexStar()
					currStarCenter = []int{}
					scale = 1
					fallticks = 0
					mouseLock = false
					fmt.Println("Mouse unlocked 1")
					animateFall = nil
				}
			}
		}
	}
	if currExX > -1 && currExY > -1 {
		gl.PushMatrix()
		topy := 19
		if currExX%2 == 1 {
			topy = 0
		}
		if starRotate {
			timesToRotate = 0
			gl.Translatef(float32(currExX*33+102), float32(currExY*38+topy+94), 0)
			gl.Scalef(1.3, 1.3, 1)
			gl.Rotatef(rotate, 0, 0, 1)
			drawHex(-22, -14, 6, 1)
			drawHex(-22, -14-HEX_HEIGHT, hexMap[currExX][currExY-1], 1)
			drawHex(-22, -20+HEX_HEIGHT, hexMap[currExX][currExY+1], 1)
			pm := 0
			if currExX%2 == 1 {
				pm = -1
			}
			drawHex(-52, -36, hexMap[currExX-1][currExY+pm], 1)
			drawHex(-52, -40+HEX_HEIGHT, hexMap[currExX-1][currExY+pm+1], 1)
			drawHex(8, -36, hexMap[currExX+1][currExY+pm], 1)
			drawHex(8, -40+HEX_HEIGHT, hexMap[currExX+1][currExY+pm+1], 1)
		} else {
			// gl.Translatef(float32(currExX*33+HEX_WIDTH+80), float32(currExxY*38+topy+20+80), 0)
			gl.Translatef(float32(prevSelectPos[0]), float32(prevSelectPos[1]), 0)
			gl.Scalef(1.3, 1.3, 1)
			gl.Rotatef(rotate, 0, 0, 1)
			for _, v := range selectedHex {
				switch v[2] {
				case 1:
					drawHex(-32, -34, hexMap[v[0]][v[1]], 1)
				case 2:
					drawHex(0, -17, hexMap[v[0]][v[1]], 1)
				case 3:
					drawHex(-32, 0, hexMap[v[0]][v[1]], 1)
				case 4:
					drawHex(-44, -19, hexMap[v[0]][v[1]], 1)
				case 5:
					drawHex(-12, -36, hexMap[v[0]][v[1]], 1)
				case 6:
					drawHex(-12, -2, hexMap[v[0]][v[1]], 1)
				}
			}
			// if currExX%2 == 0 {
			// 	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			// 	drawHex(-12, -36, hexMap[currExX+1][currExY], 1)
			// } else {
			// 	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			// 	drawHex(-12, -36, hexMap[currExX+1][currExY-1], 1)
			// }
			// gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			// drawHex(-44, -19, hexMap[currExX][currExY], 1)
			// if currExX%2 == 0 {
			// 	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			// 	drawHex(-12, -2, hexMap[currExX+1][currExY+1], 1)
			// } else {
			// 	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
			// 	drawHex(-12, -2, hexMap[currExX+1][currExY], 1)
			// }
		}
		gl.PopMatrix()
		if !starRotate && rotate < 120 {
			rotate += 15
			// rotate = 15
		} else if starRotate && rotate < 60 {
			rotate += 6
		} else {
			if starRotate {
				if currExX%2 == 0 {
					hexMap[currExX][currExY-1], hexMap[currExX+1][currExY], hexMap[currExX+1][currExY+1], hexMap[currExX][currExY+1], hexMap[currExX-1][currExY+1], hexMap[currExX-1][currExY] = hexMap[currExX-1][currExY], hexMap[currExX][currExY-1], hexMap[currExX+1][currExY], hexMap[currExX+1][currExY+1], hexMap[currExX][currExY+1], hexMap[currExX-1][currExY+1]
				} else {
					hexMap[currExX][currExY-1], hexMap[currExX+1][currExY-1], hexMap[currExX+1][currExY], hexMap[currExX][currExY+1], hexMap[currExX-1][currExY], hexMap[currExX-1][currExY-1] = hexMap[currExX-1][currExY-1], hexMap[currExX][currExY-1], hexMap[currExX+1][currExY-1], hexMap[currExX+1][currExY], hexMap[currExX][currExY+1], hexMap[currExX-1][currExY]
				}
			} else {
				v2 := make([][]int, 3)
				for _, v := range selectedHex {
					idx := 0
					switch v[2] {
					case 1, 4:
						idx = 0
					case 2, 5:
						idx = 1
					case 3, 6:
						idx = 2
					}
					v2[idx] = []int{v[0], v[1]}
					fmt.Println(idx, v[0], v[1])
				}
				hexMap[v2[0][0]][v2[0][1]], hexMap[v2[1][0]][v2[1][1]], hexMap[v2[2][0]][v2[2][1]] = hexMap[v2[2][0]][v2[2][1]], hexMap[v2[0][0]][v2[0][1]], hexMap[v2[1][0]][v2[1][1]]
			}
			starMatches = checkHexStar()
			if len(starMatches) > 6 {
				fmt.Println(starMatches)
			}
			if len(starMatches) >= 6 {
				timesToRotate = 0
				rotate = 0
				currExX = -1
				currExY = -1
				starScale = 1
				starAlpha = 1
				starRotate = false
				currStarCenter = getStarCenter(starMatches)
				hexMap[currStarCenter[0]][currStarCenter[1]] = 6
				// makeStarAndGenNew(starMatches)
			} else {
				matches := checkHexMap()
				if len(matches) > 0 {
					currentMatches = matches
					scale = 1
					currExX = -1
					currExY = -1
					rotate = 0
					timesToRotate = 0
					starRotate = false
				} else {
					if timesToRotate == 0 {
						currExX = -1
						currExY = -1
						rotate = 0
						timesToRotate = 0
						starRotate = false
						mouseLock = false
						fmt.Println("Mouse unlocked 3")
					}
					rotate = 0
					timesToRotate--
				}
			}
		}
	}
	if !mouseLock {
		prevSelectPos = calcClosestCenter(posX, posY)
		drawBorderAtXY(float32(prevSelectPos[0]), float32(prevSelectPos[1]), prevSelectPos[2])
	}
	gl.Flush()
	gl.Disable(gl.TEXTURE_2D)
	gl.Disable(gl.BLEND)
}