コード例 #1
0
ファイル: game.go プロジェクト: TimothyKlim/mandala-examples
func newGameState(window mandala.Window) *gameState {
	s := new(gameState)
	s.window = window

	s.window.MakeContextCurrent()

	w, h := window.GetSize()

	s.world = newWorld(w, h)

	// Create the building reading it from a string
	rand.Seed(int64(time.Now().Nanosecond()))

	// Uncomment the following lines to generate the world
	// starting from a string (defined in world.go)

	// s.world.createFromString(pyramid)
	// s.world.setGround(newGround(0, float32(10), float32(w), float32(10)))

	s.world.createFromSvg("raw/world.svg")

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	return s
}
コード例 #2
0
ファイル: game.go プロジェクト: remogatto/mozaik
func draw() {
	// Draw
	gl.ClearColor(0.9, 0.85, 0.46, 0.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	w := g.world
	w.background.Draw()
}
コード例 #3
0
// NewGameState creates a new game state. It needs a window onto which
// render the scene.
func NewGameState(window mandala.Window) *GameState {
	s := new(GameState)
	s.window = window

	s.window.MakeContextCurrent()

	w, h := window.GetSize()

	s.World = NewWorld(w, h)

	s.Fps = DefaultFps

	// Uncomment the following lines to generate the world
	// starting from a string (defined in world.go)

	// s.World.CreateFromString(pyramid)
	// s.World.setGround(newGround(s.World, 0, float32(10), float32(w), float32(10)))

	s.World.CreateFromSvg("raw/world.svg")

	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	return s
}
コード例 #4
0
ファイル: testlib.go プロジェクト: kebo/gorgasm
func (renderState *renderState) init(window gorgasm.Window) {
	window.MakeContextCurrent()

	renderState.window = window
	width, height := window.GetSize()

	// Set the viewport
	gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height))
	check()

	// Compile the shaders
	program := Program(FragmentShader(fsh), VertexShader(vsh))
	gl.UseProgram(program)
	check()

	// Get attributes
	attrPos = uint32(gl.GetAttribLocation(program, "pos"))
	attrTexIn = uint32(gl.GetAttribLocation(program, "texIn"))
	unifTexture = gl.GetUniformLocation(program, "texture")
	gl.EnableVertexAttribArray(attrPos)
	gl.EnableVertexAttribArray(attrTexIn)
	check()

	// Upload vertices data
	gl.GenBuffers(1, &verticesArrayBuffer)
	gl.BindBuffer(gl.ARRAY_BUFFER, verticesArrayBuffer)
	gl.BufferData(gl.ARRAY_BUFFER, gl.SizeiPtr(len(vertices))*4, gl.Void(&vertices[0]), gl.STATIC_DRAW)
	check()

	// Upload texture data
	img, err := loadImage(GOPHER_PNG)
	if err != nil {
		panic(err)
	}

	// Prepare the image to be placed on a texture.
	bounds := img.Bounds()
	imgWidth, imgHeight := bounds.Size().X, bounds.Size().Y
	buffer := make([]byte, imgWidth*imgHeight*4)
	index := 0
	for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
		for x := bounds.Min.X; x < bounds.Max.X; x++ {
			r, g, b, a := img.At(x, y).RGBA()
			buffer[index] = byte(r)
			buffer[index+1] = byte(g)
			buffer[index+2] = byte(b)
			buffer[index+3] = byte(a)
			index += 4
		}
	}

	gl.GenTextures(1, &textureBuffer)
	gl.BindTexture(gl.TEXTURE_2D, textureBuffer)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.Sizei(imgWidth), gl.Sizei(imgHeight), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Void(&buffer[0]))
	check()

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
}
コード例 #5
0
ファイル: testlib.go プロジェクト: remogatto/gltext
func (renderState *renderState) init(window mandala.Window) {
	window.MakeContextCurrent()

	renderState.window = window
	width, height := window.GetSize()

	// Set the viewport
	gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height))
	gl.ClearColor(0.0, 0.0, 1.0, 1.0)
}
コード例 #6
0
ファイル: testlib.go プロジェクト: leonardyp/mandala
func (renderState *renderState) init(window mandala.Window) {
	window.MakeContextCurrent()

	renderState.window = window
	width, height := window.GetSize()

	// Set the viewport
	gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height))
	check()

	// Compile the shaders
	program := shaders.NewProgram(fsh, vsh)
	program.Use()
	check()

	// Get attributes
	attrPos = program.GetAttribute("pos")
	attrTexIn = program.GetAttribute("texIn")
	unifTexture = program.GetUniform("texture")
	gl.EnableVertexAttribArray(attrPos)
	gl.EnableVertexAttribArray(attrTexIn)
	check()

	// Upload texture data
	img, err := loadImage(GOPHER_PNG)
	if err != nil {
		panic(err)
	}

	// Prepare the image to be placed on a texture.
	bounds := img.Bounds()
	imgWidth, imgHeight := bounds.Size().X, bounds.Size().Y
	buffer := make([]byte, imgWidth*imgHeight*4)
	index := 0
	for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
		for x := bounds.Min.X; x < bounds.Max.X; x++ {
			r, g, b, a := img.At(x, y).RGBA()
			buffer[index] = byte(r)
			buffer[index+1] = byte(g)
			buffer[index+2] = byte(b)
			buffer[index+3] = byte(a)
			index += 4
		}
	}

	gl.GenTextures(1, &textureBuffer)
	gl.BindTexture(gl.TEXTURE_2D, textureBuffer)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.Sizei(imgWidth), gl.Sizei(imgHeight), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Void(&buffer[0]))
	check()

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
}
コード例 #7
0
ファイル: world.go プロジェクト: remogatto/mandala-examples
func NewWorld(width, height int) *World {
	gl.Enable(gl.DEPTH_TEST)
	gl.ClearColor(0.0, 0.0, 0.0, 0.0)
	gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height))

	return &World{
		Width:      width,
		Height:     height,
		objects:    make([]*Cube, 0),
		projection: mathgl.Perspective(60, float32(width)/float32(height), 1, 20),
		view:       mathgl.Ident4f(),
	}
}
コード例 #8
0
ファイル: testlib.go プロジェクト: remogatto/shapes
func (renderState *renderState) init(window mandala.Window) {
	window.MakeContextCurrent()

	renderState.window = window
	width, height := window.GetSize()

	// Set the viewport
	gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height))
	gl.ClearColor(0.0, 0.0, 0.0, 1.0)

	renderState.boxProgram = shaders.NewProgram(shapes.DefaultBoxFS, shapes.DefaultBoxVS)
	renderState.segmentProgram = shaders.NewProgram(shapes.DefaultSegmentFS, shapes.DefaultSegmentVS)
}
コード例 #9
0
ファイル: game.go プロジェクト: remogatto/mandala-examples
func draw() {
	gl.ClearColor(1.0, 0.0, 0.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
}