func (w *Window) run(init func(w *Window)) { runtime.LockOSThread() glfw.MakeContextCurrent(w.w) defer glfw.MakeContextCurrent(nil) init(w) // glfw should fire initial resize events to avoid this duplication (https://github.com/glfw/glfw/issues/62) w.resized(w.w.Size()) w.framebufferResized(w.w.FramebufferSize()) gl.Enable(gl.SCISSOR_TEST) gl.Enable(gl.BLEND) gl.Enable(gl.POINT_SMOOTH) gl.Enable(gl.LINE_SMOOTH) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) for !w.close { select { case f := <-w.do: f() case <-w.paint: gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Scissor(0, 0, w.bufWidth, w.bufHeight) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) w.base().paint() w.w.SwapBuffers() } } }
func (w *Window) run() { runtime.LockOSThread() glfw.MakeContextCurrent(w.w) defer glfw.MakeContextCurrent(nil) // glfw should fire initial resize events to avoid this duplication (https://github.com/glfw/glfw/issues/62) width, height := w.w.Size() gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, gl.Double(width), 0, gl.Double(height), -1, 1) Resize(w, Pt(float64(width), float64(height))) width, height = w.w.FramebufferSize() gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height)) gl.Enable(gl.BLEND) gl.Enable(gl.POINT_SMOOTH) gl.Enable(gl.LINE_SMOOTH) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) for !w.close { select { case f := <-w.do: f() case <-w.paint: gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) w.base().paint() w.w.SwapBuffers() } } }
func (r Region) PushClipPlanes() { if len(clippers) == 0 { gl.Enable(gl.CLIP_PLANE0) gl.Enable(gl.CLIP_PLANE1) gl.Enable(gl.CLIP_PLANE2) gl.Enable(gl.CLIP_PLANE3) r.setClipPlanes() clippers = append(clippers, r) } else { cur := clippers[len(clippers)-1] clippers = append(clippers, r.Isect(cur)) clippers[len(clippers)-1].setClipPlanes() } }
func (o *OpenGl) set3dView() { gl.Enable(gl.TEXTURE_2D) gl.Enable(gl.DEPTH_TEST) gl.Enable(gl.LIGHTING) gl.Enable(gl.LIGHT0) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() //gl.Perspective(cam.Zoom(), o.mW / o.mH, cam.Near(), cam.Far()) gl.MatrixMode(gl.MODELVIEW) //e := o.Camera.EYE() //a := o.Camera.AT() //u := o.Camera.UP() //gl.LookAt(e.X, e.Y, e.Z, a.X, a.Y, a.Z, u.X, u.Y, u.Z) }
func (s *Scene) Init() (err error) { runtime.LockOSThread() gl.Enable(gl.TEXTURE_2D) gl.Enable(gl.DEPTH_TEST) gl.ClearColor(0.0, 0.0, 0.0, 0.0) gl.ClearDepth(1) //gl.DepthFunc(gl.LEQUAL) gl.Viewport(0, 0, Width, Height) mm.init() return }
func RenderAdvanced(x, y, dx, dy, rot float64, flip bool) { setupTextureList() if textureList == 0 { return } var run, op mathgl.Mat4 run.Identity() op.Translation(float32(x), float32(y), 0) run.Multiply(&op) op.Translation(float32(dx/2), float32(dy/2), 0) run.Multiply(&op) op.RotationZ(float32(rot)) run.Multiply(&op) if flip { op.Translation(float32(-dx/2), float32(-dy/2), 0) run.Multiply(&op) op.Scaling(float32(dx), float32(dy), 1) run.Multiply(&op) } else { op.Translation(float32(dx/2), float32(-dy/2), 0) run.Multiply(&op) op.Scaling(float32(-dx), float32(dy), 1) run.Multiply(&op) } gl.PushMatrix() gl.MultMatrixf((*gl.Float)(&run[0])) gl.Enable(gl.TEXTURE_2D) gl.CallList(textureList) gl.PopMatrix() }
func (tsm *ThunderSubMenu) Draw(region Region, style StyleStack) { gl.Disable(gl.TEXTURE_2D) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Enable(gl.BLEND) base.EnableShader("marble") offset, ok := style.Get("offset").(linear.Vec2) if ok { base.SetUniformV2("marble", "offset", offset) } else { base.SetUniformV2("marble", "offset", linear.Vec2{}) } gl.Color4ub(255, 255, 255, 255) gl.Begin(gl.QUADS) x := gl.Int(region.X) y := gl.Int(region.Y) dx := gl.Int(region.Dx) dy := gl.Int(region.Dy) gl.Vertex2i(x, y) gl.Vertex2i(x, y+dy) gl.Vertex2i(x+dx, y+dy) gl.Vertex2i(x+dx, y) gl.End() base.EnableShader("") for i, option := range tsm.Options { region.Dy = tsm.requests[option].Dy if i == tsm.selected { style.PushStyle(map[string]interface{}{"selected": true}) } else { style.PushStyle(map[string]interface{}{"selected": false}) } option.Draw(region, style) style.Pop() region.Y += tsm.requests[option].Dy } }
func InitGL(smooth bool, multisample int) { core.Fatal(gl.Init()) gl.Enable(gl.LIGHTING) gl.Enable(gl.CULL_FACE) gl.CullFace(gl.BACK) if multisample != 0 { gl.Enable(gl.MULTISAMPLE) } if smooth { gl.ShadeModel(gl.SMOOTH) } }
func (ms *ManaSource) Draw(local *LocalData, zoom float64, dx float64, dy float64) { if local.nodeTextureData == nil { // gl.Enable(gl.TEXTURE_2D) local.nodeTextureData = make([]byte, ms.options.NumNodeRows*ms.options.NumNodeCols*3) gl.GenTextures(1, &local.nodeTextureId) gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId) gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT) gl.TexImage2D( gl.TEXTURE_2D, 0, gl.RGB, gl.Sizei(ms.options.NumNodeRows), gl.Sizei(ms.options.NumNodeCols), 0, gl.RGB, gl.UNSIGNED_BYTE, gl.Pointer(&local.nodeTextureData[0])) } for i := range ms.rawNodes { for c := 0; c < 3; c++ { color_frac := ms.rawNodes[i].Mana[c] * 1.0 / ms.options.NodeMagnitude color_range := float64(ms.options.MaxNodeBrightness - ms.options.MinNodeBrightness) local.nodeTextureData[i*3+c] = byte( color_frac*color_range + float64(ms.options.MinNodeBrightness)) } } gl.Enable(gl.TEXTURE_2D) //gl.ActiveTexture(gl.TEXTURE0) gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId) gl.TexSubImage2D( gl.TEXTURE_2D, 0, 0, 0, gl.Sizei(ms.options.NumNodeRows), gl.Sizei(ms.options.NumNodeCols), gl.RGB, gl.UNSIGNED_BYTE, gl.Pointer(&local.nodeTextureData[0])) base.EnableShader("nodes") base.SetUniformI("nodes", "width", ms.options.NumNodeRows*3) base.SetUniformI("nodes", "height", ms.options.NumNodeCols*3) base.SetUniformI("nodes", "drains", 1) base.SetUniformI("nodes", "tex0", 0) base.SetUniformI("nodes", "tex1", 1) base.SetUniformF("nodes", "zoom", float32(zoom)) gl.ActiveTexture(gl.TEXTURE0) gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId) // I have no idea why this value for move works, but it does. So, hooray. move := (dx - dy) / 2 texture.RenderAdvanced(move, -move, dy, dx, 3.1415926535/2, true) base.EnableShader("") gl.Disable(gl.TEXTURE_2D) }
func initWindow(sys system.System, width int, height int) { sys.CreateWindow(10, 10, width, height) sys.EnableVSync(false) err := gl.Init() if err != nil { panic(err) } gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.EnableClientState(gl.VERTEX_ARRAY) gl.EnableClientState(gl.COLOR_ARRAY) gl.Enable(gl.CULL_FACE) gl.FrontFace(gl.CW) gl.ClearColor(0, 0, 0, 1) }
func glInit(width, height int) { gl.Init() gl.Enable(gl.TEXTURE_2D) gl.PixelStorei(gl.UNPACK_ALIGNMENT, 1) gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height)) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, gl.Double(width), gl.Double(height), 0, -1, 1) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.EnableClientState(gl.VERTEX_ARRAY) gl.EnableClientState(gl.COLOR_ARRAY) gl.EnableClientState(gl.TEXTURE_COORD_ARRAY) gl.VertexPointer(2, gl.FLOAT, 0, gl.Pointer(&vs[0])) gl.ColorPointer(3, gl.UNSIGNED_BYTE, 0, gl.Pointer(&cs[0])) gl.TexCoordPointer(2, gl.FLOAT, 0, gl.Pointer(&ts[0])) }
func initScene() { gl.Disable(gl.TEXTURE_2D) gl.Disable(gl.DEPTH_TEST) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Disable(gl.ALPHA_TEST) gl.Enable(gl.LINE_SMOOTH) gl.Hint(gl.LINE_SMOOTH_HINT, gl.NICEST) gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE) gl.LineWidth(1.0) gl.ClearColor(0.0, 0.0, 0.0, 0.0) gl.ClearDepth(1) //gl.DepthFunc(gl.LEQUAL) gl.Viewport(0, 0, Width, Height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() perspective(110.0, 1.0, 4, 8192) }
func ClearScene() { ambient := []gl.Float{0.7, 0.7, 0.7, 1} diffuse := []gl.Float{0.9, 0.9, 0.9, 1} lightpos := []gl.Float{0.2, 0.5, 1, 1} gl.Lightfv(gl.LIGHT0, gl.AMBIENT, &ambient[0]) gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, &diffuse[0]) gl.Lightfv(gl.LIGHT0, gl.POSITION, &lightpos[0]) gl.Enable(gl.LIGHT0) gl.ClearColor(1, 1, 1, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) }
func Text(x, y, z float32, str string) { gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Enable(gl.BLEND) gl.RasterPos3f(x, y, z) for _, ch := range str { //glut.BitmapCharacter(glut.BITMAP_9_BY_15, string(ch)) } gl.Disable(gl.BLEND) }
func makeErrorTexture() { gl.Enable(gl.TEXTURE_2D) gl.GenTextures(1, (*gl.Uint)(&error_texture)) gl.BindTexture(gl.TEXTURE_2D, error_texture) gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT) pink := []byte{255, 0, 255, 255} gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.BYTE, gl.Pointer(&pink[0])) }
func (g *Game) RenderLocalEditor(region g2.Region) { g.editor.Lock() defer g.editor.Unlock() g.editor.region = region g.editor.camera.regionDims = linear.Vec2{float64(region.Dims.Dx), float64(region.Dims.Dy)} levelDims := linear.Vec2{float64(g.Level.Room.Dx), float64(g.Level.Room.Dy)} g.editor.camera.StandardRegion(levelDims.Scale(0.5), levelDims) g.editor.camera.approachTarget() gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.LoadIdentity() defer gl.PopMatrix() gl.PushAttrib(gl.VIEWPORT_BIT) gl.Viewport(gl.Int(region.X), gl.Int(region.Y), gl.Sizei(region.Dx), gl.Sizei(region.Dy)) defer gl.PopAttrib() current := &g.editor.camera.current gl.Ortho( gl.Double(current.mid.X-current.dims.X/2), gl.Double(current.mid.X+current.dims.X/2), gl.Double(current.mid.Y+current.dims.Y/2), gl.Double(current.mid.Y-current.dims.Y/2), gl.Double(1000), gl.Double(-1000), ) defer func() { gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) }() gl.MatrixMode(gl.MODELVIEW) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) g.renderWalls() g.renderEdges() g.renderBases() g.renderEntsAndAbilities() g.renderProcesses() g.editor.renderPathing(&g.Level.Room, g.local.pathingData) switch g.editor.action { case editorActionNone: case editorActionPlaceBlock: g.editor.renderPlaceBlock(g) default: base.Error().Printf("Unexpected editorAction: %v", g.editor.action) } }
func Number(x, y, z, n float32) { gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Enable(gl.BLEND) s := "" fmt.Fprintf(s, "%f", n) gl.RasterPos3f(x, y, z) for _, ch := range s { //glut.BitmapCharacter(glut.BITMAP_9_BY_15, string(ch)) } gl.Disable(gl.BLEND) }
func Render(x, y, dx, dy float64) { var run, op mathgl.Mat4 run.Identity() op.Translation(float32(x), float32(y), 0) run.Multiply(&op) op.Scaling(float32(dx), float32(dy), 1) run.Multiply(&op) gl.PushMatrix() gl.Enable(gl.TEXTURE_2D) gl.MultMatrixf((*gl.Float)(&run[0])) gl.CallList(textureList) gl.PopMatrix() }
func (sb *spriteBox) Draw(region gui.Region) { gl.Disable(gl.TEXTURE_2D) gl.Color4d(sb.r, sb.g, sb.b, 1) gl.Begin(gl.QUADS) gl.Vertex2i(int32(region.X+region.Dx/3), int32(region.Y)) gl.Vertex2i(int32(region.X+region.Dx/3), int32(region.Y+region.Dy)) gl.Vertex2i(int32(region.X+region.Dx/3*2), int32(region.Y+region.Dy)) gl.Vertex2i(int32(region.X+region.Dx/3*2), int32(region.Y)) gl.End() if sb.s != nil { gl.Enable(gl.TEXTURE_2D) tx, ty, tx2, ty2 := sb.s.Bind() // fmt.Printf("Tex: %f %f %f %f\n", tx, ty, tx2, ty2) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Color4f(1, 1, 1, 1) gl.Begin(gl.QUADS) x := int32(region.X + region.Dx/2) y := int32(region.Y + region.Dy/2) gl.TexCoord2d(tx, -ty) gl.Vertex2i(x-50, y-75) gl.TexCoord2d(tx, -ty2) gl.Vertex2i(x-50, y+75) gl.TexCoord2d(tx2, -ty2) gl.Vertex2i(x+50, y+75) gl.TexCoord2d(tx2, -ty) gl.Vertex2i(x+50, y-75) gl.End() gl.Color4d(1, 1, 1, 1) text := fmt.Sprintf("%d : %s : %s", sb.s.Facing(), sb.s.Anim(), sb.s.AnimState()) if sb.top { dict.RenderString(text, float64(region.X), float64(region.Y+region.Dy)-dict.MaxHeight(), 0, dict.MaxHeight(), gui.Left) } else { dict.RenderString(text, float64(region.X), float64(region.Y), 0, dict.MaxHeight(), gui.Left) } } }
func (tm *ThunderMenu) Draw(region Region, style StyleStack) { // Set clip planes gl.PushAttrib(gl.TRANSFORM_BIT) defer gl.PopAttrib() var eqs [4][4]gl.Double eqs[0][0], eqs[0][1], eqs[0][2], eqs[0][3] = 1, 0, 0, -gl.Double(region.X) eqs[1][0], eqs[1][1], eqs[1][2], eqs[1][3] = -1, 0, 0, gl.Double(region.X+region.Dx) eqs[2][0], eqs[2][1], eqs[2][2], eqs[2][3] = 0, 1, 0, -gl.Double(region.Y) eqs[3][0], eqs[3][1], eqs[3][2], eqs[3][3] = 0, -1, 0, gl.Double(region.Y+region.Dy) gl.Enable(gl.CLIP_PLANE0) gl.Enable(gl.CLIP_PLANE1) gl.Enable(gl.CLIP_PLANE2) gl.Enable(gl.CLIP_PLANE3) gl.ClipPlane(gl.CLIP_PLANE0, &eqs[0][0]) gl.ClipPlane(gl.CLIP_PLANE1, &eqs[1][0]) gl.ClipPlane(gl.CLIP_PLANE2, &eqs[2][0]) gl.ClipPlane(gl.CLIP_PLANE3, &eqs[3][0]) var start, end int if tm.delta <= 0 { start = tm.current + int(math.Floor(tm.delta)) end = tm.current region.X += int(float64(region.Dx) * (float64(start-tm.current) - tm.delta)) } else { start = tm.current end = tm.current + int(math.Ceil(tm.delta)) region.X += int(float64(region.Dx) * (float64(end-tm.current) - tm.delta - math.Floor(tm.delta) - 1)) } var offset linear.Vec2 offset.X = (float64(tm.current) + tm.delta) * float64(region.Dx) for i := start; i <= end; i++ { style.PushStyle(map[string]interface{}{"offset": offset}) tm.Subs[tm.menuStack[i]].Draw(region, style) style.Pop() region.X += region.Dx } }
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[0]) gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, &diffuse[0]) gl.Lightfv(gl.LIGHT0, gl.POSITION, &lightpos[0]) 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() texture, err = createTextureFromBytes(gopher_png[:]) return }
func initScene() { gl.Enable(gl.DEPTH_TEST) gl.Enable(gl.LIGHTING) gl.ClearColor(0.1, 0.1, 0.6, 1.0) gl.ClearDepth(1) gl.DepthFunc(gl.LEQUAL) gl.Lightfv(gl.LIGHT0, gl.AMBIENT, &ambient[0]) gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, &diffuse[0]) gl.Lightfv(gl.LIGHT0, gl.POSITION, &lightPos[0]) gl.Enable(gl.LIGHT0) gl.Viewport(0, 0, Width, Height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Frustum(-1, 1, -1, 1, 1.0, 1000.0) gl.Rotatef(20, 1, 0, 0) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.PushMatrix() return }
func renderBoard(g *game.Game, x, y, dx, dy int) { tx := dx / len(g.Level.Tiles) ty := dy / len(g.Level.Tiles[0]) gl.Enable(gl.TEXTURE_2D) gl.Color4ub(255, 255, 255, 255) for i := range g.Level.Tiles { for j := range g.Level.Tiles[i] { if g.Level.Tiles[i][j].Type == game.TileEmpty { tilePath := filepath.Join(base.GetDataDir(), fmt.Sprintf("textures/tile%d.png", (i+j)%4+1)) tile := texture.LoadFromPath(tilePath) tile.Render(float64(x+i*tx), float64(y+j*ty), float64(tx), float64(ty)) } } } }
func initDraw() error { runtime.LockOSThread() err := gl.Init() if err != nil { return err } gl.ClearColor(0.0, 0.0, 0.0, 1.0) gl.Enable(gl.BLEND) gl.BlendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ZERO) return checkForErrors() }
func (gw *GameWindow) Draw(region gui.Region) { gw.region = region latest_region = region gl.PushMatrix() defer gl.PopMatrix() gl.Translated(gl.Double(gw.region.X), gl.Double(gw.region.Y), 0) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gw.game.manaSource.Draw(gw, float64(gw.game.Dx), float64(gw.game.Dy)) gl.Begin(gl.LINES) gl.Color4d(1, 1, 1, 1) for _, poly := range gw.game.Room.Walls { for i := range poly { seg := poly.Seg(i) gl.Vertex2d(gl.Double(seg.P.X), gl.Double(seg.P.Y)) gl.Vertex2d(gl.Double(seg.Q.X), gl.Double(seg.Q.Y)) } } gl.End() gl.Begin(gl.TRIANGLE_FAN) gl.Color4d(1, 0, 0, 1) for _, poly := range gw.game.Room.Lava { for _, v := range poly { gl.Vertex2d(gl.Double(v.X), gl.Double(v.Y)) } } gl.End() gl.Color4d(1, 1, 1, 1) for _, ent := range gw.game.Ents { ent.Draw(gw.game) } gl.Disable(gl.TEXTURE_2D) for _, player := range local.players { if player.active_ability != nil { player.active_ability.Draw(player.id, gw.game) } } // base.GetDictionary("luxisr").RenderString("monkeys!!!", 10, 10, 0, float64(gw.game.Game_thinks), gin.Left) }
func mainLoop(client sgf.ClientEngine, controllers []gin.DeviceId, console *base.Console) { client.MakeRequest(game.Join{Rebels: make([]*game.RebelPlayer, 2)}) ticker := time.Tick(time.Millisecond * 17) render.Queue(func() { gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) }) for { <-ticker if gin.In().GetKey(gin.AnyEscape).FramePressCount() != 0 { return } sys.Think() render.Queue(func() { gl.Clear(gl.COLOR_BUFFER_BIT) gl.Disable(gl.DEPTH_TEST) gui.SetFontColor(1, 1, 1, 1) gl.Disable(gl.TEXTURE_2D) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(gl.Double(0), gl.Double(wdx), gl.Double(wdy), gl.Double(0), 1000, -1000) gl.ClearColor(0, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() base.GetDictionary("crackin").RenderString("Waiting on some nubs", float64(wdx)/2, 300, 0, 100, gui.Center) }) client.RLock() g := client.Game().(*game.Game) mode := g.Mode client.RUnlock() if mode == game.ModeWaiting { } else if mode == game.ModeProgram { programLoop(client, controllers, console) } else if mode == game.ModeRun { } render.Queue(func() { sys.SwapBuffers() }) render.Purge() } }
func (g *Game) RenderLocalGame(region g2.Region) { g.local.Camera.regionDims = linear.Vec2{float64(region.Dims.Dx), float64(region.Dims.Dy)} // func (g *Game) renderLocalHelper(region g2.Region, local *LocalData, camera *cameraInfo, side int) { g.local.Camera.FocusRegion(g, 0) gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.LoadIdentity() // Set the viewport so that we only render into the region that we're supposed // to render to. // TODO: Check if this works on all graphics cards - I've heard that the opengl // spec doesn't actually require that viewport does any clipping. gl.PushAttrib(gl.VIEWPORT_BIT) gl.Viewport(gl.Int(region.X), gl.Int(region.Y), gl.Sizei(region.Dx), gl.Sizei(region.Dy)) defer gl.PopAttrib() current := &g.local.Camera.current gl.Ortho( gl.Double(current.mid.X-current.dims.X/2), gl.Double(current.mid.X+current.dims.X/2), gl.Double(current.mid.Y+current.dims.Y/2), gl.Double(current.mid.Y-current.dims.Y/2), gl.Double(1000), gl.Double(-1000), ) defer func() { gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) }() gl.MatrixMode(gl.MODELVIEW) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) level := g.Level zoom := current.dims.X / float64(region.Dims.Dx) level.ManaSource.Draw(zoom, float64(level.Room.Dx), float64(level.Room.Dy)) g.renderWalls() g.renderEdges() g.renderBases() g.renderEntsAndAbilities() g.renderProcesses() g.RenderLosMask() }
func DrawStarTex(t *data.Star) { // Find the center point of the texture to rotate around xav := (t.X1 + t.X2) / 2 yav := (t.Y1 + t.Y2) / 2 //Translate there, rotate, translate back gl.MatrixMode(gl.MODELVIEW) gl.Translatef(xav, yav, 0) gl.Rotatef(gl.Float(t.Theta), 0, 0, 1) gl.Translatef(-xav, -yav, 0) //Bind our texture to be drawn by id gl.Color3f(1, 1, 1) gl.Enable(gl.TEXTURE_2D) gl.BindTexture(gl.TEXTURE_2D, t.TexId) // Draw a rectangle with the texture stretched to the corners gl.Begin(gl.QUADS) // Stretch the texture to its 4 corners. gl.TexCoord2d(0, 0) gl.Vertex2f(t.X1, t.Y1) gl.TexCoord2d(0, 1) gl.Vertex2f(t.X1, t.Y2) gl.TexCoord2d(1, 1) gl.Vertex2f(t.X2, t.Y2) gl.TexCoord2d(1, 0) gl.Vertex2f(t.X2, t.Y1) gl.End() // Unbind the texture in case something else wants to draw gl.Disable(gl.TEXTURE_2D) // Reset the matrix gl.LoadIdentity() }
func (a *app) OnGLInit() { gl.Init() var ntex int if *blend { ntex = 6 } else { ntex = 3 } for i := 0; i < ntex; i++ { texinit(i + 1) } a.factorloc = shinit() initquad() gl.Enable(gl.TEXTURE_2D) gl.Disable(gl.DEPTH_TEST) a.tbase = time.Now() if *fullscreen { a.enterFullscreen() } }
func (m *Manager) LoadSprite(path string) (*Sprite, error) { // We can't run this during an init() function because it will get queued to // run before the opengl context is created, so we just check here and run // it if we haven't run it before. gen_tex_once.Do(func() { render.Queue(func() { gl.Enable(gl.TEXTURE_2D) gl.GenTextures(1, &error_texture) gl.BindTexture(gl.TEXTURE_2D, error_texture) gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT) pink := []byte{255, 0, 255, 255} gl.TexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_INT, gl.Pointer(&pink[0])) }) }) path = filepath.Clean(path) err := m.loadSharedSprite(path) if err != nil { return nil, err } var s Sprite m.mutex.Lock() s.shared = m.shared[path] m.mutex.Unlock() s.anim_node = s.shared.anim_start s.state_node = s.shared.state_start return &s, nil }