Example #1
0
// program & OpenGL initialization
func Init() {
	pos := []float32{5.0, 5.0, 10.0, 0.0}
	red := []float32{0.8, 0.1, 0.0, 1.0}
	green := []float32{0.0, 0.8, 0.2, 1.0}
	blue := []float32{0.2, 0.2, 1.0, 1.0}

	gl.Lightfv(gl.LIGHT0, gl.POSITION, pos)
	gl.Enable(gl.CULL_FACE)
	gl.Enable(gl.LIGHTING)
	gl.Enable(gl.LIGHT0)
	gl.Enable(gl.DEPTH_TEST)

	// make the gears
	gear1 = gl.GenLists(1)
	gl.NewList(gear1, gl.COMPILE)
	gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, red)
	gear(1.0, 4.0, 1.0, 20, 0.7)
	gl.EndList()

	gear2 = gl.GenLists(1)
	gl.NewList(gear2, gl.COMPILE)
	gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, green)
	gear(0.5, 2.0, 2.0, 10, 0.7)
	gl.EndList()

	gear3 = gl.GenLists(1)
	gl.NewList(gear3, gl.COMPILE)
	gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, blue)
	gear(1.3, 2.0, 0.5, 10, 0.7)
	gl.EndList()

	gl.Enable(gl.NORMALIZE)

	// Parse command line options

	info := flag.Bool("info", false, "Info")
	autoexit = flag.Int("exit", 30, "Auto Exit after n seconts\n")

	flag.Parse()

	if *info {
		fmt.Printf("gl.RENDERER   = %s\n", gl.GetString(gl.RENDERER))
		fmt.Printf("gl.VERSION    = %s\n", gl.GetString(gl.VERSION))
		fmt.Printf("gl.VENDOR     = %s\n", gl.GetString(gl.VENDOR))
		fmt.Printf("gl.EXTENSIONS = %s\n", gl.GetString(gl.EXTENSIONS))
		os.Exit(1)
	}
}
Example #2
0
func init_() {
	pos := []float32{5.0, 5.0, 10.0, 0.0}
	red := []float32{0.8, 0.1, 0.0, 1.0}
	green := []float32{0.0, 0.8, 0.2, 1.0}
	blue := []float32{0.2, 0.2, 1.0, 1.0}

	gl.Lightfv(gl.LIGHT0, gl.POSITION, pos)
	gl.Enable(gl.CULL_FACE)
	gl.Enable(gl.LIGHTING)
	gl.Enable(gl.LIGHT0)
	gl.Enable(gl.DEPTH_TEST)

	/* make the gears */
	gear1 = gl.GenLists(1)
	gl.NewList(gear1, gl.COMPILE)
	gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, red)
	gear(1.0, 4.0, 1.0, 20, 0.7)
	gl.EndList()

	gear2 = gl.GenLists(1)
	gl.NewList(gear2, gl.COMPILE)
	gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, green)
	gear(0.5, 2.0, 2.0, 10, 0.7)
	gl.EndList()

	gear3 = gl.GenLists(1)
	gl.NewList(gear3, gl.COMPILE)
	gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, blue)
	gear(1.3, 2.0, 0.5, 10, 0.7)
	gl.EndList()

	gl.Enable(gl.NORMALIZE)

	if *printInfo {
		print("GL_RENDERER   = ", gl.GetString(gl.RENDERER), "\n")
		print("GL_VERSION    = ", gl.GetString(gl.VERSION), "\n")
		print("GL_VENDOR     = ", gl.GetString(gl.VENDOR), "\n")
		print("GL_EXTENSIONS = ", gl.GetString(gl.EXTENSIONS), "\n")
	}

}
Example #3
0
// initGL initializes GLFW and OpenGL.
func initGL() (*glfw.Window, error) {
	if !glfw.Init() {
		log.Panic("glfw Error:")
	}

	var err error
	window, err = glfw.CreateWindow(768, 768, "My Own Shadertoy", nil, nil)
	if err != nil {
		glfw.Terminate()
		return nil, err
	}

	window.MakeContextCurrent()

	window.SetSizeCallback(onResize)

	window.SetKeyCallback(onKey)
	window.SetMouseButtonCallback(onMouse)
	window.SetCursorPositionCallback(onCursor)

	errno := gl.Init()
	if errno != gl.NO_ERROR {
		str, err := glu.ErrorString(errno)
		if err != nil {
			return nil, fmt.Errorf("Unknown openGL error: %d", errno)
		}
		return nil, fmt.Errorf(str)
	}

	gl.Enable(gl.TEXTURE_1D)
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.TEXTURE_3D)

	fmt.Printf("gl.RENDERER   = %s\n", gl.GetString(gl.RENDERER))
	fmt.Printf("gl.VERSION    = %s\n", gl.GetString(gl.VERSION))
	fmt.Printf("gl.VENDOR     = %s\n", gl.GetString(gl.VENDOR))
	fmt.Printf("gl.EXTENSIONS = %s\n", gl.GetString(gl.EXTENSIONS))

	return window, nil
}
Example #4
0
File: graf.go Project: pwaller/mema
func Init() {
	//gl.Enable(gl.DEPTH_TEST)

	var tmpmaxa []float32 = []float32{0}

	gl.GetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, tmpmaxa)
	MaxAnisotropy = tmpmaxa[0]
	log.Print("MaxAnisotropy: ", MaxAnisotropy)

	// Anti-aliasing
	gl.Enable(gl.LINE_SMOOTH)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	//gl.BlendFunc(gl.SRC_ALPHA, gl.DST_ALPHA)
	//gl.BlendFunc(gl.SRC_ALPHA_SATURATE, gl.ONE)
	gl.Hint(gl.LINE_SMOOTH_HINT, gl.NICEST)
	gl.Hint(gl.GENERATE_MIPMAP_HINT, gl.NICEST)

	extensions := gl.GetString(gl.EXTENSIONS)
	if !strings.Contains(extensions, "GL_ARB_framebuffer_object") {
		log.Panic("No FBO support :-(")
	}
}
Example #5
0
func main() {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	fmt.Println("OpenTibia Map Editor")

	conf := &Configuration{}
	conf.Load("config.json")

	var sprLoader client.SpriteLoader
	var datLoader client.DatLoader
	var itemLoader ot.ItemLoader
	//var otbLoader ot.OtbLoader
	//var otMap ot.Map

	var group sync.WaitGroup
	group.Add(3)

	go func() {
		if err := sprLoader.Load(conf.SprFile); err != nil {
			log.Fatal(err)
		}
		group.Done()
	}()
	go func() {
		if err := datLoader.Load(conf.DatFile); err != nil {
			log.Fatal(err)
		}
		group.Done()
	}()
	go func() {
		if err := itemLoader.LoadXML("items.xml"); err != nil {
			log.Fatal(err)
		}
		group.Done()
	}()
	/*
		go func() {
			if err := otbLoader.Load("items.otb"); err != nil {
				log.Fatal(err)
			}

			otMap.Initialize()
			if err := otMap.ReadOTBM("forgotten.otbm", &otbLoader); err != nil {
				log.Fatal(err)
			}

			group.Done()
		}()
	*/
	group.Wait()

	if !glfw.Init() {
		panic("Failed to initialize GLFW")
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.ContextVersionMajor, 3)
	glfw.WindowHint(glfw.ContextVersionMinor, 2)
	glfw.WindowHint(glfw.OpenglForwardCompatible, glfw.True)
	glfw.WindowHint(glfw.OpenglProfile, glfw.OpenglCoreProfile)

	window, err := glfw.CreateWindow(640, 480, "Map Editor", nil, nil)
	if err != nil {
		panic(err)
	}

	window.SetKeyCallback(keyHandler)

	window.MakeContextCurrent()

	if err := gl.Init(); err != 0 {
		log.Fatal("Could not init gl")
	}

	log.Printf("OpenGL Version: %s", gl.GetString(gl.VERSION))
	log.Printf("GLSL Version: %s", gl.GetString(gl.SHADING_LANGUAGE_VERSION))
	log.Printf("Vendor: %s", gl.GetString(gl.VENDOR))
	log.Printf("Renderer: %s", gl.GetString(gl.RENDERER))

	r := renderer.Renderer{}

	r.Initialize()
	r.SetViewport(0, 0, 800, 600)

	for !window.ShouldClose() {
		r.Render()

		window.SwapBuffers()
		glfw.PollEvents()
	}

	/*
		ids := datLoader.GetSpriteIDs(420)
		sprite := sprLoader.GetSprite(ids[0])

		img := image.NewNRGBA(image.Rect(0, 0, 32, 32))
		img.Pix = sprite

		out, _ := os.Create("test.png")
		defer out.Close()

		if err := png.Encode(out, img); err != nil {
			log.Fatal(err)
		}*/
}