// newTexture will return a new generated texture will not data uploaded to it. func newTexture(width, height int32, mipmaps bool) *Texture { new_texture := &Texture{ textureId: gl.CreateTexture(), Width: width, Height: height, wrap: Wrap{s: WRAP_CLAMP, t: WRAP_CLAMP}, filter: newFilter(), mipmaps: mipmaps, } new_texture.SetFilter(FILTER_NEAREST, FILTER_NEAREST) new_texture.SetWrap(WRAP_CLAMP, WRAP_CLAMP) if new_texture.mipmaps { new_texture.filter.mipmap = states.back().defaultMipmapFilter new_texture.SetMipmapSharpness(states.back().defaultMipmapSharpness) } if new_texture.mipmaps { // Auto-generate mipmaps every time the texture is modified, if glGenerateMipmap isn't supported. setTexMipMap() } new_texture.generateVerticies() return new_texture }
// Set the 'default' texture (id 0) as a repeating white pixel. Otherwise, // texture2D calls inside a shader would return black when drawing graphics // primitives, which would create the need to use different "passthrough" // shaders for untextured primitives vs images. func createDefaultTexture() { gl_state.defaultTexture = gl.CreateTexture() bindTexture(gl_state.defaultTexture) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT) pix := []byte{255, 255, 255, 255} gl.TexImage2D(gl.TEXTURE_2D, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(pix)) }