Ejemplo n.º 1
0
func main() {
	// This file holds the actual glyph shapes.
	imgFile, err := gas.Abs("github.com/go-gl/examples/data/bitmap_font.png")
	if err != nil {
		log.Printf("Find font image file: %v", err)
		return
	}

	// This file is a JSON encoded dataset which describes the font
	// and contains the pixel offsets and sizes for each glyph in
	// bitmap_font.png. Both files are needed to load a bitmap font.
	configFile, err := gas.Abs("github.com/go-gl/examples/data/bitmap_font.js")
	if err != nil {
		log.Printf("Find font config file: %v", err)
		return
	}

	err = initGL()
	if err != nil {
		log.Printf("InitGL: %v", err)
		return
	}

	defer glfw.Terminate()

	// Load the same bitmap font at different scale factors.
	for i := range fonts {
		fonts[i], err = loadFont(imgFile, configFile, i+1)
		if err != nil {
			log.Printf("LoadFont: %v", err)
			return
		}

		defer fonts[i].Release()
	}

	for glfw.WindowParam(glfw.Opened) > 0 {
		gl.Clear(gl.COLOR_BUFFER_BIT)

		err = drawString(10, 10, "0 1 2 3 4 5 6 7 8 9 A B C D E F")
		if err != nil {
			log.Printf("Printf: %v", err)
			return
		}

		glfw.SwapBuffers()
	}
}
Ejemplo n.º 2
0
Archivo: text.go Proyecto: pwaller/glh
// Load the default font used to render packages. It will panic if unable to find the font.
//
// The search path used is: The directories of the GOPATH env-var and the current directory, ie. "."
//
// If FontFile already have a non-empty path, this method does nothing.
func MustInitText() {
	if len(FontFile) > 0 {
		return
	}
	font := "code.google.com/p/freetype-go/luxi-fonts/luximr.ttf"
	var err error
	FontFile, err = gas.Abs(font)
	if err != nil {
		log.Panicf("Unable to load font file: %s", font)
	}
}
Ejemplo n.º 3
0
func (d *DrawImage) rebuildProgram() error {
	file, err := gas.Abs("github.com/andrebq/exp/opala/shaders")
	if err != nil {
		return err
	}
	program, err := compileProgram(file, "renderimage")
	if err != nil {
		return err
	}
	d.program = program
	return checkGlError()
}
Ejemplo n.º 4
0
// Load the font
func loadFonts(scale int32) *gltext.Font {
	file, err := gas.Abs("code.google.com/p/freetype-go/testdata/luxisr.ttf")
	if err != nil {
		panic(err)
	}
	fd, err := os.Open(file)
	if err != nil {
		panic(err)
	}
	defer fd.Close()

	font, err := gltext.LoadTruetype(fd, scale, 32, 127, gltext.LeftToRight)
	if err != nil {
		panic(err)
	}
	return font
}
Ejemplo n.º 5
0
Archivo: main.go Proyecto: andrebq/exp
// Load the mesh information.
func loadMeshInfo() {

	println(*meshFile)
	if *meshFile == "" {
		path, err := gas.Abs("github.com/andrebq/assimp/data/cube.dae")
		if err != nil {
			panic(err)
		}
		*meshFile = path
	}
	println(*meshFile)

	var err error
	scene, err = conv.LoadAsset(*meshFile)
	if err != nil {
		panic(err)
	}
}
Ejemplo n.º 6
0
Archivo: main.go Proyecto: andrebq/exp
func main() {
	staticDir, err := gas.Abs("github.com/andrebq/exp/davd/site")
	if err != nil {
		log.Printf("Error loading static site directory. cause: %v", err)
		return
	}

	m := &httpfs.Mount{BaseDir: *baseDir}
	httpfs := httpfs.NewHttpFS(m, "/fs/")

	http.Handle("/fs/", http.StripPrefix("/fs", httpfs))
	http.Handle("/", http.FileServer(http.Dir(staticDir)))

	log.Printf("Starting davd server at %v", *addr)
	err = http.ListenAndServe(*addr, nil)
	http.ListenAndServe(*addr, nil)
	if err != nil {
		log.Printf("Error opening server: %v", err)
	}
}
Ejemplo n.º 7
0
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}
	path, err := gas.Abs("github.com/andrebq/wfobj/testdata/complex/complex.obj")
	if err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}
	mesh, err = wfobj.LoadMeshFromFile(path)
	if err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

	if err = glfw.OpenWindow(Width, Height, 8, 8, 8, 8, 0, 8, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(Title)
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetKeyCallback(onKey)

	initGL()

	running = true
	for running && glfw.WindowParam(glfw.Opened) == 1 {
		drawScene()
	}
}
Ejemplo n.º 8
0
func main() {
	file, err := gas.Abs("code.google.com/p/freetype-go/luxi-fonts/luxisr.ttf")
	if err != nil {
		log.Printf("Find font file: %v", err)
		return
	}

	err = initGL()
	if err != nil {
		log.Printf("InitGL: %v", err)
		return
	}

	defer glfw.Terminate()

	// Load the same font at different scale factors and directions.
	for i := range fonts {
		fonts[i], err = loadFont(file, int32(12+i))
		if err != nil {
			log.Printf("LoadFont: %v", err)
			return
		}

		defer fonts[i].Release()
	}

	for glfw.WindowParam(glfw.Opened) > 0 {
		gl.Clear(gl.COLOR_BUFFER_BIT)

		err = drawString(10, 10, SampleString)
		if err != nil {
			log.Printf("Printf: %v", err)
			return
		}

		glfw.SwapBuffers()
	}
}
Ejemplo n.º 9
0
func init() {
	texturefiles[0], _ = gas.Abs("github.com/go-gl/examples/data/Glass.tga")
}
Ejemplo n.º 10
0
Archivo: 06.go Proyecto: nzlov/gogl
func init() {
	texturefiles[0], _ = gas.Abs("github.com/go-gl/examples/data/gopher.png")
}
Ejemplo n.º 11
0
func (self *Server) startHttp() error {
	http.Handle("/stream", websocket.Handler(func(ws *websocket.Conn) {
		log.Printf("New websocket: %v", ws)

		session := &ServerSession{
			ws:        ws,
			byteOrder: nil,
			rateLimit: 0x1000,
		}

		self.sessions = append(self.sessions, session)
		var req *JSONRPCRequest
		for {
			if err := websocket.JSON.Receive(ws, &req); err != nil {
				log.Printf("Error %v", err)
				break
			}
			log.Printf("Request: %v", req)
			res := &JSONRPCResponse{Id: req.Id}

			switch req.Method {
			case "init":
				switch byteOrder := req.Params["byteOrder"].(type) {
				case string:
					if byteOrder == "BIG_ENDIAN" {
						session.byteOrder = binary.BigEndian
					} else {
						session.byteOrder = binary.LittleEndian
					}
				default:
				}
				session.rateLimit = int64(req.Params["rateLimit"].(float64)) * 1e6
				session.initialized = true

				res.Result = map[string]interface{}{
					"config":       self.Config,
					"rigFrequency": self.rigFrequency,
					"rigMode":      self.rigMode,
				}
			case "frequency":
				self.handleFrequency(req, res, session)
			case "deviceBuffer":
				self.handleDeviceBuffer(req, res, session)
			case "speed":
				self.handleSpeed(req, res, session)
			case "tone":
				self.handleTone(req, res, session)
			case "send":
				self.handleSend(req, res, session)
			case "stop":
				self.handleStop(req, res, session)
			case "echo":
				self.handleEcho(req, res, session)
			default:
				res.Error = "unkown method"
			}

			log.Printf("Response: %v", res)
			websocket.JSON.Send(ws, res)
		}
		log.Printf("Closed websocket: %v", ws)
		for i, v := range self.sessions {
			if v == session {
				// remove this socket
				self.sessions = append(self.sessions[:i], self.sessions[i+1:]...)
				break
			}
		}
	}))

	go func() {
		bufferLittle := new(bytes.Buffer)
		bufferBig := new(bytes.Buffer)

		getBytes := func(result []float32, byteOrder binary.ByteOrder) []byte {
			var buffer *bytes.Buffer
			if byteOrder == binary.BigEndian {
				buffer = bufferBig
			} else {
				buffer = bufferLittle
			}

			if buffer.Len() > 0 {
				return buffer.Bytes()
			}

			err := binary.Write(buffer, byteOrder, result)
			if err != nil {
				fmt.Println("binary.Write failed:", err)
			}
			return buffer.Bytes()
		}

		for self.running {
			result := <-self.fftResult

			bufferLittle.Reset()
			bufferBig.Reset()

			for _, session := range self.sessions {
				if !session.initialized || session.byteOrder == nil {
					continue
				}
				now := time.Now().UnixNano()
				if now-session.lastTime < session.rateLimit {
					continue
				}
				websocket.Message.Send(session.ws, getBytes(result, session.byteOrder))
				session.lastTime = now
			}
		}
	}()

	var err error

	dir, err := gas.Abs("github.com/cho45/go-KX3-panadapter/static")
	if err != nil {
		panic(err)
	}
	http.Handle("/", http.FileServer(http.Dir(dir)))

	log.Printf("Http/WebSocket is now on http://%s/", self.Config.Server.Listen)
	err = http.ListenAndServe(self.Config.Server.Listen, nil)
	return err
}