// list of boxes // the point of origin // the translated offset from the origin // the angles co-ordinate // the index of the array // the degree of angular rotation func wall(b []uint32, o, offset, a_cord cord, i int32, a float64, s size) []uint32 { b = append(b, gl.GenLists(1)) gl.NewList(b[i], gl.COMPILE) gl.Translated(o.x+offset.x, o.y+offset.y, o.z+offset.z) gl.Rotated(a, a_cord.x, a_cord.y, a_cord.z) box(s.x, s.y, s.z) gl.EndList() return b }
func InitFont() { LoadTexture(filepath.FromSlash("/Users/Dmitri/Dropbox/Work/2015/Bitmap Fonts/Helvetica Neue.png")) oFontBase = gl.GenLists(32 + 96) for i := 0; i < 96; i++ { const shiftY = float64(1.0 / 6) indexX, indexY := i%16, i/16 charWidth := shiftXs[indexY][indexX+1] - shiftXs[indexY][indexX] gl.NewList(oFontBase+uint32(i+32), gl.COMPILE) gl.Begin(gl.QUADS) gl.TexCoord2d(shiftXs[indexY][indexX], float64(indexY)*shiftY) gl.Vertex2d(0, 0) gl.TexCoord2d(shiftXs[indexY][indexX+1], float64(indexY)*shiftY) gl.Vertex2d(fontWidth*charWidth/float64(1.0/16), 0) gl.TexCoord2d(shiftXs[indexY][indexX+1], float64(indexY+1)*shiftY) gl.Vertex2d(fontWidth*charWidth/float64(1.0/16), fontHeight) gl.TexCoord2d(shiftXs[indexY][indexX], float64(indexY+1)*shiftY) gl.Vertex2d(0, fontHeight) gl.End() gl.Translated(fontWidth*charWidth/float64(1.0/16), 0.0, 0.0) gl.EndList() } oFontBackground = gl.GenLists(1) gl.NewList(oFontBackground, gl.COMPILE) gl.Begin(gl.QUADS) gl.Vertex2d(0, 0) gl.Vertex2d(0, fontHeight) gl.Vertex2d(fontWidth, fontHeight) gl.Vertex2d(fontWidth, 0) gl.End() gl.Translated(fontWidth, 0.0, 0.0) gl.EndList() CheckGLError() }
func InitFont() { LoadTexture(filepath.Join("data", "Font.png")) oFontBase = gl.GenLists(32 + 96*4) for i := 0; i < 96*4; i++ { const shiftX, shiftY = float64(1.0 / 16), float64(1.0 / 6 / 4) indexX, indexY := i%16, i/16 gl.NewList(oFontBase+uint32(i+32), gl.COMPILE) gl.Begin(gl.QUADS) gl.TexCoord2d(float64(indexX)*shiftX, float64(indexY)*shiftY) gl.Vertex2i(0, 0) gl.TexCoord2d(float64(indexX+1)*shiftX, float64(indexY)*shiftY) gl.Vertex2i(fontWidth, 0) gl.TexCoord2d(float64(indexX+1)*shiftX, float64(indexY+1)*shiftY) gl.Vertex2i(fontWidth, fontHeight) gl.TexCoord2d(float64(indexX)*shiftX, float64(indexY+1)*shiftY) gl.Vertex2i(0, fontHeight) gl.End() gl.Translated(fontWidth, 0.0, 0.0) gl.EndList() } oFontBackground = gl.GenLists(1) gl.NewList(oFontBackground, gl.COMPILE) gl.Begin(gl.QUADS) gl.Vertex2i(0, 0) gl.Vertex2i(0, fontHeight) gl.Vertex2i(fontWidth, fontHeight) gl.Vertex2i(fontWidth, 0) gl.End() gl.Translated(fontWidth, 0.0, 0.0) gl.EndList() CheckGLError() }
// loadFont loads the given font data. This does not deal with font scaling. // Scaling should be handled by the independent Bitmap/Truetype loaders. // We therefore expect the supplied image and charset to already be adjusted // to the correct font scale. // // The image should hold a sprite sheet, defining the graphical layout for // every glyph. The config describes font metadata. func loadFont(img *image.RGBA, config *FontConfig) (f *Font, err error) { f = new(Font) f.config = config // Resize image to next power-of-two. img = Pow2Image(img).(*image.RGBA) ib := img.Bounds() // Create the texture itself. It will contain all glyphs. // Individual glyph-quads display a subset of this texture. gl.GenTextures(1, &f.texture) gl.BindTexture(gl.TEXTURE_2D, f.texture) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(ib.Dx()), int32(ib.Dy()), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(img.Pix)) // Create display lists for each glyph. f.listbase = gl.GenLists(int32(len(config.Glyphs))) texWidth := float32(ib.Dx()) texHeight := float32(ib.Dy()) for index, glyph := range config.Glyphs { // Update max glyph bounds. if glyph.Width > f.maxGlyphWidth { f.maxGlyphWidth = glyph.Width } if glyph.Height > f.maxGlyphHeight { f.maxGlyphHeight = glyph.Height } // Quad width/height vw := float32(glyph.Width) vh := float32(glyph.Height) // Texture coordinate offsets. tx1 := float32(glyph.X) / texWidth ty1 := float32(glyph.Y) / texHeight tx2 := (float32(glyph.X) + vw) / texWidth ty2 := (float32(glyph.Y) + vh) / texHeight // Advance width (or height if we render top-to-bottom) adv := float32(glyph.Advance) gl.NewList(f.listbase+uint32(index), gl.COMPILE) { gl.Begin(gl.QUADS) { gl.TexCoord2f(tx1, ty2) gl.Vertex2f(0, 0) gl.TexCoord2f(tx2, ty2) gl.Vertex2f(vw, 0) gl.TexCoord2f(tx2, ty1) gl.Vertex2f(vw, vh) gl.TexCoord2f(tx1, ty1) gl.Vertex2f(0, vh) } gl.End() switch config.Dir { case LeftToRight: gl.Translatef(adv, 0, 0) case RightToLeft: gl.Translatef(-adv, 0, 0) case TopToBottom: gl.Translatef(0, -adv, 0) } } gl.EndList() } err = checkGLError() return }