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() }
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) }
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 // 减少四边形的旋转变量 }
func renderCorner(color ColorDef, ww, hh, start float64, radius, lineWidth float32) { setColor(color) max := BlockCornerSegments * (start + 1) // Render the corner gl.Begin(gl.TRIANGLE_FAN) gl.Vertex2d(ww, hh) for i := start * BlockCornerSegments; i <= max; i++ { a := math.Pi / 2 * i / BlockCornerSegments x := math.Cos(a) * float64(radius) y := math.Sin(a) * float64(radius) gl.Vertex2d(ww+x, hh+y) } gl.End() if lineWidth != 0 { // Render the shape gl.LineWidth(lineWidth) gl.Color3i(0, 0, 0) gl.Begin(gl.LINE_STRIP) for i := start * BlockCornerSegments; i <= max; i++ { a := math.Pi / 2 * i / BlockCornerSegments x := math.Cos(a) * float64(radius) y := math.Sin(a) * float64(radius) gl.Vertex2d(ww+x, hh+y) } gl.End() } }
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() ///必须交换显示区才能展现 }
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) // 赋一个新蓝色分量 } } }
func drawHex(x, y, kind int, alpha float32) { if kind == 6 { gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.REPLACE) starTex.Bind(gl.TEXTURE_2D) gl.Begin(gl.QUADS) gl.TexCoord2f(0, 0) gl.Vertex2i(x, y) gl.TexCoord2f(0, 1) gl.Vertex2i(x, y+HEX_HEIGHT) gl.TexCoord2f(1, 1) gl.Vertex2i(x+HEX_WIDTH, y+HEX_HEIGHT) gl.TexCoord2f(1, 0) gl.Vertex2i(x+HEX_WIDTH, y) gl.End() } else { gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) var r, g, b float32 switch kind { case 0: r = 1 case 1: g = 1 case 2: b = 1 case 3: r = 1 g = 1 case 4: r = 1 b = 1 case 5: g = 1 - 222/255 b = 1 } hexTex.Bind(gl.TEXTURE_2D) gl.Begin(gl.QUADS) if alpha < 1 { gl.Color4f(r, g, b, alpha) } else { gl.Color3f(r, g, b) } gl.TexCoord2f(0, 0) gl.Vertex2i(x, y) gl.TexCoord2f(0, 1) gl.Vertex2i(x, y+HEX_HEIGHT) gl.TexCoord2f(1, 1) gl.Vertex2i(x+HEX_WIDTH, y+HEX_HEIGHT) gl.TexCoord2f(1, 0) gl.Vertex2i(x+HEX_WIDTH, y) gl.End() } }
func (sg *OpenGLGraphics) Rect(x, y, w, h int, style chart.Style) { // log.Panicf("Unimplemented: %s", whoami()) x, y, w, h = chart.SanitizeRect(x, y, w, h, style.LineWidth) defer glh.OpenGLSentinel()() // glh.With(glh.Attrib{gl.ENABLE_BIT | gl.COLOR_BUFFER_BIT}, func() { glh.ColorC(style.FillColor) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Begin(gl.QUADS) glh.Squarei(x, y, w, h) gl.End() }) if style.LineWidth != 0 { gl.LineWidth(float32(style.LineWidth)) //log.Print("Linewidth: ", float32(style.LineWidth)) glh.With(glh.Attrib{gl.ENABLE_BIT | gl.COLOR_BUFFER_BIT}, func() { glh.ColorC(style.LineColor) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Begin(gl.LINE_LOOP) glh.Squarei(x, y, w, h) gl.End() }) } // linecol := style.LineColor // if linecol != "" { // s = fmt.Sprintf("stroke:%s; ", linecol) // } else { // linecol = "#808080" // } // s += fmt.Sprintf("stroke-width: %d; ", style.LineWidth) // s += fmt.Sprintf("opacity: %.2f; ", 1-style.Alpha) // if style.FillColor != "" { // s += fmt.Sprintf("fill: %s; fill-opacity: %.2f", style.FillColor, 1-style.Alpha) // } else { // s += "fill-opacity: 0" // } // sg.svg.Rect(x, y, w, h, s) // GenericRect(sg, x, y, w, h, style) // TODO }
//Draws all the sprites in the supplied slice func (sheet SpriteSheet) Draw(sprites []*Sprite) { gl.Enable(gl.TEXTURE_2D) sheet.texture.Bind(gl.TEXTURE_2D) for _, sprite := range sprites { gl.Begin(gl.TRIANGLE_STRIP) { gl.TexCoord2f(sprite.left, sprite.bottom) gl.Vertex2f(sprite.X, sprite.Y) gl.TexCoord2f(sprite.left, sprite.top) gl.Vertex2f(sprite.X, sprite.Y+sprite.H) gl.TexCoord2f(sprite.right, sprite.bottom) gl.Vertex2f(sprite.X+sprite.W, sprite.Y) gl.TexCoord2f(sprite.right, sprite.top) gl.Vertex2f(sprite.X+sprite.W, sprite.Y+sprite.H) } gl.End() } sheet.texture.Unbind(gl.TEXTURE_2D) gl.Disable(gl.TEXTURE_2D) }
func (pen *Pen) lineTo(x, y int) { gl.Enable(gl.BLEND) gl.Enable(gl.POINT_SMOOTH) gl.Enable(gl.LINE_SMOOTH) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Color4f(0.0, 0.0, 0.0, 0.1) gl.Begin(gl.LINES) var p [2]int for i := range pen.points { p = pen.points[i] if p[0] == 0 && p[1] == 0 { continue } if distanceTo(x, y, p[0], p[1]) < 10.0 { gl.Vertex2i(x, y) gl.Vertex2i(p[0], p[1]) } } gl.End() pen.n = (pen.n + 1) % len(pen.points) pen.points[pen.n][0] = x pen.points[pen.n][1] = y pen.moveTo(x, y) }
// 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() } }
func (cube *Cube) Render() { x, y, z := cube.Position.X, cube.Position.Y, cube.Position.Z gl.Begin(gl.QUADS) gl.Color3d(0.5-(x/50), 0.5-(y/50), 0.5-(z/50)) // Front Side gl.TexCoord2f(0, 0) gl.Vertex3d(x-0.5, y-0.5, z+0.5) gl.TexCoord2f(1, 0) gl.Vertex3d(x+0.5, y-0.5, z+0.5) gl.TexCoord2f(1, 1) gl.Vertex3d(x+0.5, y+0.5, z+0.5) gl.TexCoord2f(0, 1) gl.Vertex3d(x-0.5, y+0.5, z+0.5) // Left Side gl.Color3d(0.5-(x/20), 0.5-(y/20), 0.5-(z/20)) gl.TexCoord2f(0, 0) gl.Vertex3d(x-0.5, y-0.5, z-0.5) gl.TexCoord2f(1, 0) gl.Vertex3d(x-0.5, y-0.5, z+0.5) gl.TexCoord2f(1, 1) gl.Vertex3d(x-0.5, y+0.5, z+0.5) gl.TexCoord2f(0, 1) gl.Vertex3d(x-0.5, y+0.5, z-0.5) gl.End() }
// drawCircle draws a circle for the specified radius, rotation angle, and the specified number of sides func drawCircle(radius float64, sides int) { gl.Begin(gl.LINE_LOOP) for a := 0.0; a < 2*math.Pi; a += (2 * math.Pi / float64(sides)) { gl.Vertex2d(math.Sin(a)*radius, math.Cos(a)*radius) } gl.Vertex3f(0, 0, 0) gl.End() }
func drawPaddle(x float32, y float32) { gl.PushMatrix() gl.Translatef(float32(x), float32(y), 0) gl.Color3f(1.0, 1.0, 1.0) gl.Begin(gl.LINE_STRIP) gl.Vertex2f(0, -5) gl.Vertex2f(0, 5) gl.End() gl.PopMatrix() }
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() }
func drawQuad(srcwidth, destwidth, srcheight, destheight float32) { gl.Begin(gl.QUADS) gl.TexCoord2i(0, 0) gl.Vertex2f(-1, -1) gl.TexCoord2i(int(srcwidth), 0) gl.Vertex2f(-1+destwidth, -1) gl.TexCoord2i(int(srcwidth), int(srcheight)) gl.Vertex2f(-1+destwidth, -1+destheight) gl.TexCoord2i(0, int(srcheight)) gl.Vertex2f(-1, -1+destheight) gl.End() }
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() }
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. */ }
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.Begin(gl.TRIANGLES) // 绘制三角形 gl.Vertex3f(0.0, 1.0, 0.0) // 上顶点 gl.Vertex3f(-1.0, -1.0, 0.0) // 左下 gl.Vertex3f(1.0, -1.0, 0.0) // 右下 gl.End() // 三角形绘制结束 gl.Translatef(3.0, 0.0, 0.0) // 右移3单位 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() }
func DrawEntity(en Entity) { x := en.Xpos y := en.Ypos r := en.Rot s := en.Size col := en.Colour switch col { case "grey": gl.Color3d(0.5, 0.5, 0.5) case "red": gl.Color3d(1, 0, 0) case "green": gl.Color3d(0, 1, 0) case "blue": gl.Color3d(0, 0, 1) case "lblue": gl.Color3d(0.3, 0.3, 1) case "orange": gl.Color3d(1, 0.5, 0) case "yellow": gl.Color3d(1, 1, 0) case "purple": gl.Color3d(1, 0, 1) case "white": gl.Color3d(1, 1, 1) default: gl.Color3d(1, 1, 1) } gl.PushMatrix() gl.Translated(x, y, 0) gl.Scaled(s, s, s) //gl.Rotated(r*180/math.Pi, 0, 0, 1) gl.Rotated(r, 0, 0, 1) enx := [3]float64{-0.7, 0.7, 0} eny := [3]float64{1, 1, -1} //in OpenGL 3.2, the vertices below would be stored on the GPU //so all you would need to do is say DrawShape(A) or something gl.Begin(gl.TRIANGLES) gl.Vertex3d(enx[0], eny[0], 0) gl.Vertex3d(enx[1], eny[1], 0) gl.Vertex3d(enx[2], eny[2], 0) gl.End() gl.PopMatrix() }
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() }
func (t *Texture) PreloadRender() { t.Bind() gl.Begin(gl.QUADS) gl.TexCoord2f(0, 1) gl.Vertex3f(0, 0, 1) gl.TexCoord2f(1, 1) gl.Vertex3f(0, 0, 1) gl.TexCoord2f(1, 0) gl.Vertex3f(0, 0, 1) gl.TexCoord2f(0, 0) gl.Vertex3f(0, 0, 1) gl.End() }
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() } }
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() ///必须交换显示区才能展现 }
func (t *Texture) Render() { t.Bind() xratio := float32(t.width) / float32(t.height) gl.Begin(gl.QUADS) gl.TexCoord2f(0, 1) gl.Vertex3f(-0.5, -0.5, 1) gl.TexCoord2f(1, 1) gl.Vertex3f((xratio)-0.5, -0.5, 1) gl.TexCoord2f(1, 0) gl.Vertex3f((xratio)-0.5, 0.5, 1) gl.TexCoord2f(0, 0) gl.Vertex3f(-0.5, 0.5, 1) gl.End() }
func paintSprite(minx int, miny int, maxx int, maxy int, t *system.Texture, index int) { gl.MatrixMode(gl.TEXTURE) gl.Begin(gl.QUADS) gl.TexCoord2d(t.MinX(index), t.MinY(index)) gl.Vertex2i(minx, miny) gl.TexCoord2d(t.MaxX(index), t.MinY(index)) gl.Vertex2i(maxx, miny) gl.TexCoord2d(t.MaxX(index), t.MaxY(index)) gl.Vertex2i(maxx, maxy) gl.TexCoord2d(t.MinX(index), t.MaxY(index)) gl.Vertex2i(minx, maxy) gl.End() gl.MatrixMode(gl.MODELVIEW) }
func (explosion *Explosion) Draw() { if explosion.IsAlive() { for l, _ := range explosion.Lines { gl.Begin(gl.LINES) for v, _ := range explosion.Lines[l].Shape.Vectors { gl.Color3d(explosion.Lines[l].Shape.Colors[v].R, explosion.Lines[l].Shape.Colors[v].G, explosion.Lines[l].Shape.Colors[v].B) explosion.Lines[l].GlVertex2d(explosion.Lines[l].Shape.Vectors[v]) } gl.End() } } }
func RenderAtlas(a Atlas) { a.Bind() xratio := float32(a.Width()) / float32(a.Height()) gl.Begin(gl.QUADS) gl.TexCoord2f(0, 1) gl.Vertex3f(-0.5, -0.5, 1) gl.TexCoord2f(1, 1) gl.Vertex3f((xratio)-0.5, -0.5, 1) gl.TexCoord2f(1, 0) gl.Vertex3f((xratio)-0.5, 0.5, 1) gl.TexCoord2f(0, 0) gl.Vertex3f(-0.5, 0.5, 1) gl.End() }
func DrawSizeableTri(Tr SizeableTri) { ax := Tr.Ax bx := Tr.Bx cx := Tr.Cx ay := Tr.Ay by := Tr.By cy := Tr.Cy col := Tr.Colour switch col { case "grey": gl.Color3d(0.5, 0.5, 0.5) case "red": gl.Color3d(1, 0, 0) case "green": gl.Color3d(0, 1, 0) case "blue": gl.Color3d(0, 0, 1) case "lblue": gl.Color3d(0.3, 0.3, 1) case "orange": gl.Color3d(1, 0.5, 0) case "yellow": gl.Color3d(1, 1, 0) case "purple": gl.Color3d(1, 0, 1) default: gl.Color3d(1, 1, 1) } gl.PushMatrix() // gl.Translated(x, y, 0) // gl.Scaled(s, s, s) // gl.Rotated(r, 0, 0, 1) gl.Begin(gl.TRIANGLES) gl.Vertex3d(ax, ay, 0) gl.Vertex3d(bx, by, 0) gl.Vertex3d(cx, cy, 0) gl.End() gl.PopMatrix() }
func (s *Display) drawFrame(screenData *types.Screen) { gl.Clear(gl.COLOR_BUFFER_BIT) gl.Disable(gl.DEPTH_TEST) gl.PointSize(float32(s.ScreenSizeMultiplier) + 1.0) gl.Begin(gl.POINTS) for y := 0; y < SCREEN_HEIGHT; y++ { for x := 0; x < SCREEN_WIDTH; x++ { var pixel types.RGB = screenData[y][x] gl.Color3ub(pixel.Red, pixel.Green, pixel.Blue) gl.Vertex2i(x*s.ScreenSizeMultiplier, y*s.ScreenSizeMultiplier) } } gl.End() glfw.SwapBuffers() }