Beispiel #1
0
// setTextureUnit activates a texture unit
func setTextureUnit(textureunit int) error {
	if textureunit < 0 || textureunit >= len(gl_state.boundTextures) {
		return fmt.Errorf("Invalid texture unit index (%v).", textureunit)
	}

	if textureunit != gl_state.curTextureUnit {
		gl.ActiveTexture(gl.Enum(gl.TEXTURE0 + uint32(textureunit)))
	}

	gl_state.curTextureUnit = textureunit
	return nil
}
Beispiel #2
0
// InitContext will initiate the opengl context with a viewport in the size of
// w x h. This is generally called from the game loop and wont generally need to
// be called unless you are rolling your own game loop.
func InitContext(w, h int32) {
	if gl_state.initialized {
		return
	}

	// Okay, setup OpenGL.
	gl.ContextWatcher.OnMakeCurrent(nil)

	//Get system info
	opengl_version = gl.GetString(gl.VERSION)
	opengl_vendor = gl.GetString(gl.VENDOR)
	gl_state.defaultFBO = gl.GetBoundFramebuffer()
	gl.GetIntegerv(gl.VIEWPORT, gl_state.viewport)
	// And the current scissor - but we need to compensate for GL scissors
	// starting at the bottom left instead of top left.
	gl.GetIntegerv(gl.SCISSOR_BOX, states.back().scissorBox)
	states.back().scissorBox[1] = gl_state.viewport[3] - (states.back().scissorBox[1] + states.back().scissorBox[3])

	initMaxValues() //check shim code

	glcolor := []float32{1.0, 1.0, 1.0, 1.0}
	gl.VertexAttrib4fv(attrib_color, glcolor)
	gl.VertexAttrib4fv(attrib_constantcolor, glcolor)
	useVertexAttribArrays(0)

	// Enable blending
	gl.Enable(gl.BLEND)
	SetBlendMode(BLENDMODE_ALPHA)
	// Auto-generated mipmaps should be the best quality possible
	gl.Hint(gl.GENERATE_MIPMAP_HINT, gl.NICEST)
	// Make sure antialiasing works when set elsewhere
	enableMultisample() //check shim code
	// Set pixel row alignment
	gl.PixelStorei(gl.UNPACK_ALIGNMENT, 1)

	//default matricies
	gl_state.projectionStack = matstack.NewMatStack()
	gl_state.viewStack = matstack.NewMatStack() //stacks are initialized with ident matricies on top

	SetViewportSize(w, h)
	SetBackgroundColor(0, 0, 0, 255)

	gl_state.boundTextures = make([]gl.Texture, maxTextureUnits)
	curgltextureunit := gl.GetInteger(gl.ACTIVE_TEXTURE)
	gl_state.curTextureUnit = int(curgltextureunit - gl.TEXTURE0)
	// Retrieve currently bound textures for each texture unit.
	for i := 0; i < len(gl_state.boundTextures); i++ {
		gl.ActiveTexture(gl.Enum(gl.TEXTURE0 + uint32(i)))
		gl_state.boundTextures[i] = gl.Texture{Value: uint32(gl.GetInteger(gl.TEXTURE_BINDING_2D))}
	}
	gl.ActiveTexture(gl.Enum(curgltextureunit))
	createDefaultTexture()
	setTextureUnit(0)

	// We always need a default shader.
	defaultShader = NewShader()

	gl_state.initialized = true

	loadAllVolatile()

	//have to set this after loadallvolatile() so we are sure the  default shader is loaded
	SetShader(nil)
}