Page MenuHome

BGE: Allow access to original texture openGL Bind code/Id/Number

Authored by Ulysse Martin (youle) on Feb 15 2016, 6:30 AM.



This patch adds a python method to get openGL bind code of material's texture according to the texture slot.

import bge

cont = bge.logic.getCurrentController()
own = cont.owner

bindId = own.meshes[0].materials[0].getTextureBindcode(0)
Test file:

This can be used to play with texture in openGL, for example, remove mipmap on the texture or play with all wrapping or filtering options.
And this can be used to learn openGL with Blender.

Diff Detail

rB Blender

Event Timeline

Ulysse Martin (youle) retitled this revision from to BGE: Allow access to original texture openGL Bind code/Id/Number.
Ulysse Martin (youle) updated this object.

I don't know in what case existing "bindId" attribute can be used. But I nevertheless replaced "OpenGL Bind Name" with "OpenGL Bind code/Id/Number" (I know that we don't have to make "unrelated" patch modifs but it's a small modification).

The patch can be used to learn how to use textures with openGL in Blender. I try to learn openGL and this is the main reason why I propose this patch. I think Blender Game Engine is not only a tool to make games, but can be a great tool to learn python, GLSL, openGL.

How is this property different from bindId? Taking a quick look at the source code, it looks like this is meant to be an OpenGL name. However, it looks like there are some cases where it has not been set. Could we just make sure m_actTex gets set in more cases?

Ulysse Martin (youle) edited edge metadata.

I changed the place of the code (moved from Texture.cpp to KX_BlenderMaterial.cpp) because of the discussion I had with Kupoman:

Sorry, a mistake in the previous patch.

Daniel Stokes (kupoman) edited edge metadata.

This looks better :)

This revision is now accepted and ready to land.Feb 17 2016, 3:55 AM
Diego Lopes (TwisterGE) edited edge metadata.

That's great!


It's normal to specify the argument type here ?


Same thing here for all prints and doc.

Ulysse Martin (youle) edited edge metadata.
Ulysse Martin (youle) marked 2 inline comments as done.

inline comments done

Mitchell Stokes (moguri) edited edge metadata.

Looks good to me.

This revision was automatically updated to reflect the committed changes.

We have a similar option for VideoTexture images if I remember correctly. There we have a direct access to the bind id without using a get method. Shouldn't we unify this?

@Dalai Felinto (dfelinto): This was my first intention to replace existing attribute (bindId) that returns m_actTex (dynamic texture generated in Texture.cpp) openGL binId with the original texture bind Id, because I don't understand in what case m_actTex can be useful.


  • I didn't want to break the API in the case someone used m_actTex
  • I had this discussion: with Kupoman that convinced me to move the code in KX_BlenderMaterial (We don't have to call Texture_Init method in Texture.cpp if the code is in KX_BlenderMaterial)