Exemplo n.º 1
0
func NewSpriteDrawer(window *glfw.Window, layers int) *SpriteDrawer {
	s := new(SpriteDrawer)

	vao := gl.GenVertexArray()
	vao.Bind()

	s.Camera = vec2.Identity

	s.Program = CreateProgram("shaders/2d.vert", "shaders/2d.geom", "shaders/texture.frag")
	s.Use()
	s.camera_uniform = s.GetUniformLocation("camera")

	s.Texture = gl.GenTexture()
	s.Texture.Bind(gl.TEXTURE_2D_ARRAY)
	gl.TexImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA, 2048, 2048, layers, 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
	gl.TexParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.LINEAR)

	s.Window = window
	w, h := window.GetSize()
	s.OnScreenResize(w, h)

	s.Window.SetSizeCallback(func(window *glfw.Window, w, h int) {
		s.OnScreenResize(w, h)
	})

	return s
}
Exemplo n.º 2
0
func (t *Texture) Options(filter, clamp int) {
	t.Bind()
	gl.TexParameteri(t.target, gl.TEXTURE_MIN_FILTER, filter)
	gl.TexParameteri(t.target, gl.TEXTURE_MAG_FILTER, filter)
	gl.TexParameteri(t.target, gl.TEXTURE_WRAP_S, clamp)
	gl.TexParameteri(t.target, gl.TEXTURE_WRAP_T, clamp)
}
Exemplo n.º 3
0
func (v *Video) initGL() {
	if gl.Init() != 0 {
		panic(sdl.GetError())
	}

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.Enable(gl.CULL_FACE)
	gl.Enable(gl.DEPTH_TEST)

	v.prog = createProgram(vertShaderSrcDef, fragShaderSrcDef)
	posAttrib := v.prog.GetAttribLocation("vPosition")
	texCoordAttr := v.prog.GetAttribLocation("vTexCoord")
	v.textureUni = v.prog.GetAttribLocation("texture")

	v.texture = gl.GenTexture()
	gl.ActiveTexture(gl.TEXTURE0)
	v.texture.Bind(gl.TEXTURE_2D)

	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

	v.prog.Use()
	posAttrib.EnableArray()
	texCoordAttr.EnableArray()

	vertVBO := gl.GenBuffer()
	vertVBO.Bind(gl.ARRAY_BUFFER)
	verts := []float32{-1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0}
	gl.BufferData(gl.ARRAY_BUFFER, len(verts)*int(unsafe.Sizeof(verts[0])), &verts[0], gl.STATIC_DRAW)

	textCoorBuf := gl.GenBuffer()
	textCoorBuf.Bind(gl.ARRAY_BUFFER)
	texVerts := []float32{0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}
	gl.BufferData(gl.ARRAY_BUFFER, len(texVerts)*int(unsafe.Sizeof(texVerts[0])), &texVerts[0], gl.STATIC_DRAW)

	posAttrib.AttribPointer(2, gl.FLOAT, false, 0, uintptr(0))
	texCoordAttr.AttribPointer(2, gl.FLOAT, false, 0, uintptr(0))
}
Exemplo n.º 4
0
func (this *FrameBuffer) Resize(width, height int) {
	//this.Framebuffer.Bind()
	// this.RenderTexture := gl.GenTexture()
	this.RenderTexture.Bind(gl.TEXTURE_RECTANGLE)
	gl.TexImage2D(gl.TEXTURE_RECTANGLE, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
	gl.TexParameteri(gl.TEXTURE_RECTANGLE, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_RECTANGLE, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	this.RenderTexture.Unbind(gl.TEXTURE_RECTANGLE)

	// depthStencilTexture := gl.GenTexture()
	this.DepthTexture.Bind(gl.TEXTURE_RECTANGLE)
	gl.TexImage2D(gl.TEXTURE_RECTANGLE, 0, gl.DEPTH24_STENCIL8, width, height, 0, gl.DEPTH_STENCIL, gl.UNSIGNED_INT_24_8, nil)
	gl.TexParameteri(gl.TEXTURE_RECTANGLE, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_RECTANGLE, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_RECTANGLE, gl.TEXTURE_WRAP_S, gl.CLAMP)
	gl.TexParameteri(gl.TEXTURE_RECTANGLE, gl.TEXTURE_WRAP_T, gl.CLAMP)
	this.DepthTexture.Unbind(gl.TEXTURE_RECTANGLE)
}
Exemplo n.º 5
0
func NewTextures(heightMap *gamestate.HeightMap) *Textures {
	textures := make([]gl.Texture, 10)
	gl.GenTextures(textures)

	gl.ActiveTexture(gl.TEXTURE0 + constants.TextureGround)
	textures[1].Bind(gl.TEXTURE_2D)
	helpers.LoadTexture2DWatched("textures/GravelCobbleS.jpg")
	gl.GenerateMipmap(gl.TEXTURE_2D)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_R, gl.REPEAT)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)

	gl.ActiveTexture(gl.TEXTURE0 + constants.TextureCliffs)
	textures[2].Bind(gl.TEXTURE_2D)
	helpers.LoadTexture2DWatched("textures/Cliffs0149_18_S.png")
	gl.GenerateMipmap(gl.TEXTURE_2D)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_R, gl.REPEAT)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)

	gl.ActiveTexture(gl.TEXTURE0 + constants.TextureColorBand)
	textures[3].Bind(gl.TEXTURE_1D)
	helpers.LoadTexture1DWatched("textures/gradient.png")
	gl.TexParameteri(gl.TEXTURE_1D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_1D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)

	gl.ActiveTexture(gl.TEXTURE0 + constants.TextureHeightMap)
	textures[4].Bind(gl.TEXTURE_2D)
	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.R16, heightMap.W, heightMap.H, 0, gl.RED, gl.FLOAT, heightMap.TexturePixels())
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)

	gl.ActiveTexture(gl.TEXTURE0 + constants.TextureTree)
	textures[5].Bind(gl.TEXTURE_2D)
	helpers.LoadTexture2DWatched("textures/palme.png")
	gl.GenerateMipmap(gl.TEXTURE_2D)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)

	gl.ActiveTexture(gl.TEXTURE0 + constants.TextureFireBall)
	textures[6].Bind(gl.TEXTURE_2D)
	helpers.LoadTexture2DWatched("textures/fireball.png")
	gl.GenerateMipmap(gl.TEXTURE_2D)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)

	gl.ActiveTexture(gl.TEXTURE0 + constants.TextureSkybox)
	textures[7].Bind(gl.TEXTURE_CUBE_MAP)
	helpers.LoadTextureCubeWatched("textures/Above_The_Sea.jpg")
	gl.GenerateMipmap(gl.TEXTURE_CUBE_MAP)
	gl.TexParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
	gl.TexParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	//gl.TexParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_R, gl.CLAMP_TO_EDGE)
	gl.TexParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	gl.TexParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
	gl.Enable(gl.TEXTURE_CUBE_MAP_SEAMLESS)

	ttf.Init()
	defer ttf.Quit()
	font, _ := ttf.OpenFont("fonts/Symbola.ttf", 64)
	color := sdl.Color{255, 255, 255, 255}
	surface, _ := font.RenderUTF8_Blended("Bla", color)
	defer surface.Free()
	gl.ActiveTexture(gl.TEXTURE0 + constants.TextureFont)
	textures[8].Bind(gl.TEXTURE_2D)
	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int(surface.W), int(surface.H), 0, gl.RGBA, gl.UNSIGNED_BYTE, uintptr(surface.Data()))
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)

	gl.ActiveTexture(gl.TEXTURE0)
	return &Textures{textures}
}
Exemplo n.º 6
0
func (t *Texture) SetWraping(wrapType WrapType, wrap Wrap) {
	t.Bind()
	gl.TexParameteri(t.target, gl.GLenum(wrapType), int(wrap))
}
Exemplo n.º 7
0
func (t *Texture) SetFiltering(minFilter Filter, magFilter Filter) {
	t.Bind()
	gl.TexParameteri(t.target, gl.TEXTURE_MAG_FILTER, int(magFilter))
	gl.TexParameteri(t.target, gl.TEXTURE_MIN_FILTER, int(minFilter))
}
Exemplo n.º 8
0
func (t *Texture) Param(filter, value int) {
	t.Bind()
	gl.TexParameteri(t.target, gl.GLenum(filter), value)
}