Exemple #1
0
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)
}
Exemple #2
0
func (sg *OpenGLGraphics) Line(x0, y0, x1, y1 int, style chart.Style) {
	//log.Panicf("Unimplemented: %s", whoami())
	defer glh.OpenGLSentinel()()

	gl.LineWidth(float32(style.LineWidth))

	// TODO: line stipple?
	//sc := chart.Color2RGBA(style.LineColor, uint8(style.Alpha*255))
	//log.Printf("color: %s %d %d %d %d", style.FillColor, sc.R, sc.G, sc.B, sc.A)

	glh.ColorC(style.LineColor)
	//sc := style.LineColor
	//gl.Color4ub(sc.R, sc.G, sc.B, sc.A)
	// TODO: Check this works

	glh.With(glh.Attrib{gl.ENABLE_BIT | gl.COLOR_BUFFER_BIT}, func() {
		gl.Enable(gl.BLEND)
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

		glh.With(glh.Primitive{gl.LINES}, func() {
			gl.Vertex2i(x0, y0)
			gl.Vertex2i(x1, y1)
		})
	})
}
Exemple #3
0
func display() {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Begin(gl.TRIANGLES)
	gl.Color3f(0.0, 0.0, 1.0) /* blue */
	gl.Vertex2i(0, 0)
	gl.Color3f(0.0, 1.0, 0.0) /* green */
	gl.Vertex2i(200, 200)
	gl.Color3f(1.0, 0.0, 0.0) /* red */
	gl.Vertex2i(20, 200)
	gl.End()
	gl.Flush() /* Single buffered, so needs a flush. */
}
Exemple #4
0
func paintSprite(minx int, miny int, maxx int, maxy int, t *system.Texture, index int) {
	gl.MatrixMode(gl.TEXTURE)
	gl.Begin(gl.QUADS)
	gl.TexCoord2d(t.MinX(index), t.MinY(index))
	gl.Vertex2i(minx, miny)
	gl.TexCoord2d(t.MaxX(index), t.MinY(index))
	gl.Vertex2i(maxx, miny)
	gl.TexCoord2d(t.MaxX(index), t.MaxY(index))
	gl.Vertex2i(maxx, maxy)
	gl.TexCoord2d(t.MinX(index), t.MaxY(index))
	gl.Vertex2i(minx, maxy)
	gl.End()
	gl.MatrixMode(gl.MODELVIEW)
}
Exemple #5
0
// Emit Vertices of a square with texture co-ordinates which wind anti-clockwise
func Squarei(x, y, w, h int) {
	u, v, u2, v2 := 0, 1, 1, 0

	gl.TexCoord2i(u, v)
	gl.Vertex2i(x, y)

	gl.TexCoord2i(u2, v)
	gl.Vertex2i(x+w, y)

	gl.TexCoord2i(u2, v2)
	gl.Vertex2i(x+w, y+h)

	gl.TexCoord2i(u, v2)
	gl.Vertex2i(x, y+h)
}
Exemple #6
0
func drawQuad(x, y, w, h int, u, v, u2, v2 float32) {
	gl.Begin(gl.QUADS)

	gl.TexCoord2f(float32(u), float32(v))
	gl.Vertex2i(int(x), int(y))

	gl.TexCoord2f(float32(u2), float32(v))
	gl.Vertex2i(int(x+w), int(y))

	gl.TexCoord2f(float32(u2), float32(v2))
	gl.Vertex2i(int(x+w), int(y+h))

	gl.TexCoord2f(float32(u), float32(v2))
	gl.Vertex2i(int(x), int(y+h))

	gl.End()
}
Exemple #7
0
func drawHex(x, y, kind int, alpha float32) {
	if kind == 6 {
		gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.REPLACE)
		starTex.Bind(gl.TEXTURE_2D)
		gl.Begin(gl.QUADS)
		gl.TexCoord2f(0, 0)
		gl.Vertex2i(x, y)
		gl.TexCoord2f(0, 1)
		gl.Vertex2i(x, y+HEX_HEIGHT)
		gl.TexCoord2f(1, 1)
		gl.Vertex2i(x+HEX_WIDTH, y+HEX_HEIGHT)
		gl.TexCoord2f(1, 0)
		gl.Vertex2i(x+HEX_WIDTH, y)
		gl.End()
	} else {
		gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		var r, g, b float32
		switch kind {
		case 0:
			r = 1
		case 1:
			g = 1
		case 2:
			b = 1
		case 3:
			r = 1
			g = 1
		case 4:
			r = 1
			b = 1
		case 5:
			g = 1 - 222/255
			b = 1
		}
		hexTex.Bind(gl.TEXTURE_2D)
		gl.Begin(gl.QUADS)
		if alpha < 1 {
			gl.Color4f(r, g, b, alpha)
		} else {
			gl.Color3f(r, g, b)
		}
		gl.TexCoord2f(0, 0)
		gl.Vertex2i(x, y)
		gl.TexCoord2f(0, 1)
		gl.Vertex2i(x, y+HEX_HEIGHT)
		gl.TexCoord2f(1, 1)
		gl.Vertex2i(x+HEX_WIDTH, y+HEX_HEIGHT)
		gl.TexCoord2f(1, 0)
		gl.Vertex2i(x+HEX_WIDTH, y)
		gl.End()
	}
}
Exemple #8
0
func TexturedQuad(t *glh.Texture, x, y, w, h int) {
	glh.With(t, func() {
		gl.Enable(gl.BLEND)
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.Color4f(255.0, 255.0, 255.0, 1.0)
		gl.Begin(gl.TRIANGLE_FAN)

		gl.TexCoord2f(0, 0)
		gl.Vertex2i(x, y)
		gl.TexCoord2f(1, 0)
		gl.Vertex2i(x+w, y)
		gl.TexCoord2f(1, 1)
		gl.Vertex2i(x+w, y+h)
		gl.TexCoord2f(0, 1)
		gl.Vertex2i(x, y+h)

		gl.End()
	})
}
Exemple #9
0
func (rw *RenderWindow) draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Enable(gl.LINE_SMOOTH)
	for chanIdx, channel := range rw.Channels {
		color := channel.GetColor()
		gl.Color4f(color[0], color[1], color[2], color[3])
		gl.Begin(gl.LINES)
		lastY := int64(0)
		for i := 0; i < len(rw.renderBuffers[chanIdx]); i += 1 {
			y := rw.Height - (rw.renderBuffers[chanIdx][i] * rw.Height / 1024)
			gl.Vertex2i(i-1, int(lastY))
			gl.Vertex2i(i, int(y))
			lastY = y
		}
		gl.Flush()
		gl.End()
	}
	glfw.SwapBuffers()
}
func drawFrame(screenData *Screen) {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Begin(gl.POINTS)

	for i := 0; i < SCREEN_WIDTH; i++ {
		for j := 0; j < SCREEN_HEIGHT; j++ {
			var pixel Color = screenData[i][j]
			gl.Color3d(pixel.Red, pixel.Green, pixel.Blue)
			gl.Vertex2i(i, j)
		}
	}
	gl.End()
}
Exemple #11
0
func drawBorderAtXY(x, y float32, reverse int) {
	if x <= 80 || y <= 80 {
		return
	}
	gl.PushMatrix()
	gl.Translatef(x, y, 0)
	if reverse == 1 {
		gl.Rotatef(60, 0, 0, 1)
	}
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.REPLACE)
	borderTex.Bind(gl.TEXTURE_2D)
	gl.Begin(gl.QUADS)
	gl.TexCoord2f(0, 0)
	gl.Vertex2i(-38, -38)
	gl.TexCoord2f(0, 1)
	gl.Vertex2i(-38, 38)
	gl.TexCoord2f(1, 1)
	gl.Vertex2i(38, 38)
	gl.TexCoord2f(1, 0)
	gl.Vertex2i(38, -38)
	gl.End()
	gl.PopMatrix()
}
Exemple #12
0
func (h *Hex) Render(alpha float32, drawFromCenter bool) {
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	if h.Kind == HexFlower {
		gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.REPLACE)
		starTex.Bind(gl.TEXTURE_2D)
	} else {
		gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
		hexTex.Bind(gl.TEXTURE_2D)
		gl.GetError()
		var r, g, b uint8
		r = uint8(colors.Colors[h.Kind-1][0])
		g = uint8(colors.Colors[h.Kind-1][1])
		b = uint8(colors.Colors[h.Kind-1][2])
		if alpha < 1 {
			gl.Color4ub(r, g, b, uint8(alpha*255))
		} else {
			gl.Color3ub(r, g, b)
		}
	}
	gl.Begin(gl.QUADS)
	gl.TexCoord2f(0, 0)
	if drawFromCenter {
		gl.Vertex2i(HEX_WIDTH/2, HEX_HEIGHT/2)
	} else {
		gl.Vertex2i(HEX_WIDTH, HEX_HEIGHT)
	}
	gl.TexCoord2f(0, 1)
	if drawFromCenter {
		gl.Vertex2i(HEX_WIDTH/2, -HEX_HEIGHT/2)
	} else {
		gl.Vertex2i(HEX_WIDTH, 0)
	}
	gl.TexCoord2f(1, 1)
	if drawFromCenter {
		gl.Vertex2i(-HEX_WIDTH/2, -HEX_HEIGHT/2)
	} else {
		gl.Vertex2i(0, 0)
	}
	gl.TexCoord2f(1, 0)
	if drawFromCenter {
		gl.Vertex2i(-HEX_WIDTH/2, HEX_HEIGHT/2)
	} else {
		gl.Vertex2i(0, HEX_HEIGHT)
	}
	gl.End()
}
Exemple #13
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()
}
Exemple #14
0
func drawSelection(p1, p2 Point) {
	min, max := minMaxPoints(p1, p2)

	gl.Color3ub(255, 0, 0)
	gl.Begin(gl.LINES)
	gl.Vertex2i(int(min.X), int(min.Y))
	gl.Vertex2i(int(max.X), int(min.Y))

	gl.Vertex2i(int(min.X), int(min.Y))
	gl.Vertex2i(int(min.X), int(max.Y))

	gl.Vertex2i(int(max.X), int(max.Y))
	gl.Vertex2i(int(max.X), int(min.Y))

	gl.Vertex2i(int(max.X), int(max.Y))
	gl.Vertex2i(int(min.X), int(max.Y))
	gl.End()
	gl.Color3ub(255, 255, 255)
}
Exemple #15
0
// Draw a test pattern
func TestWindowCoordsA(t *testing.T) {
	gltest.OnTheMainThread(func() {
		gltest.SetWindowSize(40, 5)

		w, h := GetViewportWH()
		With(WindowCoords{}, func() {
			// So that we draw in the middle of the pixel
			gl.Translated(0.5, 0.5, 0)

			gl.Color4f(1, 1, 1, 1)
			With(Primitive{gl.POINTS}, func() {
				for i := 0; i < w+1; i += 2 {
					gl.Vertex2i(i, h/2)
				}
			})
		})
	}, func() {
		CaptureToPng("TestWindowCoordsA.png")
	})
}
Exemple #16
0
// vertex draws vertices.
// Used in classic render mode.
func (a *Attr) vertex(i int) {
	i *= a.size

	switch a.size {
	case 2:
		switch v := a.data.(type) {
		case []int16:
			gl.Vertex2s(v[i], v[i+1])
		case []int32:
			gl.Vertex2i(int(v[i]), int(v[i+1]))
		case []float32:
			gl.Vertex2f(v[i], v[i+1])
		case []float64:
			gl.Vertex2d(v[i], v[i+1])
		}
	case 3:
		switch v := a.data.(type) {
		case []int16:
			gl.Vertex3s(v[i], v[i+1], v[i+2])
		case []int32:
			gl.Vertex3i(int(v[i]), int(v[i+1]), int(v[i+2]))
		case []float32:
			gl.Vertex3f(v[i], v[i+1], v[i+2])
		case []float64:
			gl.Vertex3d(v[i], v[i+1], v[i+2])
		}
	case 4:
		switch v := a.data.(type) {
		case []int16:
			gl.Vertex4s(v[i], v[i+1], v[i+2], v[i+3])
		case []int32:
			gl.Vertex4i(int(v[i]), int(v[i+1]), int(v[i+2]), int(v[i+3]))
		case []float32:
			gl.Vertex4f(v[i], v[i+1], v[i+2], v[i+3])
		case []float64:
			gl.Vertex4d(v[i], v[i+1], v[i+2], v[i+3])
		}
	}
}
Exemple #17
0
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)
}
Exemple #18
0
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)
		}
	}
}
Exemple #19
0
// Draw a test pattern
func TestWindowCoords(t *testing.T) {
	gltest.OnTheMainThread(func() {
		gltest.SetWindowSize(40, 40)

		w, h := GetViewportWH()
		With(WindowCoords{}, func() {
			// So that we draw in the middle of the pixel
			gl.Translated(0.5, 0.5, 0)

			// Draw stripes
			stride := 1
			internal_n := 4
			for b := 0; b < w/2-internal_n*stride; b += stride {
				if b/stride%2 == 0 {
					gl.Color4f(1, 1, 1, 1)
				} else {
					gl.Color4f(1, 0, 0, 1)
				}
				With(Primitive{gl.LINE_LOOP}, func() {
					gl.Vertex2i(b, b)
					gl.Vertex2i(w-b, b)
					gl.Vertex2i(w-b, h-b)
					gl.Vertex2i(b, h-b)
				})
			}

			// Central white, green, blue checked pattern
			gl.PointSize(2)
			With(Primitive{gl.POINTS}, func() {
				gl.Color4f(1, 1, 1, 1)
				gl.Vertex2i(w/2-2, h/2-2)
				gl.Vertex2i(w/2+2, h/2+2)

				gl.Color4f(0, 1, 0, 1)
				gl.Vertex2i(w/2+2, h/2-2)
				gl.Vertex2i(w/2-2, h/2+2)

				gl.Color4f(1, 1, 1, 1)
				gl.Vertex2i(w/2, h/2)
			})

			// Blue horizontal line to show
			With(Primitive{gl.LINE_LOOP}, func() {
				gl.Color4f(0, 0, 1, 1)
				gl.Vertex2i(0, h/2-4)
				gl.Vertex2i(w, h/2-4)

				gl.Vertex2i(w/2-4, 0)
				gl.Vertex2i(w/2-4, h)
			})

			// Remove some pixels near the boundaries
			gl.PointSize(1)
			gl.Color4f(0, 0, 0, 1)
			With(Primitive{gl.POINTS}, func() {
				// Black dot in top left
				gl.Vertex2i(0, 0)
				// Off the top right (should not be visible)
				gl.Vertex2i(w, 0)
				// Bottom left pixel (should be visible as a black dot)
				gl.Vertex2i(0, h-1)
			})
		})
	}, func() {
		CaptureToPng("TestWindowCoords.png")
	})
}