コード例 #1
0
ファイル: main.go プロジェクト: jayschwa/examples
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()
}
コード例 #2
0
ファイル: 04.go プロジェクト: nzlov/gogl
func draw() {                  // 从这里开始进行所有的绘制

	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) // 清除屏幕和深度缓存
	gl.LoadIdentity()                                   // 重置当前的模型观察矩阵
	gl.Translatef(-1.5, 0.0, -6.0)                      // 左移 1.5 单位,并移入屏幕 6.0

	gl.Rotatef(rtri, 0.0, 1.0, 0.0) // 绕Y轴旋转三角形
	gl.Begin(gl.TRIANGLES)          // 绘制三角形
	gl.Color3f(1.0, 0.0, 0.0)       // 设置当前色为红色
	gl.Vertex3f(0.0, 1.0, 0.0)      // 上顶点
	gl.Color3f(0.0, 1.0, 0.0)       // 设置当前色为绿色
	gl.Vertex3f(-1.0, -1.0, 0.0)    // 左下
	gl.Color3f(0.0, 0.0, 1.0)       // 设置当前色为蓝色
	gl.Vertex3f(1.0, -1.0, 0.0)     // 右下
	gl.End()                        // 三角形绘制结束

	gl.LoadIdentity()                // 重置当前的模型观察矩阵
	gl.Translatef(1.5, 0.0, -6.0)    // 右移1.5单位,并移入屏幕 6.0
	gl.Rotatef(rquad, 1.0, 0.0, 0.0) //  绕X轴旋转四边形
	gl.Color3f(0.5, 0.5, 1.0)        // 一次性将当前色设置为蓝色
	gl.Begin(gl.QUADS)               //  绘制正方形
	gl.Vertex3f(-1.0, 1.0, 0.0)      // 左上
	gl.Vertex3f(1.0, 1.0, 0.0)       // 右上
	gl.Vertex3f(1.0, -1.0, 0.0)      // 左下
	gl.Vertex3f(-1.0, -1.0, 0.0)     // 右下
	gl.End()

	rtri += 0.2 // 增加三角形的旋转变量

	rquad -= 0.15 // 减少四边形的旋转变量
}
コード例 #3
0
ファイル: main.go プロジェクト: pwaller/debris
// Render a sphere with the correct orientation (poles along y-axis)
// Also makes a correction to avoid lighting flicker.
// TODO: Replace with geodesic
func Sphere(radius float32, granularity int) {
	glh.With(glh.Matrix{gl.MODELVIEW}, func() {
		// Needed to avoid a strange lighting effect
		gl.Rotatef(90, 0, 1, 0)

		// Rotate so that poles are on the y-axis
		gl.Rotatef(90, 1, 0, 0)
		glu.Sphere(quadric, radius, granularity, granularity)
	})
}
コード例 #4
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()
	}
}
コード例 #5
0
ファイル: 10.go プロジェクト: nzlov/gogl
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.LoadIdentity() // 重置当前矩阵

	texture.Bind(gl.TEXTURE_2D)

	var x_m, y_m, z_m, u_m, v_m float32
	xtrans := -xpos
	ztrans := -zpos
	ytrans := -walkbias - 0.25
	sceneroty := 360.0 - yrot

	var numtriangles int

	gl.Rotatef(lookupdown, 1.0, 0, 0)
	gl.Rotatef(sceneroty, 0, 1.0, 0)

	gl.Translatef(xtrans, ytrans, ztrans)

	numtriangles = sector1.numtriangles

	// Process Each Triangle
	for loop_m := 0; loop_m < numtriangles; loop_m++ {
		gl.Begin(gl.TRIANGLES)
		gl.Normal3f(0.0, 0.0, 1.0)
		x_m = sector1.triangles[loop_m].vertex[0].x
		y_m = sector1.triangles[loop_m].vertex[0].y
		z_m = sector1.triangles[loop_m].vertex[0].z
		u_m = sector1.triangles[loop_m].vertex[0].u
		v_m = sector1.triangles[loop_m].vertex[0].v
		gl.TexCoord2f(u_m, v_m)
		gl.Vertex3f(x_m, y_m, z_m)

		x_m = sector1.triangles[loop_m].vertex[1].x
		y_m = sector1.triangles[loop_m].vertex[1].y
		z_m = sector1.triangles[loop_m].vertex[1].z
		u_m = sector1.triangles[loop_m].vertex[1].u
		v_m = sector1.triangles[loop_m].vertex[1].v
		gl.TexCoord2f(u_m, v_m)
		gl.Vertex3f(x_m, y_m, z_m)

		x_m = sector1.triangles[loop_m].vertex[2].x
		y_m = sector1.triangles[loop_m].vertex[2].y
		z_m = sector1.triangles[loop_m].vertex[2].z
		u_m = sector1.triangles[loop_m].vertex[2].u
		v_m = sector1.triangles[loop_m].vertex[2].v
		gl.TexCoord2f(u_m, v_m)
		gl.Vertex3f(x_m, y_m, z_m)
		gl.End()
	}
}
コード例 #6
0
ファイル: bouncing_balls.go プロジェクト: niksaak/chipmunk
// OpenGL draw function
func draw() {
	gl.Clear(gl.COLOR_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.LoadIdentity()

	gl.Begin(gl.LINES)
	gl.Color3f(.2, .2, .2)
	for i := range staticLines {
		x := staticLines[i].GetAsSegment().A.X
		y := staticLines[i].GetAsSegment().A.Y
		gl.Vertex3f(float32(x), float32(y), 0)
		x = staticLines[i].GetAsSegment().B.X
		y = staticLines[i].GetAsSegment().B.Y
		gl.Vertex3f(float32(x), float32(y), 0)
	}
	gl.End()

	gl.Color4f(.3, .3, 1, .8)
	// draw balls
	for _, ball := range balls {
		gl.PushMatrix()
		pos := ball.Body.Position()
		rot := ball.Body.Angle() * chipmunk.DegreeConst
		gl.Translatef(float32(pos.X), float32(pos.Y), 0.0)
		gl.Rotatef(float32(rot), 0, 0, 1)
		drawCircle(float64(ballRadius), 60)
		gl.PopMatrix()
	}
}
コード例 #7
0
ファイル: fontdemo.go プロジェクト: himanshushekhar/glut
func display() {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	bitmap_output(40, 35, "This is written in a GLUT bitmap font.", glut.BITMAP_TIMES_ROMAN_24)
	bitmap_output(30, 210, "More bitmap text is a fixed 9 by 15 font.", glut.BITMAP_9_BY_15)
	bitmap_output(70, 240, "                Helvetica is yet another bitmap font.", glut.BITMAP_HELVETICA_18)

	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()
	glu.Perspective(40.0, 1.0, 0.1, 20.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	glu.LookAt(0.0, 0.0, 4.0, /* eye is at (0,0,30) */
		0.0, 0.0, 0.0, /* center is at (0,0,0) */
		0.0, 1.0, 0.0) /* up is in postivie Y direction */
	gl.PushMatrix()
	gl.Translatef(0, 0, -4)
	gl.Rotatef(50, 0, 1, 0)
	stroke_output(-2.5, 1.1, "  This is written in a", glut.STROKE_ROMAN)
	stroke_output(-2.5, 0, " GLUT stroke font.", glut.STROKE_ROMAN)
	stroke_output(-2.5, -1.1, "using 3D perspective.", glut.STROKE_ROMAN)
	gl.PopMatrix()
	gl.MatrixMode(gl.MODELVIEW)
	gl.PopMatrix()
	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
	gl.MatrixMode(gl.MODELVIEW)
	gl.Flush()
}
コード例 #8
0
ファイル: 09.go プロジェクト: nzlov/gogl
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	texture.Bind(gl.TEXTURE_2D)

	for loop = 0; loop < num; loop++ {
		gl.LoadIdentity()                            // 绘制每颗星星之前,重置模型观察矩阵
		gl.Translatef(0.0, 0.0, zoom)                // 深入屏幕里面
		gl.Rotatef(tilt, 1.0, 0.0, 0.0)              // 倾斜视角
		gl.Rotatef(ztilt, 0.0, 0.0, 1.0)             // 倾斜视角
		gl.Rotatef(star[loop].angle, 0.0, 1.0, 0.0)  // 旋转至当前所画星星的角度
		gl.Translatef(star[loop].dist, 0.0, 0.0)     // 沿X轴正向移动
		gl.Rotatef(-star[loop].angle, 0.0, 1.0, 0.0) // 取消当前星星的角度
		gl.Rotatef(-ztilt, 0.0, 0.0, 1.0)            // 取消屏幕倾斜
		gl.Rotatef(-tilt, 1.0, 0.0, 0.0)             // 取消屏幕倾斜
		if twinkle {                                 // 启用闪烁效果
			// 使用byte型数值指定一个颜色
			gl.Color4ub(star[(num-loop)-1].r, star[(num-loop)-1].g, star[(num-loop)-1].b, 255)
			gl.Begin(gl.QUADS) // 开始绘制纹理映射过的四边形
			gl.TexCoord2f(0.0, 0.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(1.0, 1.0)
			gl.Vertex3f(1.0, 1.0, 0.0)
			gl.TexCoord2f(0.0, 1.0)
			gl.Vertex3f(-1.0, 1.0, 0.0)
			gl.End() // 四边形绘制结束

		}
		gl.Rotatef(spin, 0.0, 0.0, 1.0) // 绕z轴旋转星星
		// 使用byte型数值指定一个颜色
		gl.Color4ub(star[loop].r, star[loop].g, star[loop].b, 255)
		gl.Begin(gl.QUADS) // 开始绘制纹理映射过的四边形
		gl.TexCoord2f(0.0, 0.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(1.0, 1.0)
		gl.Vertex3f(1.0, 1.0, 0.0)
		gl.TexCoord2f(0.0, 1.0)
		gl.Vertex3f(-1.0, 1.0, 0.0)
		gl.End() // 四边形绘制结束

		spin += 0.01                            // 星星的公转
		star[loop].angle += float32(loop) / num // 改变星星的自转角度
		star[loop].dist -= 0.01                 // 改变星星离中心的距离
		if star[loop].dist < 0.0 {              // 星星到达中心了么
			star[loop].dist += 5 // 往外移5个单位
			//fmt.Println(loop, star[loop].dist)
			star[loop].r = uint8(rand.Int() % 256) // 赋一个新红色分量
			star[loop].g = uint8(rand.Int() % 256) // 赋一个新绿色分量
			star[loop].b = uint8(rand.Int() % 256) // 赋一个新蓝色分量
		}
	}
}
コード例 #9
0
ファイル: main.go プロジェクト: srm88/blocks
func drawBlock(loc Loc, b *Block) {
	// Save current modelview matrix on to the stack
	gl.PushMatrix()
	// Move block
	gl.Translatef(loc.X, loc.Y, loc.Z)
	// Rotate block
	gl.Rotatef(b.Pitch, 1, 0, 0)
	gl.Rotatef(b.Yaw, 0, 1, 0)
	gl.Rotatef(b.Roll, 0, 0, 1)
	// Start specifying the vertices of quads.
	gl.Begin(gl.QUADS)
	for _, quad := range b.Quads {
		gl.Color3fv(quad.Color)
		for _, vertex := range quad.Vertices {
			gl.Vertex3fv(b.Vertices[vertex])
		}
	}
	gl.End()
	// Restore old modelview matrix
	gl.PopMatrix()
}
コード例 #10
0
ファイル: main_init.go プロジェクト: remogatto/mozaik
func renderSwitchBlocks(s *Switch) {
	// TODO constant
	v := SwitchSize / 2
	x, y := float32(s.X+v), float32(s.Y+v)
	gl.LoadIdentity()
	gl.Translatef(x, y, 0)
	if s.rotate != 0 {
		gl.Rotatef(float32(s.rotate), 0, 0, 1)
	}
	bsf := float32(BlockSize - s.Z)
	padding := float32(BlockPadding)

	var b *Block
	// Render block top left
	b = g.level.blocks[s.line][s.col]
	if !b.Rendered {
		gl.PushMatrix()
		gl.Translatef(-bsf-padding, -bsf-padding, 0)
		renderBlock(b, bsf)
		gl.PopMatrix()
		b.Rendered = true
	}

	// Render block top right
	b = g.level.blocks[s.line][s.col+1]
	if !b.Rendered {
		gl.PushMatrix()
		gl.Translatef(padding, -bsf-padding, 0)
		renderBlock(b, bsf)
		gl.PopMatrix()
		b.Rendered = true
	}

	// Render block bottom right
	b = g.level.blocks[s.line+1][s.col+1]
	if !b.Rendered {
		gl.PushMatrix()
		gl.Translatef(padding, padding, 0)
		renderBlock(b, bsf)
		gl.PopMatrix()
		b.Rendered = true
	}

	// render block bottom left
	b = g.level.blocks[s.line+1][s.col]
	if !b.Rendered {
		gl.PushMatrix()
		gl.Translatef(-bsf-padding, padding, 0)
		renderBlock(b, bsf)
		gl.PopMatrix()
		b.Rendered = true
	}
}
コード例 #11
0
ファイル: 20110516_nehe04.go プロジェクト: bonly/exercise
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) /// 清除屏幕及深度缓存

	gl.LoadIdentity()              /// 重置模型观察矩阵
	gl.Translatef(-1.5, 0, -6)     /// 左移 1.5 单位,并移入屏幕 6.0
	gl.Rotatef(trisAngle, 0, 1, 0) ///以y为轴 参数:角度,X,Y,Z

	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()               ///三角形绘制结束,三角形将被填充。
	//但是因为每个顶点有不同的颜色,因此看起来颜色从每个角喷出,并刚好在三角形的中心汇合,三种颜色相互混合。这就是平滑着色。

	/// 要让对象绕自身的轴旋转,必须让对象的中心坐标总是(0.0f,0,0f,0,0f),因此这里的四边形是满屏跑的
	gl.LoadIdentity() ///将当前点移到了屏幕中心,X坐标轴从左至右,Y坐标轴从下至上,Z坐标轴从里至外。
	///OpenGL屏幕中心的坐标值是X和Y轴上的0.0f点。中心左面的坐标值是负值,右面是正值。移向屏幕顶端是正值,移向屏幕底端是负值。移入屏幕深处是负值,移出屏幕则是正值。
	gl.Rotatef(quadAngle, 1, 0, 0) /// 以x为轴
	gl.Translatef(1.5, 0, -6)      ///以当前点为起始点移动?(是的)-6为距离
	//gl.Translatef(3, 0, -6); ///右移3单位,看不见?(因为loadIdentity()置中了)
	gl.Color3f(0.5, 0.5, 1.0) ///一次性将当前色设置为蓝色

	/// @note 顺时针绘制的正方形意味着我们所看见的是四边形的背面
	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() ///必须交换显示区才能展现
}
コード例 #12
0
ファイル: main.go プロジェクト: srm88/blocks
func redraw() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	var viewport [4]int32
	gl.GetIntegerv(gl.VIEWPORT, viewport[:4])
	aspect := float64(viewport[2]) / float64(viewport[3])
	glu.Perspective(60, aspect, 1, 100)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(POV.X, POV.Y, POV.Z)
	gl.Rotatef(POV.Pitch, 1, 0, 0)
	gl.Rotatef(POV.Yaw, 0, 1, 0)
	gl.Rotatef(POV.Roll, 0, 0, 1)
	for x, row := range World {
		for z, block := range row {
			drawBlock(translateCoordinates(x, 0, z), block)
			if x == CursorX && z == CursorZ {
				drawCursor()
			}
		}
	}
}
コード例 #13
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()
	}
}
コード例 #14
0
ファイル: view.go プロジェクト: rick-monster/gopong
func drawBall(angle float32, ball_x float32, ball_y float32) {
	gl.PushMatrix()
	gl.Color3f(1, 1, 1)
	gl.Translatef(ball_x, ball_y, 0.0)
	gl.Begin(gl.LINE_LOOP)
	for rad := 0.0; rad < 1.0; rad += 0.01 {
		gl.Vertex2f(
			float32(2.0*math.Cos(2.0*math.Pi*rad)),
			float32(2.0*math.Sin(2.0*math.Pi*rad)+0.2))
	}
	gl.End()
	gl.Rotatef(angle, 0.0, 0.0, 1.0)

	gl.Begin(gl.LINE_STRIP)
	gl.Vertex2f(0, 0)
	gl.Vertex2f(2, 0)
	gl.End()

	gl.PopMatrix()
}
コード例 #15
0
ファイル: main.go プロジェクト: TheOnly92/gexic
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()
}
コード例 #16
0
ファイル: 05.go プロジェクト: nzlov/gogl
func draw() {                  // 从这里开始进行所有的绘制

	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) // 清除屏幕和深度缓存
	gl.LoadIdentity()                                   // 重置当前的模型观察矩阵
	gl.Translatef(-1.5, 0.0, -6.0)                      // 左移 1.5 单位,并移入屏幕 6.0

	gl.Rotatef(rtri, 0.0, 1.0, 0.0) // 绕Y轴旋转三角形

	gl.Begin(gl.TRIANGLES)       // 绘制三角形
	gl.Color3f(1.0, 0.0, 0.0)    // 设置当前色为红色
	gl.Vertex3f(0.0, 1.0, 0.0)   // 三角形的上顶点 (前侧面)
	gl.Color3f(0.0, 1.0, 0.0)    // 设置当前色为绿色
	gl.Vertex3f(-1.0, -1.0, 1.0) // 三角形的左下顶点 (前侧面)
	gl.Color3f(0.0, 0.0, 1.0)    // 设置当前色为蓝色
	gl.Vertex3f(1.0, -1.0, 1.0)  // 三角形的右下顶点 (前侧面)

	gl.Color3f(1.0, 0.0, 0.0)    // 设置当前色为红色
	gl.Vertex3f(0.0, 1.0, 0.0)   // 三角形的上顶点 (右侧面)
	gl.Color3f(0.0, 0.0, 1.0)    // 设置当前色为蓝色
	gl.Vertex3f(1.0, -1.0, 1.0)  // 三角形的左下顶点 (右侧面)
	gl.Color3f(0.0, 1.0, 0.0)    // 设置当前色为绿色
	gl.Vertex3f(1.0, -1.0, -1.0) // 三角形的右下顶点 (右侧面)

	gl.Color3f(1.0, 0.0, 0.0)     // 设置当前色为红色
	gl.Vertex3f(0.0, 1.0, 0.0)    // 三角形的上顶点 (后侧面)
	gl.Color3f(0.0, 0.0, 1.0)     // 设置当前色为蓝色
	gl.Vertex3f(1.0, -1.0, -1.0)  // 三角形的左下顶点 (后侧面)
	gl.Color3f(0.0, 1.0, 0.0)     // 设置当前色为绿色
	gl.Vertex3f(-1.0, -1.0, -1.0) // 三角形的右下顶点 (后侧面)

	gl.Color3f(1.0, 0.0, 0.0)     // 设置当前色为红色
	gl.Vertex3f(0.0, 1.0, 0.0)    // 三角形的上顶点 (左侧面)
	gl.Color3f(0.0, 0.0, 1.0)     // 设置当前色为蓝色
	gl.Vertex3f(-1.0, -1.0, -1.0) // 三角形的左下顶点 (左侧面)
	gl.Color3f(0.0, 1.0, 0.0)     // 设置当前色为绿色
	gl.Vertex3f(-1.0, -1.0, 1.0)  // 三角形的右下顶点 (左侧面)

	gl.End()                      // 三角形侧面绘制结束
	gl.Begin(gl.QUADS)            // 三角形底面绘制形
	gl.Vertex3f(1.0, -1.0, -1.0)  // 四边形的右上顶点 (底面)
	gl.Vertex3f(-1.0, -1.0, -1.0) // 四边形的左上顶点 (底面)
	gl.Vertex3f(-1.0, -1.0, 1.0)  // 四边形的左下顶点 (底面)
	gl.Vertex3f(1.0, -1.0, 1.0)   // 四边形的右下顶点 (底面)
	gl.End()                      // 三角形底面绘制结束

	gl.LoadIdentity()                // 重置当前的模型观察矩阵
	gl.Translatef(1.5, 0.0, -7.0)    // 右移1.5单位,并移入屏幕 6.0
	gl.Rotatef(rquad, 1.0, 1.0, 1.0) //  绕X轴旋转四边形
	gl.Begin(gl.QUADS)               //  绘制正方形

	gl.Color3f(1.0, 0.0, 0.0)    // 一次性将当前色设置为红色
	gl.Vertex3f(1.0, 1.0, -1.0)  // 四边形的右上顶点 (顶面)
	gl.Vertex3f(-1.0, 1.0, -1.0) // 四边形的左上顶点 (顶面)
	gl.Vertex3f(-1.0, 1.0, 1.0)  // 四边形的左下顶点 (顶面)
	gl.Vertex3f(1.0, 1.0, 1.0)   // 四边形的右下顶点 (顶面)

	gl.Color3f(1.0, 0.5, 0.0)    // 一次性将当前色设置为橙色
	gl.Vertex3f(1.0, 1.0, 1.0)   // 四边形的右上顶点 (前面)
	gl.Vertex3f(-1.0, 1.0, 1.0)  // 四边形的左上顶点 (前面)
	gl.Vertex3f(-1.0, -1.0, 1.0) // 四边形的左下顶点 (前面)
	gl.Vertex3f(1.0, -1.0, 1.0)  // 四边形的右下顶点 (前面)

	gl.Color3f(0.0, 0.0, 1.0)    // 一次性将当前色设置为绿色
	gl.Vertex3f(1.0, 1.0, -1.0)  // 四边形的右上顶点 (右面)
	gl.Vertex3f(1.0, 1.0, 1.0)   // 四边形的左上顶点 (右面)
	gl.Vertex3f(1.0, -1.0, 1.0)  // 四边形的左下顶点 (右面)
	gl.Vertex3f(1.0, -1.0, -1.0) // 四边形的右下顶点 (右面)

	gl.Color3f(0.0, 1.0, 0.0)     // 一次性将当前色设置为蓝色
	gl.Vertex3f(-1.0, 1.0, -1.0)  // 四边形的右上顶点 (后面)
	gl.Vertex3f(1.0, 1.0, -1.0)   // 四边形的左上顶点 (后面)
	gl.Vertex3f(1.0, -1.0, -1.0)  // 四边形的左下顶点 (后面)
	gl.Vertex3f(-1.0, -1.0, -1.0) // 四边形的右下顶点 (后面)

	gl.Color3f(1.0, 1.0, 0.0)     // 一次性将当前色设置为黄色
	gl.Vertex3f(-1.0, 1.0, 1.0)   // 四边形的右上顶点 (左面)
	gl.Vertex3f(-1.0, 1.0, -1.0)  // 四边形的左上顶点 (左面)
	gl.Vertex3f(-1.0, -1.0, -1.0) // 四边形的左下顶点 (左面)
	gl.Vertex3f(-1.0, -1.0, 1.0)  // 四边形的右下顶点 (左面)

	gl.Color3f(1.0, 1.0, 1.0)     // 一次性将当前色设置为白色
	gl.Vertex3f(1.0, -1.0, -1.0)  // 四边形的右上顶点 (底面)
	gl.Vertex3f(-1.0, -1.0, -1.0) // 四边形的左上顶点 (底面)
	gl.Vertex3f(-1.0, -1.0, 1.0)  // 四边形的左下顶点 (底面)
	gl.Vertex3f(1.0, -1.0, 1.0)   // 四边形的右下顶点 (底面)
	gl.End()

	rtri += 0.2 // 增加三角形的旋转变量

	rquad -= 0.15 // 减少四边形的旋转变量
}
コード例 #17
0
ファイル: 20110517_nehe06.go プロジェクト: bonly/exercise
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) /// 清除屏幕及深度缓存
	gl.LoadIdentity()                                   /// 重置模型观察矩阵

	gl.Translatef(0, 0, -5)          /// 并移入屏幕 5.0
	gl.Rotatef(rotation[0], 1, 0, 0) ///以x为轴旋转 参数:角度,X,Y,Z
	gl.Rotatef(rotation[1], 0, 1, 0)
	gl.Rotatef(rotation[2], 0, 0, 1)

	rotation[0] += 0.3
	rotation[1] += 0.2
	rotation[2] += 0.4

	/*
	  选择我们使用的纹理。如果您在您的场景中使用多个纹理,
	  应该使用来 glBindTexture(GL_TEXTURE_2D, texture[ 所使用纹理对应的数字 ]) 选择要绑定的纹理。
	  当想改变纹理时,应该绑定新的纹理。有一点值得指出的是,您不能在 glBegin() 和 glEnd() 之间绑定纹理,
	  必须在 glBegin() 之前或 glEnd() 之后绑定。注意在后面是如何使用 glBindTexture 来指定和绑定纹理的。
	*/
	textures[0].Bind(gl.TEXTURE_2D) ///选择纹理

	/*
	为了将纹理正确的映射到四边形上,必须将纹理的右上角映射到四边形的右上角,纹理的左上角映射到四边形的左上角,
	纹理的右下角映射到四边形的右下角,纹理的左下角映射到四边形的左下角。
	如果映射错误的话,图像显示时可能上下颠倒,侧向一边或者什么都不是。
	glTexCoord2f 的第一个参数是X坐标。 0.0f 是纹理的左侧。 0.5f 是纹理的中点, 1.0f 是纹理的右侧。
	glTexCoord2f 的第二个参数是Y坐标。 0.0f 是纹理的底部。 0.5f 是纹理的中点, 1.0f 是纹理的顶部。

	所以纹理的左上坐标是 X:0.0f,Y:1.0f ,四边形的左上顶点是 X: -1.0f,Y:1.0f 。其余三点依此类推。
	*/
	gl.Begin(gl.QUADS)     ///绘制正方形
	gl.TexCoord2f(0, 0)    ///前面
	gl.Vertex3f(-1, -1, 1) ///左下
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, 1) ///右下
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, 1) ///右上
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, 1) ///左上

	gl.TexCoord2d(1, 0)     ///后面
	gl.Vertex3f(-1, -1, -1) ///右下
	gl.TexCoord2d(1, 1)
	gl.Vertex3f(-1, 1, -1) ///右上
	gl.TexCoord2d(0, 1)
	gl.Vertex3f(1, 1, -1) ///左上
	gl.TexCoord2d(0, 0)
	gl.Vertex3f(1, -1, -1) //左下

	gl.TexCoord2d(0, 1) ///上面
	gl.Vertex3f(-1, 1, -1)
	gl.TexCoord2d(0, 0)
	gl.Vertex3f(-1, 1, 1)
	gl.TexCoord2d(1, 0)
	gl.Vertex3f(1, 1, 1)
	gl.TexCoord2d(1, 1)
	gl.Vertex3f(1, 1, -1)

	gl.TexCoord2d(1, 1) ///下面
	gl.Vertex3f(-1, -1, -1)
	gl.TexCoord2d(0, 1)
	gl.Vertex3f(1, -1, -1)
	gl.TexCoord2d(0, 0)
	gl.Vertex3f(1, -1, 1)
	gl.TexCoord2d(1, 0)
	gl.Vertex3f(-1, -1, -1)

	gl.TexCoord2d(1, 0) ///右面
	gl.Vertex3f(1, -1, -1)
	gl.TexCoord2d(1, 1)
	gl.Vertex3f(1, 1, -1)
	gl.TexCoord2d(0, 1)
	gl.Vertex3f(1, 1, 1)
	gl.TexCoord2d(0, 0)
	gl.Vertex3f(1, -1, 1)

	gl.TexCoord2d(0, 0) ///左面
	gl.Vertex3f(-1, -1, -1)
	gl.TexCoord2d(1, 0)
	gl.Vertex3f(-1, -1, 1)
	gl.TexCoord2d(1, 1)
	gl.Vertex3f(-1, 1, 1)
	gl.TexCoord2d(0, 1)
	gl.Vertex3f(-1, 1, -1)

	gl.End() ///正方形绘制结束

	glfw.SwapBuffers() ///必须交换显示区才能展现
}
コード例 #18
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)
}
コード例 #19
0
ファイル: main.go プロジェクト: pwaller/examples
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.LoadIdentity()

	gl.Translatef(0, 0, z)

	gl.Rotatef(rotation[0], 1, 0, 0)
	gl.Rotatef(rotation[1], 0, 1, 0)

	rotation[0] += speed[0]
	rotation[1] += speed[1]

	textures[filter].Bind(gl.TEXTURE_2D)

	gl.Begin(gl.QUADS)
	// Front Face
	gl.Normal3f(0, 0, 1) // Normal Pointing Towards Viewer
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, 1) // Point 1 (Front)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, 1) // Point 2 (Front)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, 1) // Point 3 (Front)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, 1) // Point 4 (Front)
	// Back Face
	gl.Normal3f(0, 0, -1) // Normal Pointing Away From Viewer
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, -1) // Point 1 (Back)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, -1) // Point 2 (Back)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, -1) // Point 3 (Back)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, -1) // Point 4 (Back)
	// Top Face
	gl.Normal3f(0, 1, 0) // Normal Pointing Up
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1) // Point 1 (Top)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, 1, 1) // Point 2 (Top)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, 1, 1) // Point 3 (Top)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1) // Point 4 (Top)
	// Bottom Face
	gl.Normal3f(0, -1, 0) // Normal Pointing Down
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, -1, -1) // Point 1 (Bottom)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, -1, -1) // Point 2 (Bottom)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1) // Point 3 (Bottom)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1) // Point 4 (Bottom)
	// Right face
	gl.Normal3f(1, 0, 0) // Normal Pointing Right
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, -1) // Point 1 (Right)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1) // Point 2 (Right)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, 1) // Point 3 (Right)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1) // Point 4 (Right)
	// Left Face
	gl.Normal3f(-1, 0, 0) // Normal Pointing Left
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, -1) // Point 1 (Left)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1) // Point 2 (Left)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, 1) // Point 3 (Left)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1)
	gl.End()

	glfw.SwapBuffers()
}
コード例 #20
0
ファイル: main.go プロジェクト: sixthgear/landscapes
func main() {

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

	if err := glfw.OpenWindow(800, 600, 8, 8, 8, 8, 32, 0, glfw.Windowed); err != nil {
		glfw.Terminate()
		log.Fatal(err.Error())
	}

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

	m := GenerateMap(160, 160, 16)
	m.BuildVertices()

	gl.Enable(gl.LIGHT0)
	gl.Enable(gl.LIGHTING)
	gl.Lightfv(gl.LIGHT0, gl.POSITION, []float32{0, 1, 0.2, 0})
	gl.Lightfv(gl.LIGHT0, gl.AMBIENT, []float32{0.0, 0.0, 0.0, 1})
	gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, []float32{0.75, 0.75, 0.75, 1})
	gl.Lightfv(gl.LIGHT0, gl.SPECULAR, []float32{1, 1, 1, 1})

	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0.1, 0.05, 0.0, 1.0)

	far := 4096.0
	fov := 60.0

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	glu.Perspective(fov, 800.0/600, 1.0, far)
	gl.MatrixMode(gl.MODELVIEW)

	rot := float32(0.0)

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

		rot += 0.125

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

		gl.LoadIdentity()

		gl.Enable(gl.DEPTH_TEST)
		gl.DepthFunc(gl.LEQUAL)

		cx := float32(m.width*m.gridSize) * 0.5
		cy := float32(m.maxHeight) * 0.15
		cz := float32(m.depth*m.gridSize) * 0.5

		gl.Translatef(0, 0, -2000)
		gl.Rotatef(30, 1, 0, 0)
		gl.Rotatef(rot, 0, 1, 0)
		gl.Translatef(-cx, -cy, -cz)

		m.Draw()
		glfw.SwapBuffers()
	}

	glfw.Terminate()

}
コード例 #21
0
ファイル: main.go プロジェクト: pwaller/debris
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

	w, h := 1980, 1080
	// w, h := 1280, 768
	if err = glfw.OpenWindow(w, h, 8, 8, 8, 16, 0, 32, glfw.Fullscreen); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.CloseWindow()

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

	quadric = glu.NewQuadric()

	gl.Enable(gl.CULL_FACE)

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LEQUAL)

	gl.Enable(gl.NORMALIZE)

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

	gl.ShadeModel(gl.SMOOTH)
	gl.Enable(gl.LIGHTING)

	var (
		ambient        = []float32{0.1, 0.3, 0.6, 1}
		diffuse        = []float32{1, 1, 0.5, 1}
		specular       = []float32{0.4, 0.4, 0.4, 1}
		light_position = []float32{1, 0, 0, 0}

		// mat_specular  []float32 = []float32{1, 1, 0.5, 1}
		mat_specular  = []float32{1, 1, 0.75, 1}
		mat_shininess = float32(120)
		// light_position []float32 = []float32{0.0, 0.0, 1.0, 0.0}
	)

	const (
		fov               = 1.1 // degrees
		znear             = 145
		zfar              = 155
		camera_z_offset   = -150
		camera_x_rotation = 0 // degrees
		// camera_x_rotation = 20 // degrees

		starfield_fov = 45

		faces        = 1000
		earth_radius = 1
	)

	gl.Lightfv(gl.LIGHT1, gl.AMBIENT, ambient)
	gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, diffuse)
	gl.Lightfv(gl.LIGHT1, gl.SPECULAR, specular)
	gl.Lightfv(gl.LIGHT1, gl.POSITION, light_position)
	gl.Enable(gl.LIGHT1)

	mat_emission := []float32{0, 0, 0.1, 1}
	gl.Materialfv(gl.FRONT_AND_BACK, gl.EMISSION, mat_emission)
	gl.Materialfv(gl.FRONT_AND_BACK, gl.SPECULAR, mat_specular)
	gl.Materialf(gl.FRONT_AND_BACK, gl.SHININESS, mat_shininess)

	gl.ClearColor(0.02, 0.02, 0.02, 1)
	gl.ClearDepth(1)
	gl.ClearStencil(0)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	b := createBuffer()

	planetoids := []*Planetoid{}
	for i := 0; i < 1000; i++ {
		p := &Planetoid{
			apogee:  1.2 + rand.Float64()*0.7,
			perigee: 1.5,
			// inclination: 45,
			inclination: rand.Float64()*20 - 10,
			// inclination: 0,
			phase0:      rand.Float64() * 360,
			rising_node: rand.Float64() * 10,
			phase:       0,
			// radius:      rand.Float32()*0.05 + 0.01, //float32(r),
			radius: rand.Float32()*0.0125 + 0.005, //float32(r),
			// quadric:     glu.NewQuadric(),
			circle: b,
		}
		planetoids = append(planetoids, p)
	}

	// Initial projection matrix:

	var aspect float64

	glfw.SetWindowSizeCallback(func(w, h int) {
		gl.Viewport(0, 0, w, h)

		gl.MatrixMode(gl.PROJECTION)
		gl.LoadIdentity()
		aspect = float64(w) / float64(h)
		glu.Perspective(fov, aspect, znear, zfar)
	})

	d := float64(0)

	wireframe := false
	atmosphere := false
	polar := false
	rotating := false
	front := false
	earth := true
	cone := true
	shadowing := true
	tilt := false
	running := true

	glfw.SetKeyCallback(func(key, state int) {
		if state != glfw.KeyPress {
			// Don't act on key coming up
			return
		}

		switch key {
		case 'A':
			atmosphere = !atmosphere
		case 'C':
			cone = !cone
		case 'E':
			earth = !earth
		case 'R':
			rotating = !rotating
		case 'F':
			front = !front
			if front {
				gl.FrontFace(gl.CW)
			} else {
				gl.FrontFace(gl.CCW)
			}
		case 'S':
			shadowing = !shadowing
		case 'T':
			tilt = !tilt
		case 'W':
			wireframe = !wireframe
			method := gl.GLenum(gl.FILL)
			if wireframe {
				method = gl.LINE
			}
			gl.PolygonMode(gl.FRONT_AND_BACK, method)

		case glfw.KeyF2:
			println("Screenshot captured")
			// glh.CaptureToPng("screenshot.png")

			w, h := glh.GetViewportWH()
			im := image.NewRGBA(image.Rect(0, 0, w, h))
			glh.ClearAlpha(1)
			gl.Flush()
			glh.CaptureRGBA(im)

			go func() {
				fd, err := os.Create("screenshot.png")
				if err != nil {
					panic("Unable to open file")
				}
				defer fd.Close()

				png.Encode(fd, im)
			}()

		case 'Q', glfw.KeyEsc:
			running = !running

		case glfw.KeySpace:
			polar = !polar
		}
	})

	_ = rand.Float64

	stars := glh.NewMeshBuffer(
		glh.RenderArrays,
		glh.NewPositionAttr(3, gl.DOUBLE, gl.STATIC_DRAW),
		glh.NewColorAttr(3, gl.DOUBLE, gl.STATIC_DRAW))

	const Nstars = 50000
	points := make([]float64, 3*Nstars)
	colors := make([]float64, 3*Nstars)

	for i := 0; i < Nstars; i++ {
		const R = 1

		phi := rand.Float64() * 2 * math.Pi
		z := R * (2*rand.Float64() - 1)
		theta := math.Asin(z / R)

		points[i*3+0] = R * math.Cos(theta) * math.Cos(phi)
		points[i*3+1] = R * math.Cos(theta) * math.Sin(phi)
		points[i*3+2] = z

		const r = 0.8
		v := rand.Float64()*r + (1 - r)
		colors[i*3+0] = v
		colors[i*3+1] = v
		colors[i*3+2] = v
	}

	stars.Add(points, colors)

	render_stars := func() {
		glh.With(glh.Attrib{gl.DEPTH_BUFFER_BIT | gl.ENABLE_BIT}, func() {
			gl.Disable(gl.LIGHTING)
			gl.PointSize(1)
			gl.Color4f(1, 1, 1, 1)

			gl.Disable(gl.DEPTH_TEST)
			gl.DepthMask(false)

			stars.Render(gl.POINTS)
		})
	}

	render_scene := func() {

		// Update light position (sensitive to current modelview matrix)
		gl.Lightfv(gl.LIGHT1, gl.POSITION, light_position)
		gl.Lightfv(gl.LIGHT2, gl.POSITION, light_position)

		if earth {
			Sphere(earth_radius, faces)
		}

		unlit_points := glh.Compound(glh.Disable(gl.LIGHTING), glh.Primitive{gl.POINTS})
		glh.With(unlit_points, func() {
			gl.Vertex3d(1, 0, 0)
		})

		for _, p := range planetoids {
			const dt = 0.1 // TODO: Frame update
			p.Render(dt)
		}

		glh.With(glh.Disable(gl.LIGHTING), func() {
			// Atmosphere
			gl.Color4f(0.25, 0.25, 1, 0.1)

			if atmosphere && earth {
				Sphere(earth_radius*1.025, 100)
			}

			gl.PointSize(10)

			glh.With(glh.Primitive{gl.POINTS}, func() {
				gl.Color4f(1.75, 0.75, 0.75, 1)
				gl.Vertex3d(-1.04, 0, 0)
			})
		})

	}

	render_shadow_volume := func() {

		glh.With(glh.Attrib{
			gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.ENABLE_BIT |
				gl.POLYGON_BIT | gl.STENCIL_BUFFER_BIT,
		}, func() {

			gl.Disable(gl.LIGHTING)

			if shadowing {
				// gl.Disable(gl.DEPTH_TEST)
				gl.DepthMask(false)
				gl.DepthFunc(gl.LEQUAL)

				gl.Enable(gl.STENCIL_TEST)
				gl.ColorMask(false, false, false, false)
				gl.StencilFunc(gl.ALWAYS, 1, 0xffffffff)
			}

			shadow_volume := func() {
				const sv_length = 2
				const sv_granularity = 100
				const sv_radius = earth_radius * 1.001

				// Shadow cone
				glh.With(glh.Matrix{gl.MODELVIEW}, func() {
					gl.Rotatef(90, 1, 0, 0)
					gl.Rotatef(90, 0, -1, 0)
					gl.Color4f(0.5, 0.5, 0.5, 1)
					glu.Cylinder(quadric, sv_radius, sv_radius*1.05,
						sv_length, sv_granularity, 1)

					glu.Disk(quadric, 0, sv_radius, sv_granularity, 1)

					glh.With(glh.Matrix{gl.MODELVIEW}, func() {
						gl.Translated(0, 0, sv_length)
						glu.Disk(quadric, 0, sv_radius*1.05, sv_granularity, 1)
					})
				})

				for _, p := range planetoids {
					p.RenderShadowVolume()
				}

			}

			if cone {
				gl.FrontFace(gl.CCW)
				gl.StencilOp(gl.KEEP, gl.KEEP, gl.INCR)

				shadow_volume()

				gl.FrontFace(gl.CW)
				gl.StencilOp(gl.KEEP, gl.KEEP, gl.DECR)

				shadow_volume()
			}

			if shadowing {
				gl.StencilFunc(gl.NOTEQUAL, 0, 0xffffffff)
				gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP)

				gl.ColorMask(true, true, true, true)
				// gl.Disable(gl.STENCIL_TEST)

				gl.Disable(gl.DEPTH_TEST)

				gl.FrontFace(gl.CCW)
				// gl.Color4f(1, 0, 0, 0.75)
				gl.Color4f(0, 0, 0, 0.75)
				// gl.Color4f(1, 1, 1, 0.75)

				gl.LoadIdentity()
				gl.Translated(0, 0, camera_z_offset)
				// TODO: Figure out why this doesn't draw over the whole screen
				glh.With(glh.Disable(gl.LIGHTING), func() {
					glh.DrawQuadd(-10, -10, 20, 20)
				})

				// gl.FrontFace(gl.CW)
				// gl.Enable(gl.LIGHTING)
				// gl.Disable(gl.LIGHT1)
				// render_scene()
				// gl.Enable(gl.LIGHT1)
			}
		})
	}
	_ = render_stars

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

		glfw.SwapBuffers()

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

		rotation := func() {
			if tilt {
				gl.Rotated(20, 1, 0, 0)
			}

			if polar {
				gl.Rotated(90, 1, 0, 0)
			}

			gl.Rotated(d, 0, -1, 0)
		}

		// Star field

		glh.With(glh.Matrix{gl.PROJECTION}, func() {
			gl.LoadIdentity()
			glu.Perspective(starfield_fov, aspect, 0, 1)

			glh.With(glh.Matrix{gl.MODELVIEW}, func() {
				gl.LoadIdentity()
				rotation()
				render_stars()
			})
		})

		gl.MatrixMode(gl.MODELVIEW)
		gl.LoadIdentity()
		gl.Translated(0, 0, camera_z_offset)

		rotation()
		if rotating {
			d += 0.2
		}

		_ = render_scene
		render_scene()

		_ = render_shadow_volume
		render_shadow_volume()
	}
}
コード例 #22
0
ファイル: main.go プロジェクト: hsalokor/examples
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.LoadIdentity()

	gl.Translatef(0, 0, -5)

	gl.Rotatef(rotation[0], 1, 0, 0)
	gl.Rotatef(rotation[1], 0, 1, 0)
	gl.Rotatef(rotation[2], 0, 0, 1)

	rotation[0] += 0.3
	rotation[1] += 0.2
	rotation[2] += 0.4

	textures[0].Bind(gl.TEXTURE_2D)

	gl.Begin(gl.QUADS)
	// Front Face
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, 1) // Bottom Left Of The Texture and Quad
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, 1) // Bottom Right Of The Texture and Quad
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, 1) // Top Right Of The Texture and Quad
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, 1) // Top Left Of The Texture and Quad
	// Back Face
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, -1) // Bottom Right Of The Texture and Quad
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, -1) // Top Right Of The Texture and Quad
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, -1) // Top Left Of The Texture and Quad
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, -1) // Bottom Left Of The Texture and Quad
	// Top Face
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1) // Top Left Of The Texture and Quad
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, 1, 1) // Bottom Left Of The Texture and Quad
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, 1, 1) // Bottom Right Of The Texture and Quad
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1) // Top Right Of The Texture and Quad
	// Bottom Face
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, -1, -1) // Top Right Of The Texture and Quad
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, -1, -1) // Top Left Of The Texture and Quad
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1) // Bottom Left Of The Texture and Quad
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1) // Bottom Right Of The Texture and Quad
	// Right face
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, -1) // Bottom Right Of The Texture and Quad
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1) // Top Right Of The Texture and Quad
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, 1) // Top Left Of The Texture and Quad
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1) // Bottom Left Of The Texture and Quad
	// Left Face
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, -1) // Bottom Left Of The Texture and Quad
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1) // Bottom Right Of The Texture and Quad
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, 1) // Top Right Of The Texture and Quad
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1) // Top Left Of The Texture and Quad
	gl.End()

	glfw.SwapBuffers()
}
コード例 #23
0
ファイル: animate.go プロジェクト: TheOnly92/gexic
func (r *AnimateRotate) AnimateAndExecute() {
	if len(r.SelectedHex) == 0 {
		return
	}
	gl.PushMatrix()
	var p Point
	for _, hex := range r.SelectedHex {
		p.X += hexMap2.GetCenter(hex.Pos.X, hex.Pos.Y).X
		p.Y += hexMap2.GetCenter(hex.Pos.X, hex.Pos.Y).Y
	}
	p.X /= 3
	p.Y /= 3
	x, y := p.WithOffset()
	gl.Translatef(float32(x), float32(y), 0)
	if r.PauseTicks == 0 {
		gl.Scalef(1.3, 1.3, 1)
		gl.Rotatef(r.RotateAngle, 0, 0, 1)
	} else {
		r.PauseTicks--
	}
	for _, hex := range r.SelectedHex {
		gl.PushMatrix()
		x2, y2 := hexMap2.GetTopLeft(hex.Pos.X, hex.Pos.Y).WithOffset()
		gl.Translatef(float32(x2-x), float32(y2-y), 0)
		hex.Hex.Render(1, false)
		gl.PopMatrix()
	}
	gl.PopMatrix()
	if r.PauseTicks > 0 {
		return
	}
	if r.RotateAngle < 120 {
		r.RotateAngle += 20
	} else {
		fmt.Println(r.SelectedHex[0].Hex, r.SelectedHex[1].Hex, r.SelectedHex[2].Hex)
		hexMap2[r.SelectedHex[0].Pos.X][r.SelectedHex[0].Pos.Y], hexMap2[r.SelectedHex[1].Pos.X][r.SelectedHex[1].Pos.Y], hexMap2[r.SelectedHex[2].Pos.X][r.SelectedHex[2].Pos.Y] = hexMap2[r.SelectedHex[2].Pos.X][r.SelectedHex[2].Pos.Y], hexMap2[r.SelectedHex[0].Pos.X][r.SelectedHex[0].Pos.Y], hexMap2[r.SelectedHex[1].Pos.X][r.SelectedHex[1].Pos.Y]
		r.SelectedHex[0].Hex, r.SelectedHex[1].Hex, r.SelectedHex[2].Hex = r.SelectedHex[2].Hex, r.SelectedHex[0].Hex, r.SelectedHex[1].Hex
		collide := hexMap2.CheckCollision()
		if r.TimesToRotate == 0 || collide {
			for _, hex := range r.SelectedHex {
				if hex.Hex.State == StateRotating {
					hex.Hex.State = StateNormal
				}
			}
			r.SelectedHex = nil
			r.SelectedHex = make([]SelectedHex, 0)
			if collide {
				hexShrink.InitAnimation()
				if r.postHook != nil {
					hexShrink.postHook = r.postHook
				}
			} else {
				if r.postHook != nil {
					r.postHook()
				}
			}
		} else {
			r.TimesToRotate--
			r.RotateAngle = 0
			r.PauseTicks = 5
		}
	}
}
コード例 #24
0
ファイル: main.go プロジェクト: andrebq/exp
func main() {
	flag.Parse()

	loadMeshInfo()

	err := initGL()
	if err != nil {
		log.Printf("InitGL: %v", err)
		return
	}

	program, shaderInfo, err := loadShaders(gl.Program(0), nil)
	if err != nil {
		panic(err)
	}
	_ = program

	defer glfw.Terminate()

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

	// Perform the rendering.
	var angle float32
	reload := time.Tick(time.Duration(300 * time.Millisecond))
	for glfw.WindowParam(glfw.Opened) > 0 {
		select {
		case <-reload:
			oldInfo := shaderInfo
			program, shaderInfo, err = loadShaders(program, shaderInfo)
			if err != nil && lastErr == nil {
				lastErr = err
				println("Error loading shaders. Using old code.", lastErr)
			} else if err == nil && oldInfo != shaderInfo {
				lastErr = nil
				println("new shader code loaded")
			}
		default:
			// do nothing here
		}
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		gl.LoadIdentity()
		gl.Translatef(0, 0, -zoom)

		if angle > 0 {
			gl.Rotatef(angle, rotVet[0], rotVet[1], rotVet[2])
		}

		program.Use()

		gl.Enable(gl.COLOR_MATERIAL)
		gl.Enable(gl.POLYGON_OFFSET_FILL)
		gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)
		mb.Render(gl.TRIANGLES)

		if rotVet[0]+rotVet[1]+rotVet[2] != 0 {
			// only increment the angle if at least one of the rotate axis
			// is enabled
			angle += 0.5
		} else if angle != 0 {
			angle = 0
		}
		glfw.SwapBuffers()
	}
}
コード例 #25
0
ファイル: 20110518_nehe07.go プロジェクト: bonly/exercise
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) //清除屏幕和深度缓存
	gl.LoadIdentity()                                   //重置当前的模型观察矩阵

	gl.Translatef(0, 0, z) //移入/移出屏幕 z 个单位

	gl.Rotatef(rotation[0], 1, 0, 0) //绕X轴旋转
	gl.Rotatef(rotation[1], 0, 1, 0) //绕Y轴旋转

	rotation[0] += speed[0]
	rotation[1] += speed[1]

	textures[filter].Bind(gl.TEXTURE_2D) //绑定的纹理

	/*
	   Normal就是法线的意思,所谓法线是指经过面(多边形)上的一点且垂直于这个面(多边形)的直线。
	   使用光源的时候必须指定一条法线。法线告诉OpenGL这个多边形的朝向,并指明多边形的正面和背面。
	   如果没有指定法线,什么怪事情都可能发生:不该照亮的面被照亮了,多边形的背面也被照亮....。对了,法线应该指向多边形的外侧。

	   看着木箱的前面您会注意到法线与Z轴正向同向。这意味着法线正指向观察者-您自己。这正是我们所希望的。
	   对于木箱的背面,也正如我们所要的,法线背对着观察者。
	   如果立方体沿着X或Y轴转个180度的话,前侧面的法线仍然朝着观察者,背面的法线也还是背对着观察者。
	   换句话说,不管是哪个面,只要它朝着观察者这个面的法线就指向观察者。由于光源紧邻观察者,任何时候法线对着观察者时,这个面就会被照亮。
	   并且法线越朝着光源,就显得越亮一些。如果您把观察点放到立方体内部,你就会法线里面一片漆黑。因为法线是向外指的。
	   如果立方体内部没有光源的话,当然是一片漆黑。
	*/
	gl.Begin(gl.QUADS)
	// Front Face 前面
	gl.Normal3f(0, 0, 1) // Normal Pointing Towards Viewer 法线指向观察者
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, 1) // Point 1 (Front)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, 1) // Point 2 (Front)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, 1) // Point 3 (Front)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, 1) // Point 4 (Front)
	// Back Face 后面
	gl.Normal3f(0, 0, -1) // Normal Pointing Away From Viewer 法线背向观察者
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, -1) // Point 1 (Back)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, -1) // Point 2 (Back)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, -1) // Point 3 (Back)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, -1) // Point 4 (Back)
	// Top Face 顶面
	gl.Normal3f(0, 1, 0) // Normal Pointing Up  法线向上
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1) // Point 1 (Top)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, 1, 1) // Point 2 (Top)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, 1, 1) // Point 3 (Top)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1) // Point 4 (Top)
	// Bottom Face 底面
	gl.Normal3f(0, -1, 0) // Normal Pointing Down 法线朝下
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, -1, -1) // Point 1 (Bottom)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, -1, -1) // Point 2 (Bottom)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1) // Point 3 (Bottom)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1) // Point 4 (Bottom)
	// Right face 右面
	gl.Normal3f(1, 0, 0) // Normal Pointing Right 法线朝右
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, -1) // Point 1 (Right)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1) // Point 2 (Right)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, 1) // Point 3 (Right)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1) // Point 4 (Right)
	// Left Face 左面
	gl.Normal3f(-1, 0, 0) // Normal Pointing Left  法线朝左
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, -1) // Point 1 (Left)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1) // Point 2 (Left)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, 1) // Point 3 (Left)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1)
	gl.End()

	glfw.SwapBuffers()
}
コード例 #26
0
ファイル: gopher.go プロジェクト: nzlov/examples
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(0, 0, -3.0)
	gl.Rotatef(rotx, 1, 0, 0)
	gl.Rotatef(roty, 0, 1, 0)

	rotx += 0.5
	roty += 0.5

	texture.Bind(gl.TEXTURE_2D)

	gl.Color4f(1, 1, 1, 1)

	gl.Begin(gl.QUADS)

	gl.Normal3f(0, 0, 1)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, 1)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, 1)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, 1)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, 1)

	gl.Normal3f(0, 0, -1)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, -1)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, -1)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, -1)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, -1)

	gl.Normal3f(0, 1, 0)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, 1, 1)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, 1, 1)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1)

	gl.Normal3f(0, -1, 0)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, -1, -1)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, -1, -1)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1)

	gl.Normal3f(1, 0, 0)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, -1)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, 1)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1)

	gl.Normal3f(-1, 0, 0)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, -1)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, 1)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1)

	gl.End()
}