About Monkey 2 › Forums › Monkey 2 Programming Help › Mark: Texture shader problem ;(
This topic contains 4 replies, has 2 voices, and was last updated by 
 AdamStrange
 1 year, 8 months ago.
- 
		AuthorPosts
 - 
		
			
				
July 27, 2017 at 11:21 am #9552
I’ve got shaders and i’ve got textures
The texture is a Mojo/Graphics/Texture:
tex:Textur = Texture.Load( “asset::chars64x64_font.png”, TextureFlags.Dynamic )
it uses:
tex.Bind( 0 )
to bind the texture to the shader
the shader is custom, but uses:
uniform sampler2D TextureSampler;
in the fragment to get the texture
How do I bind tex2 to the shader?
I know it would be Tex2.Bind(1)
But it would need a uniform name for the shader to find it.
What would you suggest is the right way to do this? I know it has something to do with Texture.ValidateGLTexture(), but can’t fathom where the text would be put?
anyone have any suggestions?
July 27, 2017 at 9:27 pm #9561Youi need to use glGetUniformLocation to get the location of the texture from the shader, then glUniform1( n ) to set this uniform to the texture unit the texture is bound to.
Do not use Texture.Bind(), this is very much part of the mojo shader system and will change in future. I will also be making it ‘Internal’ soon (along with a bunch of other @hidden stuff) now that I have ‘Internal’.
Instead, use ValidateGLTexture() to retrieve the gl texture handle and glActiveTexture to select the unit you want to bind it to. So the whole process is something like:
Local unit:=0 ‘up to you < GL_MAX_TEXTURES or whatever it is…
Local location:=glGetUniformLocation( program,”SamplerNameInShader” )glUseProgram( program )
glUniform1i( location,unit )
glActiveTexture( GL_TEXTURE0+unit )
glBindTexture( GL_TEXTURE_2D,texture.ValidateGLTexture() )July 28, 2017 at 5:22 am #9569thanks Mark. I’m looking into the code snippet above and will report
July 28, 2017 at 6:18 am #9571Brilliant… After a bit of tweaking and working out where best to put things it worked – 2 textures YAY
Small question about the Texture class.
How would I copy an Image into a Texture?
I would like to have one of the Textures updated regularly with the contentment from an Image
i’m currently using:
_image.GetTexture(0).ValidateGLTexture()
is this correct?
July 28, 2017 at 7:24 am #9572OK. Heres the result i was looking for:

this is NOT a traditional shadow caster. is is operating in 2d and then being combined in 3d taking the 2d dimensions.
it should be able to handle many (well around 50-150) point lights without affecting fps. I will need to do trials now
the FPS is a rock solid 60 – not 6 (the 0 got clipped)!
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.