Beispiel #1
0
func (v *Video) Reshape(width int, height int) {
	x_offset := 0
	y_offset := 0

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

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

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

	gl.Viewport(x_offset, y_offset, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(-1, 1, -1, 1, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Disable(gl.DEPTH_TEST)
}
Beispiel #2
0
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()
}
Beispiel #3
0
func initScene() (err error) {
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.DEPTH_TEST)
	gl.Enable(gl.LIGHTING)

	gl.ClearColor(0.5, 0.5, 0.5, 0.0)
	gl.ClearDepth(1)
	gl.DepthFunc(gl.LEQUAL)

	gl.Lightfv(gl.LIGHT0, gl.AMBIENT, ambient)
	gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, diffuse)
	gl.Lightfv(gl.LIGHT0, gl.POSITION, lightpos)
	gl.Enable(gl.LIGHT0)

	gl.Viewport(0, 0, Width, Height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-1, 1, -1, 1, 1.0, 10.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	goph, err := os.Open("../../data/gopher.png")
	if err != nil {
		panic(err)
	}
	defer goph.Close()

	texture, err = createTexture(goph)
	return
}
Beispiel #4
0
Datei: 04.go Projekt: 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 // 减少四边形的旋转变量
}
Beispiel #5
0
func renderSwitch(s *Switch) {
	gl.LoadIdentity()
	// TODO constant
	v := SwitchSize / 2
	x, y := float32(s.X+v), float32(s.Y+v)
	gl.Translatef(x, y, 0)
	// Render the switch
	gl.Color3f(1, 1, 1)
	gl.Begin(gl.TRIANGLE_FAN)
	gl.Vertex2d(0, 0)
	vv := float64(v)
	for i := float64(0); i <= SwitchSegments; i++ {
		a := 2 * math.Pi * i / SwitchSegments
		gl.Vertex2d(math.Sin(a)*vv, math.Cos(a)*vv)
	}
	gl.End()

	if LineWidth != 0 {
		// Render the shape
		gl.Color3i(0, 0, 0)
		gl.LineWidth(LineWidth)
		gl.Begin(gl.LINE_LOOP)
		for i := float64(0); i <= SwitchSegments; i++ {
			a := 2 * math.Pi * i / SwitchSegments
			gl.Vertex2d(math.Sin(a)*vv, math.Cos(a)*vv)
		}
		gl.End()
	}

	// Write the switch name
	gl.LoadIdentity()
	w, h := fonts[6].Metrics(s.name)
	gl.Color3i(0, 0, 0)
	fonts[6].Printf(x-float32(w)/2, y-float32(h)/2+2, s.name)
}
Beispiel #6
0
func main() {
	_ = fmt.Sprint()

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

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

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

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

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

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

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

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

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

	g = NewGame()

	g.Start()
	go eventLoop(g)
	go renderLoop(g)
	Main()
	g.Stop()
}
Beispiel #7
0
Datei: 09.go Projekt: nzlov/gogl
// new window size
func reshape(window *glfw.Window, width, height int) {

	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-1.0, 1.0, -1.0, 1.0, 1, 20)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Beispiel #8
0
Datei: 10.go Projekt: nzlov/gogl
// new window size
func reshape(window *glfw.Window, width, height int) {

	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	glu.Perspective(45.0, float32(width)/float32(height), 0.1, 100.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Beispiel #9
0
func initGL() {
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Viewport(0, 0, 800, 600)
	gl.Ortho(0, 800, 600, 0, -1.0, 1.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.ClearColor(0.1, 0.05, 0.0, 1.0)
}
Beispiel #10
0
// onResize sets up a simple 2d ortho context based on the window size
func onResize(window *glfw.Window, w, h int) {
	w, h = window.GetSize() // query window to get screen pixels
	width, height := window.GetFramebufferSize()
	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), 0, float64(h), -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.ClearColor(1, 1, 1, 1)
}
Beispiel #11
0
func reshape(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.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Beispiel #12
0
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()
	}
}
// 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)
}
Beispiel #14
0
/*
下面的代码的作用是重新设置OpenGL场景的大小,而不管窗口的大小是否已经改变(假定您没有使用全屏模式)。
甚至您无法改变窗口的大小时(例如您在全屏模式下),它至少仍将运行一次--在程序开始时设置我们的透视图。
OpenGL场景的尺寸将被设置成它显示时所在窗口的大小。
*/
func onResize(w, h int) {
	if h == 0 {
		h = 1
	}

	gl.Viewport(0, 0, w, h)                                  ///重置当前的视口
	gl.MatrixMode(gl.PROJECTION)                             ///选择投影矩阵
	gl.LoadIdentity()                                        ///重置投影矩阵
	glu.Perspective(45.0, float64(w)/float64(h), 0.1, 100.0) ///设置视口的大小
	gl.MatrixMode(gl.MODELVIEW)                              ///选择模型观察矩阵
	gl.LoadIdentity()                                        ///重置模型观察矩阵
}
Beispiel #15
0
/* new window size or exposure */
func reshape(width int, height int) {

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

	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-1.0, 1.0, -h, h, 5.0, 60.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(0.0, 0.0, -40.0)
}
Beispiel #16
0
Datei: 08.go Projekt: nzlov/gogl
func onResize(w, h int) {
	if h == 0 {
		h = 1
	}

	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-1.0, 1.0, -1.0, 1.0, 1, 20)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Beispiel #17
0
func onResize(w, h int) {
	if h == 0 {
		h = 1
	}

	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	glu.Perspective(45.0, float64(w)/float64(h), 0.1, 100.0) //设置视窗的大小
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Beispiel #18
0
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()
}
Beispiel #19
0
func (wc WindowCoords) Enter() {
	w, h := GetViewportWH()
	Matrix{gl.PROJECTION}.Enter()
	if !wc.NoReset {
		gl.LoadIdentity()
	}
	if wc.Invert {
		gl.Ortho(0, float64(w), float64(h), 0, -1, 1)
	} else {
		gl.Ortho(0, float64(w), 0, float64(h), -1, 1)
	}
	Matrix{gl.MODELVIEW}.Enter()
	gl.LoadIdentity()
}
Beispiel #20
0
func Reshape(width, height int) {
	gl.Viewport(0, 0, width, height)

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(-1, 1, -1, 1, -1, 1)
	//gl.Ortho(-2.1, 6.1, -2.25*2, 2.1*2, -1, 1) // Y debug

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
}
Beispiel #21
0
func initGL() {
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, 1024, 768, 0, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Enable(gl.DEPTH_TEST)

	// hexTex = initTexture("hex5k", HEX_WIDTH, HEX_HEIGHT)
	hexTex = initTexture2("hex")
	wallpaper = initTexture("dark_wood_@2X", 1024, 768)
	// starTex = initTexture("hexstark", HEX_WIDTH, HEX_HEIGHT)
	starTex = initTexture2("star")
	borderTex = initTexture("hexborder", 76, 76)
}
Beispiel #22
0
Datei: 04.go Projekt: nzlov/gogl
// new window size
func reshape(window *glfw.Window, width, height int) {
	h := float64(height) / float64(width)

	znear := 5.0
	zfar := 30.0
	xmax := znear * 0.5

	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-xmax, xmax, -xmax*h, xmax*h, znear, zfar)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translated(0.0, 0.0, -20.0)
}
Beispiel #23
0
func InitDisplay() {
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, 100, 0, 100, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.PointSize(3.0)
}
Beispiel #24
0
func Reshape(w, h int) {
	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, 100, 0, 100, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
}
Beispiel #25
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() ///必须交换显示区才能展现
}
Beispiel #26
0
// onResize handles window resize events.
func onResize(w, h int) {
	if w < 1 {
		w = 1
	}

	if h < 1 {
		h = 1
	}

	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), float64(h), 0, 0, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Beispiel #27
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()
	}
}
Beispiel #28
0
// onResize handles window resize events.
func onResize(w, h int) {
	if w < 1 {
		w = 1
	}

	if h < 1 {
		h = 1
	}

	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	glu.Perspective(45.0, float64(w)/float64(h), 0.1, 2000.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Beispiel #29
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()
}
Beispiel #30
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()
	}

}