Exemple #1
0
func init_() {
	//pos := []float64{5.0, 5.0, 10.0, 0.0}

	colors := map[string][]float32{
		"0": {0.7, 0.7, 0.7, 1.0},
		"1": {1.0, 0.0, 0.0, 1.0},
		"2": {1.0, 0.6, 0.0, 1.0},
		"3": {1.0, 1.0, 0.0, 1.0},
		"4": {0.0, 1.0, 0.0, 1.0},
		"5": {0.0, 0.0, 1.0, 1.0},
		"6": {0.0, 0.6, 1.0, 1.0},
		"7": {1.0, 0.0, 1.0, 1.0},
		"8": {1.0, 1.0, 1.0, 1.0},
		"9": {0.3, 0.3, 0.3, 1.0},
	}

	fetchChunks(2, 2)

	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0.2, 0.2, 0.6, 0.0)
	gl.ClearDepth(1.0)

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LEQUAL)
	gl.Enable(gl.COLOR_MATERIAL)
	gl.Enable(gl.CULL_FACE)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
	gl.Hint(gl.LINE_SMOOTH_HINT, gl.NICEST)

	gl.Lightfv(gl.LIGHT0, gl.AMBIENT, lightAmbient)
	gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, lightDiffuse)
	gl.Lightfv(gl.LIGHT0, gl.POSITION, lightPosition)
	gl.Enable(gl.LIGHT0)
	gl.Enable(gl.LIGHTING)

	for name, color := range colors {
		/* make a cube */
		cubes[name] = gl.GenLists(1)
		gl.NewList(cubes[name], gl.COMPILE)
		cube(color)
		gl.EndList()
	}

	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")
	}

}
Exemple #2
0
func initGL() {
	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0, 0, 0, 0)
	gl.ClearDepth(1)
	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LEQUAL)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
}
// general OpenGL initialization
func initGL() {
	LoadGLTexture("data/star.bmp")

	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE)
	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0.0, 0.0, 0.0, 0.5)
	gl.ClearDepth(1.0)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
}
Exemple #4
0
func SetupVideo() {

	if sdl.Init(sdl.INIT_VIDEO) < 0 {
		panic("Couldn't initialize sdl")
	}

	w := WinW
	h := WinH

	var screen = sdl.SetVideoMode(w, h, 32, SDL_FLAGS)

	//	var screen = sdl.SetVideoMode(w, h, 32, sdl.OPENGLBLIT | sdl.DOUBLEBUF | sdl.HWSURFACE)
	//	var screen = sdl.SetVideoMode(w, h, 32, sdl.OPENGL)

	if screen == nil {
		panic("sdl error")
	}

	if ttf.Init() != 0 {
		panic("ttf init error")
	}

	if gl.Init() != 0 {
		panic("Couldn't init gl")
	}

	ResizeWindow(screen.W, screen.H)

	gl.ClearColor(0, 0, 0, 0)
	//	gl.ClearColor(1, 1, 1, 0)
	gl.ClearDepth(1.0)
	gl.DepthFunc(gl.LEQUAL)
	gl.Enable(gl.DEPTH_TEST)
	gl.ShadeModel(gl.SMOOTH)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)

	/*
		if gl.Init() != 0 {
			panic("glew error")
		}
	*/
	//	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT )

	// gl.Clear(gl.COLOR_BUFFER_BIT)

	// initGL

	// gl.Ortho(0, gl.GLdouble(screen.W), gl.GLdouble(screen.H), 0, -1.0, 1.0)

}
// general OpenGL initialization
func initGL() {
  gl.Enable(gl.TEXTURE_2D)
  gl.ShadeModel(gl.SMOOTH)
  gl.ClearColor(0.0, 0.0, 0.0, 0.5)
  gl.ClearDepth(1.0)
  gl.Enable(gl.DEPTH_TEST)
  gl.DepthFunc(gl.LEQUAL)
  gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)

  // Setup the light
  gl.Lightfv(gl.LIGHT1, gl.AMBIENT, lightAmbient[:]) // ambient lighting
  gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, lightDiffuse[:]) // make it diffuse
  gl.Lightfv(gl.LIGHT1, gl.POSITION, lightPosition[:]) // and place it
  gl.Enable(gl.LIGHT1) // and finally turn it on.

  gl.Color4f(1.0, 1.0, 1.0, 0.5) // Full Brightness, 50% Alpha ( NEW )
  gl.BlendFunc(gl.SRC_ALPHA, gl.ONE) // Blending Function For Translucency Based On Source Alpha Value ( NEW )
}
// general OpenGL initialization
func initGL() {
	// enable smooth shading
	gl.ShadeModel(gl.SMOOTH)

	// Set the background to black
	gl.ClearColor(0.0, 0.0, 0.0, 0.0)

	// Depth buffer setup
	gl.ClearDepth(1.0)

	// Enable depth testing
	gl.Enable(gl.DEPTH_TEST)

	// The type of test
	gl.DepthFunc(gl.LEQUAL)

	// Nicest perspective correction
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
}
// general OpenGL initialization
func initGL() {
	LoadGLTextures("data/mud.bmp")

	gl.Enable(gl.TEXTURE_2D)
	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0.0, 0.0, 0.0, 0.0)
	gl.ClearDepth(1.0)
	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LEQUAL)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)

	gl.Lightfv(gl.LIGHT1, gl.AMBIENT, lightAmbient[:])
	gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, lightDiffuse[:])
	gl.Lightfv(gl.LIGHT1, gl.POSITION, lightPosition[:])
	gl.Enable(gl.LIGHT1)

	gl.Color4f(1.0, 1.0, 1.0, 0.5)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE)
}
// general OpenGL initialization
func initGL() {
	gl.Enable(gl.TEXTURE_2D)
	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0.0, 0.0, 0.0, 0.5)
	gl.ClearDepth(1.0)
	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LEQUAL)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)

	// Setup the light
	gl.Lightfv(gl.LIGHT1, gl.AMBIENT, lightAmbient1[:])   // ambient lighting
	gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, lightDiffuse1[:])   // make it diffuse
	gl.Lightfv(gl.LIGHT1, gl.POSITION, lightPosition1[:]) // and place it
	gl.Enable(gl.LIGHT1)                                  // and finally turn it on.

	gl.Lightfv(gl.LIGHT2, gl.AMBIENT, lightAmbient2[:])   // ambient lighting
	gl.Lightfv(gl.LIGHT2, gl.DIFFUSE, lightDiffuse2[:])   // make it diffuse
	gl.Lightfv(gl.LIGHT2, gl.POSITION, lightPosition2[:]) // and place it
	gl.Enable(gl.LIGHT2)                                  // and finally turn it on.
}
Exemple #9
0
func main() {
	//ABSPTest()
	//return
	glfw.Init(800, 600)
	InitPhysics()

	world := new(World)
	world.Init()
	world.GameObjects = new(list.List)
	player := MakeMan(Vec3{10, 20, 10})

	world.Add(player)
	world.Add(ropetest(Vec3{0, 40, 0}, 4, 4))
	world.Add(treeThing(Vec3{20, 20, 20}, 3))
	world.Add(MakePlayer(Vec3{-20, 20, 0}).Body)
	world.Add(MakePlayer(Vec3{-20, 50, 0}).Body)

	world.Add(MakePlayer(Vec3{-20, 70, 0}).Body)
	world.Add(MakePlayer(Vec3{-20, 90, 0}).Body)
	world.Add(MakePlayer(Vec3{-20, 110, 0}).Body)
	/*for i := 0; i < 100; i++ {
		world.Add(SetPlayerAnimation(MakePlayer(Vec3{float32(int(i%10))*50,0,float32(i*2) - 200})).Body)
	}*/
	world.Add(NewGameObj(Vec3{0, -20, 0}, Vec3{10000, 10, 10000}, Vec3{0, 0.5, 0.1}, float32(math.Inf(1)), 10, nil))

	//world.Add(SetPlayerAnimation(MakePlayer(Vec3{-20,120,0})).Body)

	qtn := new(ABSPNode)
	qtn.Root = qtn
	//qtn.Position = Vec3{-10000,-10000,-10000}
	//qtn.Size = Vec3{20000,20000,20000}
	for i := world.GameObjects.Front(); i != nil; i = i.Next() {
		gobj := i.Value.(*GameObj)
		all := gobj.GetSubs()
		for i := 0; i < len(all); i++ {
			qtn.Insert(all[i])
		}
	}
	world.GameObjectTree = qtn
	fmt.Println("Total:", len(qtn.Data))
	qtn.Divide()
	cols := 0
	qtn.cd(func(obj1, obj2 SPData) {
		cols += 1
	})
	fmt.Println(cols)
	//qtn.Traverse(0)
	//return
	gl.Init()
	vs := gl.CreateShader(gl.VERTEX_SHADER)
	vs.Source(
		LoadFileToString("s1.vert"))
	vs.Compile()

	fs := gl.CreateShader(gl.FRAGMENT_SHADER)
	fs.Source(LoadFileToString("s1.frag"))
	fs.Compile()

	pg := gl.CreateProgram()
	pg.AttachShader(vs)
	pg.AttachShader(fs)
	pg.Link()
	pg.Validate()

	pg.Use()
	fmt.Println("**Shader log**")
	fmt.Println(fs.GetInfoLog())
	fmt.Println(vs.GetInfoLog())
	fmt.Println(pg.GetInfoLog())
	fmt.Println("******END*****")

	gl.ClearColor(0.5, 0.5, 1, 0)
	gl.Enable(gl.DEPTH_TEST)
	gl.Enable(gl.BLEND)
	gl.Enable(gl.POLYGON_SMOOTH)
	gl.Hint(gl.POLYGON_SMOOTH_HINT, gl.NICEST)

	var t float64
	t = float64(time.Nanoseconds()) / 1000000000
	cam1 := Camera{player, 100, Vec3{0, 0, 0}}
	glfw.AddListener(func(m glfw.MouseMoveEvent) {
		cam1.Angle.X = float32(m.X-400) / 400 * 3.14 * 2
		cam1.Angle.Y = float32(m.Y-300) / 300 * 3.14 * 2
		//player.Rotation = Vec3{cam1.Angle.X,cam1.Angle.Y,0}
	})
	glfw.AddListener(func(mw glfw.MouseWheelEvent) {
		cam1.Distance = 100 + float32(mw.Pos*mw.Pos*mw.Pos)
	})

	world.CompilePhysicsObjects()
	for it := 0; it < 10000; it += 1 {
		cam1.Setup()
		dt := float32(0.005)
		t = float64(float64(time.Nanoseconds()) / 1000000000)
		UpdatePositions(world.PhysicsObjects, dt)

		UpdateModelStates(world.PhysicsObjects)

		UpdateCollisions(world.GameObjectTree, dt)
		UpdateModelStates(world.PhysicsObjects)
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		DrawWorld(world.GameObjects, dt, pg)
		glfw.SwapBuffers()
		pt := float64(float64(time.Nanoseconds()) / 1000000000)
		sleeptime := (float64(dt) - (pt - t)) * 10e8
		fmt.Println("Sleep for:", sleeptime)
		time.Sleep(int64(sleeptime))
	}

}