示例#1
0
文件: main.go 项目: sycoso/glfw
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
func initScreen() {
	sdl.Init(sdl.INIT_VIDEO)
	const (
		resx int = 640
		resy int = 480
	)
	var (
		screen = sdl.SetVideoMode(resx, resy, 16, sdl.OPENGL)
	)

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

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

	gl.MatrixMode(gl.PROJECTION)
	//gl.MatrixMode(gl.MODELVIEW)

	gl.Viewport(0, 0, int(screen.W), int(screen.H))
	gl.LoadIdentity()
	gl.Ortho(0, float64(screen.W), float64(screen.H), 0, -1.0, 1.0)
	//gl.DepthRange(-1, 1)

	gl.ClearColor(0, 0, 0, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
}
示例#3
0
文件: window.go 项目: glenn-brown/vu
// Render draws the contents of the window, but no more than 30
// times per second.
func (w *Window) Render() {
	// Don't render more than 30 times per second.
	t := time.Now()
	if time.Since(w.lastRender).Seconds() < 1.0/30.0 {
		return
	}
	w.lastRender = t

	// Retrieve the view width and height, in pixels.
	params := make([]int32, 4)
	gl.GetIntegerv(gl.VIEWPORT, params)

	// Infer the rendering volume from the viewport size, so the
	// the rendering code can assume that the width of a pixel is
	// ~1.0.  This is important when rendering text.  This must
	// match the gl.Frustum configuration.
	width := float64(params[2])
	height := float64(params[3])
	depth := (width + height) / 2

	// Redraw the window, but not too often.
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	w.renderer.Render(width, height, depth)
	glfw.SwapBuffers()

	// Exit if the user presses escape or the window was closed.
	if glfw.Key(glfw.KeyEsc) != 0 || glfw.WindowParam(glfw.Opened) == 0 {
		os.Exit(0)
	}
}
示例#4
0
func Draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT)

	gl.PushMatrix()
	defer gl.PopMatrix()

	gl.Color4f(0, 1, 0, .5)
	DrawCircle(vect.Vect{ScreenSize.X / 2, ScreenSize.Y / 2}, ScreenSize.Y/2.0-5.0, false)

	if Settings.Paused {
		gl.Color3f(1, 1, 1)
		RenderFontAt("Paused", 20, 30)
	}

	//draw collision objects

	gl.PushMatrix()

	gl.Translated(ScreenSize.X/2, ScreenSize.Y/2, 0)
	gl.Scaled(Settings.Scale, Settings.Scale, 1)

	DrawDebugData(space)

	gl.PopMatrix()
}
示例#5
0
文件: fontdemo.go 项目: tmc/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()
}
示例#6
0
func main() {
	glfw.Init()
	defer glfw.Terminate()

	glfw.OpenWindow(640, 480, 8, 8, 8, 8, 0, 0, glfw.Windowed)
	defer glfw.CloseWindow()

	glfw.SetWindowTitle("Tile test")
	glfw.Enable(glfw.StickyKeys)
	glfw.SetSwapInterval(1)
	glfw.SetKeyCallback(inputCallback)

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, GridWidth, GridHeight, 0, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.Disable(gl.DEPTH_TEST)
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	initResources()
	initWorld()

	for Running {
		if (time.Since(DT).Nanoseconds() / 1000000) > 15 { //don't loop faster than every 15ms
			DT = time.Now()
			gl.Clear(gl.COLOR_BUFFER_BIT)
			player.update()
			renderScene()
			glfw.SwapBuffers()
		}
	}
}
示例#7
0
文件: main.go 项目: sycoso/glfw
func onKey(key, state int) {
	switch key {
	case glfw.KeyEsc:
		running = state == 0
	case 67: // 'c'
		gl.Clear(gl.COLOR_BUFFER_BIT)
	}
}
示例#8
0
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Color3f(1, 1, 1)
	drawShapes(space)

	glfw.SwapBuffers()
}
示例#9
0
文件: main.go 项目: sycoso/glfw
func onResize(w, h int) {
	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()
}
示例#10
0
func display() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	positionCamera()

	gl.Begin(gl.QUADS)
	drawTerrain()
	gl.End()

	gl.Flush()
}
示例#11
0
文件: main.go 项目: sycoso/glfw
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %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 {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.CloseWindow()

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

	if samples := glfw.WindowParam(glfw.FsaaSamples); samples != 0 {
		fmt.Fprintf(os.Stdout, "Context reports FSAA is supported with %d samples\n", samples)
	} else {
		fmt.Fprintf(os.Stdout, "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()
	}
}
示例#12
0
文件: simple.go 项目: tmc/glut
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. */
}
示例#13
0
文件: draw.go 项目: nkostelnik/gl
func main() {

	sdl.Init(sdl.INIT_VIDEO)

	var screen = sdl.SetVideoMode(640, 480, 32, sdl.OPENGL)

	if screen == nil {
		panic("sdl error")
	}

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

	pen := Pen{}

	gl.MatrixMode(gl.PROJECTION)

	gl.Viewport(0, 0, int(screen.W), int(screen.H))
	gl.LoadIdentity()
	gl.Ortho(0, float64(screen.W), float64(screen.H), 0, -1.0, 1.0)

	gl.ClearColor(1, 1, 1, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	var running = true

	for running {

		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch ev := e.(type) {
			case *sdl.QuitEvent:
				running = false
			case *sdl.KeyboardEvent:
				if ev.Keysym.Sym == sdl.K_ESCAPE {
					running = false
				}
			case *sdl.MouseMotionEvent:
				if ev.State != 0 {
					pen.lineTo(Point{int(ev.X), int(ev.Y)})
				} else {
					pen.moveTo(Point{int(ev.X), int(ev.Y)})
				}
			}
		}

		sdl.GL_SwapBuffers()
		sdl.Delay(25)
	}

	sdl.Quit()

}
示例#14
0
文件: gltoy.go 项目: shogg/gltoy
func draw() {

	t := float32(sdl.GetTicks()) / 500.0
	time := prg.GetUniformLocation("time")
	time.Uniform1f(t)

	gl.Clear(gl.COLOR_BUFFER_BIT)

	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)
	if gl.GetError() != gl.NO_ERROR {
		panic("draw error")
	}
}
示例#15
0
文件: render.go 项目: esnowkropla/dep
func general_render(s *list.List, c *camera) {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.PushMatrix()
	//gl.Translatef(float32(c.X), float32(c.Y), float32(c.Z))
	glu.LookAt(c.pos.X, c.pos.Y, c.pos.Z, c.front.X, c.front.Y, c.front.Z, c.top.X, c.top.Y, c.top.Z)

	for e := s.Front(); e != nil; e = e.Next() {
		gl.PushMatrix()
		v := e.Value.(*sprite)
		v.render()
		gl.PopMatrix()
	}
	gl.PopMatrix()
}
示例#16
0
文件: draw.go 项目: simonz05/draw
func loop() {
	e := initTriangleShaders()

	if e != nil {
		log.Fatalln(e.Error())
	}

	for esc {
		gl.ClearColor(0.0, 0.0, 0.0, 0.0)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		drawTriangle()
		glfw.SwapBuffers()
		timeSince()
	}
}
示例#17
0
// Here goes our drawing code
func drawGLScene() {
	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// Move left 1.5 units and into the screen 6.0 units.
	gl.LoadIdentity()
	gl.Translatef(-1.5, 0.0, -6.0)
	gl.Rotatef(float32(rtri), 0.0, 1.0, 0.0) // Rotate the triangle on the Y axis

	gl.Begin(gl.TRIANGLES)       // Draw triangles
	gl.Color3f(1.0, 0.0, 0.0)    // Set The Color To Red
	gl.Vertex3f(0.0, 1.0, 0.0)   // top
	gl.Color3f(0.0, 1.0, 0.0)    // Set The Color To Red
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.Color3f(0.0, 0.0, 1.0)    // Set The Color To Red
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.End()                     // finish drawing the triangle

	// Move right 3 units
	gl.LoadIdentity()
	gl.Translatef(1.5, 0.0, -6.0)
	gl.Color3f(0.5, 0.5, 1.0)                 // Set The Color To Blue One Time Only
	gl.Rotatef(float32(rquad), 1.0, 0.0, 0.0) // rotate the quad on the X axis

	gl.Begin(gl.QUADS)           // draw quads
	gl.Vertex3f(-1.0, 1.0, 0.0)  // top left
	gl.Vertex3f(1.0, 1.0, 0.0)   // top right
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.End()                     // done drawing the quad

	// Draw to the screen
	sdl.GL_SwapBuffers()

	rtri += 0.2   // Increase The Rotation Variable For The Triangle
	rquad -= 0.15 // Decrease The Rotation Variable For The Quad

	// Gather our frames per second
	frames++
	t := sdl.GetTicks()
	if t-t0 >= 5000 {
		seconds := (t - t0) / 1000.0
		fps := frames / seconds
		fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
		t0 = t
		frames = 0
	}
}
示例#18
0
// Render stuff
func Draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.LoadIdentity()

	gl.Translatef(-1.5, 0, -6)
	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()

	glfw.SwapBuffers()
}
示例#19
0
文件: main.go 项目: andrebq/wfobj
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.LoadIdentity()

	gl.Translatef(0, 0, -20+globalState.MousePos.Z*globalState.speed)

	gl.Rotatef(globalState.Rot.X, 1, 0, 0)
	gl.Rotatef(globalState.Rot.Y, 0, 1, 0)
	gl.Rotatef(globalState.Rot.Z, 0, 0, 1)

	if globalState.speed != 1 {
		gl.Scalef(globalState.speed, globalState.speed, globalState.speed)
	}

	gl.RenderMode(gl.RENDER)

	gl.Begin(gl.QUADS)
	for i, _ := range mesh.Faces {
		if colors, ok := faceColor[i]; ok {
			gl.Color3f(colors[0], colors[1], colors[2])
		} else {
			faceColor[i] = make([]float32, 3)
			faceColor[i][0] = rand.Float32()
			faceColor[i][1] = rand.Float32()
			faceColor[i][2] = rand.Float32()
			gl.Color3f(faceColor[i][0], faceColor[i][1], faceColor[i][2])
		}

		face := &mesh.Faces[i]
		for j, _ := range face.Vertices {
			var v *wfobj.Vertex
			if len(face.Normals) > 0 {
				v = &face.Normals[j]
				gl.Normal3f(v.X, v.Y, v.Z)
			}
			v = &face.Vertices[j]
			gl.Vertex3f(v.X, v.Y, v.Z)
		}
	}
	gl.End()
	gl.Finish()
	gl.Flush()

	sdl.GL_SwapBuffers()
}
示例#20
0
// Here goes our drawing code
func drawGLScene(sector Sector) {
	xtrans := gl.GLfloat(-xpos)
	ztrans := gl.GLfloat(-zpos)
	ytrans := gl.GLfloat(-walkbias - 0.25)
	scenroty := gl.GLfloat(360.0 - yrot)

	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// reset the view
	gl.LoadIdentity()

	// Rotate up and down to look up and down
	gl.Rotatef(float32(lookupdown), 1.0, 0.0, 0.0)
	// Rotate depending on direction player is facing
	gl.Rotatef(float32(scenroty), 0.0, 1.0, 0.0)
	// translate the scene based on player position
	gl.Translatef(float32(xtrans), float32(ytrans), float32(ztrans))

	gl.BindTexture(gl.TEXTURE_2D, uint(textures[filter]))

	for _, vertices := range sector {
		gl.Begin(gl.TRIANGLES)
		for _, triangle := range *vertices {
			gl.Normal3f(0.0, 0.0, 1.0)
			gl.TexCoord2f(float32(triangle.u), float32(triangle.v))
			gl.Vertex3f(float32(triangle.x), float32(triangle.y), float32(triangle.z))
		}
		gl.End()
	}

	// Draw to the screen
	sdl.GL_SwapBuffers()

	// Gather our frames per second
	frames++
	t := sdl.GetTicks()
	if t-t0 >= 5000 {
		seconds := (t - t0) / 1000.0
		fps := frames / seconds
		fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
		t0 = t
		frames = 0
	}
}
示例#21
0
func InitUI() *UI {
	ui := &UI{
		running: false,
	}

	if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
		panic(sdl.GetError())
	}

	if ttf.Init() != 0 {
		panic(sdl.GetError())
	}

	ui.screen = sdl.SetVideoMode(300, 300, 32, sdl.OPENGL)

	if ui.screen == nil {
		panic("sdl error")
	}

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

	gl.MatrixMode(gl.PROJECTION)

	gl.Viewport(0, 0, int(ui.screen.W), int(ui.screen.H))
	gl.LoadIdentity()
	gl.Ortho(0, float64(ui.screen.W), float64(ui.screen.H), 0, -1.0, 1.0)

	gl.ClearColor(1, 1, 1, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	// TTF
	sdl.EnableUNICODE(1)
	ui.font = ttf.OpenFont("FontinSans.otf", 20)
	ui.font.SetStyle(ttf.STYLE_UNDERLINE)
	if ui.font == nil {
		panic(sdl.GetError())
	}

	ui.running = true

	return ui
}
示例#22
0
func (v *Video) Render() {
	for running {
		select {
		case dimensions := <-v.resize:
			v.ResizeEvent(dimensions[0], dimensions[1])
		case val := <-v.tick:
			slice := make([]uint8, len(val)*3)
			for i := 0; i < len(val); i = i + 1 {
				slice[i*3+0] = (uint8)((val[i] >> 16) & 0xff)
				slice[i*3+1] = (uint8)((val[i] >> 8) & 0xff)
				slice[i*3+2] = (uint8)((val[i]) & 0xff)
			}

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

			v.tex.Bind(gl.TEXTURE_2D)

			if ppu.OverscanEnabled {
				gl.TexImage2D(gl.TEXTURE_2D, 0, 3, 240, 224, 0, gl.RGB, gl.UNSIGNED_BYTE, slice)
			} else {
				gl.TexImage2D(gl.TEXTURE_2D, 0, 3, 256, 240, 0, gl.RGB, gl.UNSIGNED_BYTE, slice)
			}

			gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
			gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

			gl.Begin(gl.QUADS)
			gl.TexCoord2f(0.0, 1.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(1.0, 0.0)
			gl.Vertex3f(1.0, 1.0, 0.0)
			gl.TexCoord2f(0.0, 0.0)
			gl.Vertex3f(-1.0, 1.0, 0.0)
			gl.End()

			if v.screen != nil {
				sdl.GL_SwapBuffers()
				v.fpsmanager.FramerateDelay()
			}
		}
	}
}
示例#23
0
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()

	glfw.SwapBuffers()

	Frames++
	{
		t := glfw.Time()
		if t-T0 >= 5 {
			seconds := (t - T0)
			fps := float64(Frames) / seconds
			print(Frames, " frames in ", int(seconds), " seconds = ", int(fps), " FPS\n")
			T0 = t
			Frames = 0
		}
	}
}
示例#24
0
文件: sdlgears.go 项目: nkostelnik/gl
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()

	sdl.GL_SwapBuffers()

	Frames++
	{
		t := sdl.GetTicks()
		if t-T0 >= 5000 {
			seconds := (t - T0) / 1000.0
			fps := Frames / seconds
			print(Frames, " frames in ", seconds, " seconds = ", fps, " FPS\n")
			T0 = t
			Frames = 0
		}
	}
}
示例#25
0
// Here goes our drawing code
func drawGLScene() {
	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// reset the view
	gl.LoadIdentity()

	// Draw to the screen
	sdl.GL_SwapBuffers()

	// Gather our frames per second
	frames++
	t := sdl.GetTicks()
	if t-t0 >= 5000 {
		seconds := (t - t0) / 1000.0
		fps := frames / seconds
		fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
		t0 = t
		frames = 0
	}
}
示例#26
0
文件: main.go 项目: andrebq/wfobj
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.LoadIdentity()
	gl.Translatef(1.5, 0, -6)
	gl.Rotatef(quadAngle, 1, 1, 1)

	gl.Begin(gl.QUADS)
	for i, _ := range mesh.Faces {
		gl.Color3f(rand.Float32(), rand.Float32(), rand.Float32())
		face := &mesh.Faces[i]
		for j, _ := range face.Vertices {
			v := &face.Vertices[j]
			gl.Vertex3f(v.X, v.Y, v.Z)
		}
	}
	gl.End()

	quadAngle -= 0.15

	glfw.SwapBuffers()
}
示例#27
0
文件: ca.go 项目: samnardoni/ca
func draw() {
	for y := 0; y < Size; y++ {
		for x := 0; x < Size; x++ {

			var color uint8
			if grid.Front()[y][x] {
				color = 0x00
			} else {
				color = 0xFF
			}

			pixels[(y*Size+x)*3+0] = color
			pixels[(y*Size+x)*3+1] = color
			pixels[(y*Size+x)*3+2] = color

		}
	}

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

	gl.TexImage2D(gl.TEXTURE_2D, 0, 3, Size, Size, 0, gl.RGB, gl.UNSIGNED_BYTE, pixels)

	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

	gl.Begin(gl.QUADS)
	gl.TexCoord2f(0.0, 1.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(1.0, 0.0)
	gl.Vertex3f(1.0, 1.0, 0.0)
	gl.TexCoord2f(0.0, 0.0)
	gl.Vertex3f(-1.0, 1.0, 0.0)
	gl.End()

	glfw.SwapBuffers()
}
示例#28
0
// Here goes our drawing code
func drawGLScene() {
	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// Move left 1.5 units and into the screen 6.0 units.
	gl.LoadIdentity()
	gl.Translatef(-1.5, 0.0, -6.0)

	gl.Begin(gl.TRIANGLES)       // Draw triangles
	gl.Vertex3f(0.0, 1.0, 0.0)   // top
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.End()                     // finish drawing the triangle

	// Move right 3 units
	gl.Translatef(3.0, 0.0, 0.0)

	gl.Begin(gl.QUADS)           // draw quads
	gl.Vertex3f(-1.0, 1.0, 0.0)  // top left
	gl.Vertex3f(1.0, 1.0, 0.0)   // top right
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.End()                     // done drawing the quad

	// Draw to the screen
	sdl.GL_SwapBuffers()

	// Gather our frames per second
	frames++
	t := sdl.GetTicks()
	if t-t0 >= 5000 {
		seconds := (t - t0) / 1000.0
		fps := frames / seconds
		fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
		t0 = t
		frames = 0
	}
}
示例#29
0
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// Food
	for coord, _ := range food {
		gl.LoadIdentity()
		gl.Scalef(0.05, 0.05, 1)
		gl.Translatef(float32(coord.x)-5, float32(coord.y)-5, -1)

		gl.Begin(gl.QUADS)
		gl.Color3f(0.5, float32(coord.x)/10, float32(coord.y)/10)
		gl.Vertex3f(0.25, 0.75, 0)
		gl.Vertex3f(0.75, 0.75, 0)
		gl.Color3f(0.3, float32(coord.x)/10-0.2, float32(coord.y)/10-0.2)
		gl.Vertex3f(0.75, 0.25, 0)
		gl.Vertex3f(0.25, 0.25, 0)
		gl.End()
	}

	//Snake
	for _, coord := range snake.coords {
		gl.LoadIdentity()
		gl.Scalef(0.05, 0.05, 1)
		gl.Translatef(float32(coord.x)-5, float32(coord.y)-5, -1)

		gl.Begin(gl.QUADS)
		gl.Color3f(float32(coord.y)/10, float32(coord.x)/10, 0.5)
		gl.Vertex3f(0, 1, 0)
		gl.Vertex3f(1, 1, 0)
		gl.Color3f(float32(coord.y)/10-0.2, float32(coord.x)/10-0.2, 0.3)
		gl.Vertex3f(1, 0, 0)
		gl.Vertex3f(0, 0, 0)
		gl.End()
	}

	glfw.SwapBuffers()
}
示例#30
0
func (v *Video) Render() {
	runtime.LockOSThread()

	for running {
		select {
		case val := <-v.tick:
			slice := make([]uint8, len(val)*3)
			for i := 0; i < len(val); i = i + 1 {
				slice[i*3+0] = (uint8)((val[i] >> 16) & 0xff)
				slice[i*3+1] = (uint8)((val[i] >> 8) & 0xff)
				slice[i*3+2] = (uint8)((val[i]) & 0xff)
			}

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

			v.tex.Bind(gl.TEXTURE_2D)
			gl.TexImage2D(gl.TEXTURE_2D, 0, 3, 256, 240, 0, gl.RGB, gl.UNSIGNED_BYTE, slice)
			gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
			gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

			gl.Begin(gl.QUADS)
			gl.TexCoord2f(0.0, 1.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(1.0, 0.0)
			gl.Vertex3f(1.0, 1.0, 0.0)
			gl.TexCoord2f(0.0, 0.0)
			gl.Vertex3f(-1.0, 1.0, 0.0)
			gl.End()

			glfw.SwapBuffers()
			v.fpsmanager.FramerateDelay()
		}
	}
}