Esempio n. 1
0
func parseColor(i *int, dat []string) Color {

	errString := "Failed to convert Color data: " + dat[*i]
	*i++

	var r, g, b float64
	var err error

	if r, err = strconv.ParseFloat(dat[*i], 32); err != nil {
		Logging.Info(errString, err)
	}

	*i++

	if g, err = strconv.ParseFloat(dat[*i], 32); err != nil {
		Logging.Info(errString, err)
	}

	*i++

	if b, err = strconv.ParseFloat(dat[*i], 32); err != nil {
		Logging.Info(errString, err)
	}

	return Color{R: float32(r), G: float32(g), B: float32(b)}

}
Esempio n. 2
0
// OBJAnimation takes the folder to OBJ files and creates animation from
// them
func OBJAnimation(loc string) *FrameAnimation {
	//TODO need to cache all models
	files, err := ioutil.ReadDir(loc)
	if err != nil {
		Logging.Info(err)
		return nil
	}

	fa := newFrameAnimation()

	for _, file := range files {
		// Logging.Info("Parsing anim OBJ: ", file.Name())
		splitExt := strings.Split(file.Name(), ".")
		if splitExt[1] == "obj" {
			obj := loc + string(os.PathSeparator) + splitExt[0] + ".obj"
			mtl := loc + string(os.PathSeparator) + splitExt[0] + ".mtl"
			mesh, err := G3D.ParseOBJ(obj, mtl)

			if err != nil {
				Logging.Info(err)
				continue
			}

			fa.animationImages = append(fa.animationImages, mesh)

		}

	}

	return fa
}
Esempio n. 3
0
func main() {
	// create the foundation: a new window, basic scene, and game component (node)
	GT.EngineStart()
	probe := Opengl.Probe()
	Logging.Info("Max Texture Size: ", probe.MaxTextureSize)
	Logging.Info("Max Texture Image Units: ", probe.MaxTextureImageUnits)
	Logging.Info("Shader Version: ", probe.ShaderVersion)
}
Esempio n. 4
0
// SetCurrentAnimation takes a animation's name and tries to set that as the current animation
func (a *AnimationManager) SetCurrentAnimation(mappedAnimationName string) {
	animationRetrieved, ok := a.animationsMap[mappedAnimationName]
	if !ok {
		Logging.Debug("couldn't find the animation: " + mappedAnimationName)
	}

	a.currentAnimation = animationRetrieved
	Logging.Info(mappedAnimationName, ":Set current anim to ", a.currentAnimation)
	Logging.Info("Animation Map: ", a.animationsMap)
}
Esempio n. 5
0
func fileVisitor(path string, f os.FileInfo, err error) error {
	if strings.Contains(path, ".ttf") {
		Logging.Info("Processing font: %s\n", path)
		fInfo := loadFont(path)
		fonts = append(fonts, &fInfo)

		Logging.Info("Found Font: " + fInfo.Name())
		fontsMap[fInfo.Name()] = &fInfo
	}

	return nil
}
Esempio n. 6
0
// GetAnimation grabs a mapped animation and returns it for the user to manipulate if desired
func (a *AnimationManager) GetAnimation(mappedName string) *FrameAnimation {
	animation, exists := a.animationsMap[mappedName]
	if !exists {
		Logging.Info("the animation " + mappedName + " wasn't found, please try a different name")
	}
	return animation
}
Esempio n. 7
0
func NewWindowedWindow(title string, width, height int) Window {
	// FOR GLFW event handling
	runtime.LockOSThread()

	windowSDL, err := sdl.CreateWindow(title, sdl.WINDOWPOS_UNDEFINED,
		sdl.WINDOWPOS_UNDEFINED,
		width, height, sdl.WINDOW_OPENGL)

	if err != nil {
		panic(err)
	}
	if windowSDL == nil {
		panic(sdl.GetError())
	}

	context, err := sdl.GL_CreateContext(windowSDL)

	sdl.GL_MakeCurrent(windowSDL, context)

	if err != nil {
		panic("Error loading window: " + err.Error())
	}

	w := Window{title: title, Width: width, Height: height, full: false, windowSDL: windowSDL, contextSDL: context, running: false}

	w.init()
	var current sdl.DisplayMode
	if err := sdl.GetCurrentDisplayMode(0, &current); err != nil {
		Logging.Debug("Could not get display mode: " + err.Error())
	}
	Logging.Info("Display #%d: current display mode is %dx%dpx @ %dhz. \n", 0, current.W, current.H, current.RefreshRate)

	return w
}
Esempio n. 8
0
// AddAnimation maps a created animation inside the renderer
func (a *AnimationManager) AddAnimation(animationToAdd *FrameAnimation, nameToMap string) {
	_, ok := a.animationsMap[nameToMap]
	if !ok {
		a.animationsMap[nameToMap] = animationToAdd
	} else {
		Logging.Info("the animation " + nameToMap + " already exists, please try a different name")
	}
}
Esempio n. 9
0
func (this *Mesh) VertexData() *Opengl.OpenGLVertexInfo {
	vertexData := Opengl.OpenGLVertexInfo{}

	for _, face := range this.Faces {
		for idx, vIdx := range face.V {
			c := this.Materials[face.Material].Diffuse
			v := this.Vs[vIdx]
			vdID := vertexData.NewVertex(v.X, v.Y, v.Z)
			vertexData.SetColor(vdID, c.R, c.G, c.B, 1)

			tex := this.Materials[face.Material].DiffuseTex

			if len(face.UV) == 0 || tex == "" {
				vertexData.SetMode(vdID, Opengl.NO_TEXTURE)
			} else {

				imgSec := Image.GetImageSection(GT.AssetsImages + tex)

				if imgSec == nil {
					Logging.Info("Cannot open: ", GT.AssetsImages+tex, " For Mat: ", face.Material)

				}

				// uvs
				u := this.VTs[face.UV[idx]].U
				v := this.VTs[face.UV[idx]].V

				//normals

				// x starts from left to right
				locX := int(float32(imgSec.Bounds().Dx()) * u)
				// y starts bottom to top so we need to convert.
				locY := int(float32(imgSec.Bounds().Max.Y) - float32(imgSec.Bounds().Dy())*v)

				locX += imgSec.Section.Min.X
				locY += imgSec.Section.Min.Y

				newU, newV := Image.GetUVFromPosition(image.Point{locX, locY})

				vertexData.SetUV(vdID, newU, newV)

				vertexData.SetMode(vdID, Opengl.TEXTURED)

				// set normals
				nX := this.VNs[face.VN[idx]].X
				nY := this.VNs[face.VN[idx]].Y
				nZ := this.VNs[face.VN[idx]].Z

				vertexData.SetMNormal(vdID, nX, nY, nZ)
				vertexData.SetWNormal(vdID, nX, nY, nZ)

			}
		}
	}
	return &vertexData
}
Esempio n. 10
0
func readFlags() {
	flag.Parse()

	imgsPath := getAbsPath("/Images")

	fontsPath := getAbsPath("/Fonts")

	modelsPath := getAbsPath("/Models")

	AssetsFonts = fontsPath
	AssetsImages = imgsPath + string(os.PathSeparator)
	AssetsModels = modelsPath + string(os.PathSeparator)

	Logging.Info("Assets Path: ", *Assets)
	Logging.Info("Images Path: ", AssetsImages)
	Logging.Info("Fonts Path: ", AssetsFonts)
	Logging.Info("Models Path: ", AssetsModels)
	Logging.Info("OGL Version Used: ", *OGL_VERSION)
}
Esempio n. 11
0
func getAbsPath(folder string) string {
	path, _ := filepath.Abs(*Assets + folder)

	if _, err := os.Stat(path); err != nil {
		Logging.Info("Please specify the correct Assets path with the -Assets flag")
		panic(err)
	}

	return path
}
Esempio n. 12
0
func (this *Node) GetComponent(componentType string) Component {
	for _, c := range this.components {
		Logging.Info("type:")
		Logging.Info(reflect.TypeOf(c).Elem().Name())

		cType := reflect.TypeOf(c).Elem().Name()

		// need to handle defer here as reflect may throw panic if type not a pointer
		defer func() {
			cType = reflect.TypeOf(c).Name()
		}()

		if cType == componentType {
			return c
		}
	}

	Logging.Info("Cannot find component: " + componentType)
	return nil
}
Esempio n. 13
0
func main() {

	// The logger now initializes in the Engine's start. That is where flags get parsed etc.
	GT.EngineStart()

	// TODO: test filtering and simultaneous outputs once implemented and configured
	Logging.Debug("debug")
	Logging.Info("info")

	// Note: this has been tested to work on multiple code call levels
	// so inserting debug logs in SimpleWindow.go as well as Scene.go
	// will place all info into GT/Logging/default.log
}
Esempio n. 14
0
func (this *modelRenderer) SetModel(path string, mat string) {
	//TODO make aggregate models store them in memory
	mesh, err := G3D.ParseOBJ(path, mat)

	if err != nil {
		Logging.Info(err)
	}

	this.mesh = mesh

	// this.vertexData = vertexData

}
Esempio n. 15
0
// EngineStart initializes everything in order within the engine. Should be called first
func EngineStart() {

	readFlags()

	Window.Start()
	Opengl.OGL_VERSION = *OGL_VERSION
	Opengl.Start()

	Font.LoadFonts(AssetsFonts)
	Image.LoadImages(AssetsImages)
	Opengl.CreateBuffers()
	Logging.Info("Engine initialization finished.")
	// Image.AggrImg.Print("aggr.png")
}