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() }
func InitDisplay() { gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, 100, 0, 100, -1, 1) gl.MatrixMode(gl.MODELVIEW) gl.PointSize(3.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) }
func initWindow() { // Function called to do the re-rendering glut.DisplayFunc(display) // Called when the visibility of the program changes glut.VisibilityFunc(visible) // Called when a regular ascii character is pressed glut.KeyboardFunc(keyboardIn) // Called when any non-ascii character is pressed glut.SpecialFunc(specialIn) // Called when the size of the window changes glut.ReshapeFunc(reshape) // affect our projection matrix gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() // Load an identity matrix -> projection // Specify the bounds of the of our scene gl.Ortho(0, 40, 0, 40, 0, 40) // Now affect our modelview matrix gl.MatrixMode(gl.MODELVIEW) // Make points be rendererd larger gl.PointSize(3.0) currentWindow = glut.GetWindow() }
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) }
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 }
func copiedReshape(window *glfw.Window, w int, h int) { gl.DrawBuffer(gl.FRONT_AND_BACK) //gl.Viewport(int(w/2), int(h/2), w, h) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Frustum(-1, 1, -1, 1, 1.5, 20) gl.MatrixMode(gl.MODELVIEW) }
// 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() }
// 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() }
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() }
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) }
func reshape(w, h int) { gl.Viewport(0, 0, w, h) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, float64(w), 0, float64(h), -1, 1) gl.Scalef(1, -1, 1) gl.Translatef(0, float32(-h), 0) gl.MatrixMode(gl.MODELVIEW) }
func (r *RenderTarget) popGlStates() { gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) gl.PopMatrix() gl.MatrixMode(gl.TEXTURE) gl.PopMatrix() gl.PopClientAttrib() gl.PopAttrib() }
func copiedInit() { gl.ClearColor(0, 0, 0, 0) gl.ShadeModel(gl.FLAT) gl.Enable(gl.CULL_FACE) gl.Viewport(320, 240, 640, 480) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Frustum(-1, 1, -1, 1, 1.5, 20) gl.MatrixMode(gl.MODELVIEW) }
// 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) }
// 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) }
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() }
/* 下面的代码的作用是重新设置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() ///重置模型观察矩阵 }
func (r *RenderTarget) pushGlStates() { gl.PushClientAttrib(gl.CLIENT_ALL_ATTRIB_BITS) gl.PushAttrib(gl.ALL_ATTRIB_BITS) gl.MatrixMode(gl.MODELVIEW) gl.PushMatrix() gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.MatrixMode(gl.TEXTURE) gl.PushMatrix() r.resetGlStates() }
/* 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) }
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() }
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() }
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() }
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) }
func reshapeWindow(window *glfw.Window, width, height int) { ratio := float64(width) / float64(height) gameWidth = ratio * fieldSize gameHeight = fieldSize gl.Viewport(0, 0, width, height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, gameWidth, 0, gameHeight, -1.0, 1.0) gl.MatrixMode(gl.MODELVIEW) if wireframe { gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE) } }
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 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) }
// 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) }
// 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() }
// 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() }