示例#1
0
func render() {
	modelMatrix = trig.MatrixMult(trig.RotateY(math.Pi/360), modelMatrix)

	gl.Viewport(0, 0, 768, 768)
	gl.ClearColor(0.0, 0.0, 0, 0)
	gl.Enable(gl.DEPTH_TEST)

	raytraceProgram.Use()
	mInput.UniformMatrix4f(false, (*[16]float32)(modelMatrix))
	vInput.UniformMatrix4f(false, (*[16]float32)(viewMatrix))
	pInput.UniformMatrix4f(false, (*[16]float32)(projMatrix))
	glh.With(framebuffer, func() {
		framebuffer.UpdateTextures()

		gl.DrawBuffer(gl.COLOR_ATTACHMENT0)

		gl.Clear(gl.COLOR_BUFFER_BIT)
		gl.DepthFunc(gl.GREATER)
		gl.CullFace(gl.BACK)
		cube.Render(gl.TRIANGLES, raytraceProgram)

		gl.DrawBuffer(gl.COLOR_ATTACHMENT1)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		gl.DepthFunc(gl.LESS)
		gl.CullFace(gl.FRONT)
		cube.Render(gl.TRIANGLES, raytraceProgram)
	})
}
示例#2
0
文件: gears.go 项目: nzlov/examples
// OpenGL draw function & timing
func draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

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

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

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

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

	gl.PopMatrix()
}
示例#3
0
func gameOverScreen(
	screen *sdl.Surface,
	score string,
	bg *glh.Texture,
	font *gltext.Font) bool {

	for {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch e.(type) {
			case *sdl.ResizeEvent:
				resize(screen, e.(*sdl.ResizeEvent))
			case *sdl.QuitEvent:
				return true
			case *sdl.MouseButtonEvent:
				return false
			}
		}
		renderBackground(screen, bg)
		font.Printf(110, 50, "Game Over")
		font.Printf(110, 100, "Your score: "+score)
		font.Printf(110, 150, "Click to play again")
		sdl.GL_SwapBuffers()
		time.Sleep((1 / 30) * time.Second)
	}
	return false
}
示例#4
0
文件: main.go 项目: andrebq/exp
func drawScene(mvp *glm.Matrix4, dt float64) {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	program, err := compileProgram(shaderDir, "sample")
	if err != nil {
		log.Printf("Error reading program. Cause: %v", err)
	} else {
		defer program.Delete()
	}

	// lets scale our model by 100, otherwise
	// the triangle will be 1 pixel width
	// let's make our triangle pulsate
	triangleScale += triangleScaleChangeFactor * float32(dt)
	if triangleScale >= 200 {
		triangleScale = 200
		triangleScaleChangeFactor *= -1
	} else if triangleScale < 10 {
		triangleScale = 10
		triangleScaleChangeFactor *= -1
	}
	scaled := mvp.Scale(glm.Vector3{triangleScale, triangleScale, triangleScale})

	loc := program.GetUniformLocation("MVP")
	loc.UniformMatrix4f(false, ptrForMatrix(scaled))
	theTriangleBuf.Render(gl.TRIANGLES)
}
示例#5
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 // 减少四边形的旋转变量
}
示例#6
0
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.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.Translatef(3, 0, 0)    ///右移3单位
	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()               ///正方形绘制结束

	glfw.SwapBuffers() ///必须交换显示区才能展现
}
示例#7
0
文件: 01.go 项目: nzlov/gogl
func draw() { // 从这里开始进行所有的绘制

	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) // 清除屏幕和深度缓存

	gl.LoadIdentity() // 重置当前的模型观察矩阵

}
示例#8
0
func main() {

	if !glfw.Init() {
		log.Fatal("glfw failed to initialize")
	}
	defer glfw.Terminate()

	window, err := glfw.CreateWindow(640, 480, "Deformable", nil, nil)
	if err != nil {
		log.Fatal(err.Error())
	}

	window.MakeContextCurrent()
	glfw.SwapInterval(1)
	window.SetMouseButtonCallback(handleMouseButton)
	window.SetKeyCallback(handleKeyDown)
	window.SetInputMode(glfw.Cursor, glfw.CursorHidden)

	gl.Init()
	initGL()

	i := 16
	m = GenerateMap(1600/i, 1200/i, i)
	for running && !window.ShouldClose() {

		x, y := window.GetCursorPosition()

		if drawing != 0 {
			m.Add(int(x)+int(camera[0]), int(y)+int(camera[1]), drawing, brushSizes[currentBrushSize])
		}

		gl.Clear(gl.COLOR_BUFFER_BIT)
		gl.LoadIdentity()

		gl.PushMatrix()
		gl.PushAttrib(gl.CURRENT_BIT | gl.ENABLE_BIT | gl.LIGHTING_BIT | gl.POLYGON_BIT | gl.LINE_BIT)
		gl.Translatef(-camera[0], -camera[1], 0)
		m.Draw()
		gl.PopAttrib()
		gl.PopMatrix()

		gl.PushAttrib(gl.COLOR_BUFFER_BIT)
		gl.LineWidth(2)
		gl.Enable(gl.BLEND)
		gl.BlendFunc(gl.ONE_MINUS_DST_COLOR, gl.ZERO)
		// gl.Enable(gl.LINE_SMOOTH)
		// gl.Hint(gl.LINE_SMOOTH_HINT, gl.NICEST)

		gl.Translatef(float32(x), float32(y), 0)

		gl.EnableClientState(gl.VERTEX_ARRAY)
		gl.VertexPointer(2, gl.DOUBLE, 0, cursorVerts)
		gl.DrawArrays(gl.LINE_LOOP, 0, 24)
		gl.PopAttrib()

		window.SwapBuffers()
		glfw.PollEvents()
	}

}
示例#9
0
// 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()
	}
}
示例#10
0
文件: util.go 项目: jasonrpowers/glh
// Clear the alpha channel in the color buffer
func ClearAlpha(alpha_value gl.GLclampf) {
	With(Attrib{gl.COLOR_BUFFER_BIT}, func() {
		gl.ColorMask(false, false, false, true)
		gl.ClearColor(0, 0, 0, alpha_value)
		gl.Clear(gl.COLOR_BUFFER_BIT)
	})
}
示例#11
0
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()
}
示例#12
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()
}
示例#13
0
文件: main.go 项目: jayschwa/examples
func onKey(key, state int) {
	switch key {
	case glfw.KeyEsc:
		running = state == 0
	case 67: // 'c'
		gl.Clear(gl.COLOR_BUFFER_BIT)
	}
}
示例#14
0
func (rw *RenderWindow) onKey(key, state int) {
	switch key {
	case glfw.KeyEsc:
		close(rw.quit)
	case 67: // 'c'
		gl.Clear(gl.COLOR_BUFFER_BIT)
	}
}
示例#15
0
func runGameLoop(window *glfw.Window) {
	for !window.ShouldClose() {
		// update objects
		updateObjects()

		// hit detection
		hitDetection()

		// ---------------------------------------------------------------
		// draw calls
		gl.Clear(gl.COLOR_BUFFER_BIT)

		drawCurrentScore()
		drawHighScore()

		if isGameWon() {
			drawWinningScreen()
		} else if isGameLost() {
			drawGameOverScreen()
		}

		// draw everything 9 times in a 3x3 grid stitched together for seamless clipping
		for x := -1.0; x < 2.0; x++ {
			for y := -1.0; y < 2.0; y++ {
				gl.MatrixMode(gl.MODELVIEW)
				gl.PushMatrix()
				gl.Translated(gameWidth*x, gameHeight*y, 0)

				drawObjects()

				gl.PopMatrix()
			}
		}

		gl.Flush()
		window.SwapBuffers()
		glfw.PollEvents()

		// switch resolution
		if altEnter {
			window.Destroy()

			fullscreen = !fullscreen
			var err error
			window, err = initWindow()
			if err != nil {
				panic(err)
			}

			altEnter = false

			gl.LineWidth(1)
			if fullscreen {
				gl.LineWidth(2)
			}
		}
	}
}
示例#16
0
文件: main.go 项目: GlenKelley/mathgl
func main() {
	if err := glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err.Error())
		return
	}

	defer glfw.Terminate()

	glfw.OpenWindowHint(glfw.FsaaSamples, 4)
	glfw.OpenWindowHint(glfw.OpenGLVersionMajor, 3)
	glfw.OpenWindowHint(glfw.OpenGLVersionMinor, 3)
	glfw.OpenWindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)

	if err := glfw.OpenWindow(1024, 768, 0, 0, 0, 0, 32, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err.Error())
		return
	}

	gl.Init()     // Can't find gl.GLEW_OK or any variation, not sure how to check if this worked
	gl.GetError() // Ignore error

	glfw.SetWindowTitle("Tutorial 02")

	glfw.Enable(glfw.StickyKeys)
	gl.ClearColor(0., 0., 0.4, 0.)

	prog := helper.MakeProgram("SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader")

	vBufferData := [...]float32{
		-1., -1., 0.,
		1., -1., 0.,
		0., 1., 0.}

	vertexArray := gl.GenVertexArray()
	vertexArray.Bind()
	buffer := gl.GenBuffer()
	buffer.Bind(gl.ARRAY_BUFFER)
	gl.BufferData(gl.ARRAY_BUFFER, len(vBufferData)*4, &vBufferData, gl.STATIC_DRAW)

	// Equivalent to a do... while
	for ok := true; ok; ok = (glfw.Key(glfw.KeyEsc) != glfw.KeyPress && glfw.WindowParam(glfw.Opened) == gl.TRUE) {
		gl.Clear(gl.COLOR_BUFFER_BIT)

		prog.Use()

		attribLoc := gl.AttribLocation(0)
		attribLoc.EnableArray()
		buffer.Bind(gl.ARRAY_BUFFER)
		attribLoc.AttribPointer(3, gl.FLOAT, false, 0, nil)

		gl.DrawArrays(gl.TRIANGLES, 0, 3)

		attribLoc.DisableArray()

		glfw.SwapBuffers()
	}

}
示例#17
0
文件: system.go 项目: james4k/exp
func (s *System) Run(ctx *scene.Context) {
	s.init(ctx)
	defer s.finish()
	// TODO: take active camera node
	w := float32(s.Width)
	h := float32(s.Height)
	projM := mathgl.Ortho(0, w, h, 0, -30, 30)
	viewM := mathgl.Translate3D(0, 0, 0)
	worldM := mathgl.Translate3D(0, 0, 0)
	var rect struct {
		WVP     mathgl.Mat4f   `uniform:"WorldViewProjectionM"`
		Diffuse *gfx.Sampler2D `uniform:"Diffuse"`
		geomobj gfx.Geometry
		geom    gfx.GeometryLayout
	}
	rect.WVP = projM.Mul4(viewM).Mul4(worldM)
	s.cmds <- func() {
		quadbuffer := geometry.NewBuilder(s.shader.VertexFormat())
		quadbuffer.Clear()
		quadbuffer.P(0, 0, 0).UV(-1, -1).Cf(1, 1, 1, 1)
		quadbuffer.P(w/3, 0, 0).UV(-1, -1)
		quadbuffer.P(w/3, h/3, 0).UV(-1, -1)
		quadbuffer.P(0, h/3, 0).UV(-1, -1)
		quadbuffer.Indices(0, 1, 2, 2, 0, 3)
		rect.geomobj.Alloc(gfx.StaticDraw)
		err := rect.geomobj.CopyFrom(quadbuffer)
		if err != nil {
			panic(err)
		}
		s.shader.Use()
		rect.geom.Layout(&s.shader, &rect.geomobj)
		/*
			err = rect.geomobj.CopyFrom(quadbuffer)
			if err != nil {
				panic(err)
			}
		*/
		whiteImg := image.NewNRGBA(image.Rect(0, 0, 1, 1))
		whiteImg.Set(0, 0, color.White)
		white, err := gfx.Image(whiteImg)
		if err != nil {
			panic(err)
		}
		rect.Diffuse = white
	}

	for ctx.Step() {
		s.cmds <- func() {
			gl.Viewport(0, 0, s.Width, s.Height)
			gl.ClearColor(0, 0, 0, 1.0)
			gl.ClearDepth(1)
			gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		}
		s.meshes.update(s.cmds, &s.shader)
		s.draw()
		s.sync()
	}
}
示例#18
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) // 赋一个新蓝色分量
		}
	}
}
示例#19
0
文件: emu.go 项目: jteeuwen/dcpu
// Render renders the OpenGL backend.
func (e *Emu) Render() {
	for glfw.WindowParam(glfw.Opened) != 0 {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		gl.LoadIdentity()

		e.disp.Render()

		glfw.SwapBuffers()
	}
}
示例#20
0
// TODO Dynamically fetch size and render accordingly.
func onResize(w, h int) {
	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), float64(h), 0, -1, 1)
	gl.ClearColor(0.255, 0.255, 0.255, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	// log.Printf("resized: %dx%d\n", w, h)
}
示例#21
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()
	}
}
示例#22
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)
}
示例#23
0
文件: gosgl.go 项目: rdterner/gosgl
func (p *Path) draw(canv *Canvas, alphaBuffer *glh.Framebuffer, clrStencil bool) {
	gGl.QuadraticDrawConfig.SetExcludeTransluFrags(false)
	glh.With(alphaBuffer, func() {
		gl.ClearColor(0, 0, 0, 0)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		p.glDraw(canv)
	})
	if clrStencil {
		gl.StencilMask(0x3)
		gl.ClearStencil(0x0)
		gl.Clear(gl.STENCIL_BUFFER_BIT)
	}
	gl.ColorMask(false, false, false, false)
	gl.StencilMask(0x3)
	gl.StencilFunc(gl.ALWAYS, 0, 0xff)
	gl.StencilOp(gl.KEEP, gl.KEEP, gl.INVERT)
	p.glDraw(canv)
	gl.StencilMask(0x1)
	gGl.QuadraticDrawConfig.SetExcludeTransluFrags(true)
	p.glDraw(canv)
}
示例#24
0
func DrawRTri(Red float64) {
	gl.ClearColor(0.2, 0.2, 0.2, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.Color3d(game.Red, 0, 0)
	gl.Begin(gl.TRIANGLES)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(0, 1, 0)
	gl.Vertex3d(1, 1, 0)
	gl.Vertex3d(1, 0, 0)
	gl.End()
}
示例#25
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. */
}
示例#26
0
func (r *Renderer) Render() {
	gl.Clear(gl.COLOR_BUFFER_BIT)

	r.prog.Use()

	r.vao.Bind()
	r.vbo.Bind(gl.ARRAY_BUFFER)

	gl.DrawArrays(gl.POINTS, 0, len(r.vertices))

	// FIXME: unbind vao/vbo/prog?
}
func (self *OpenGLRenderer) BeginRender() {
	gl.ClearColor(0, 0, 0, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	//	gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE)
	//
	//	gl.Enable(gl.CULL_FACE)
	//	gl.CullFace(gl.BACK)
	//
	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)
}
示例#28
0
文件: main.go 项目: jayschwa/examples
func onResize(w, h int) {
	// Write to both buffers, prevent flickering
	gl.DrawBuffer(gl.FRONT_AND_BACK)

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Viewport(0, 0, w, h)
	gl.Ortho(0, float64(w), float64(h), 0, -1.0, 1.0)
	gl.ClearColor(1, 1, 1, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
示例#29
0
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()
}
示例#30
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()
	}
}