Can I use sampler2D in ofShader?

Hi,

I tried to use ofShader in my program.
In the fragment shader, I use sampler2D rather than sampler2DRect to fetch from textures .
But it always turns out wrong.

Then i checked the source code of ofShader, ofTexture and ofTextureData and found that ofTextureData::textureTarget was always GL_TEXTURE_RECTANGLE. Then I tried to modify it by GL_TEXTURE2D at runtime, but my shader didn’t run correctly neither. Does it means I can only fetch texture using sampler2DRect in shaders?

If it is true currently, I strongly suggest that the code to be revised to accomodate the use of any texture target types in shaders, which are GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_1D_ARRAY, GL_TEXTURE_2D_ARRAY, GL_TEXTURE_RECTANGLE, GL_TEXTURE_CUBE_MAP, GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BUFFER, GL_TEXTURE_2D_MULTISAMPLE or GL_TEXTURE_2D_MULTISAMPLE_ARRAY.

Have you tried ofDisableArbTex() ? Not sure how well it is supported, but in theory it should let you use GL_TEXTURE_2D

By default OF uses ARB textures, which let you use non-power-of-2 sizes. To optimize memory textures were limited to 64x64 or 256x256, but ARB lets you use different sizes. To use GL_TEXTURE2D you want to set ofDisableArbTex() as pants mentioned and then also make sure that your images are power of two sized. There’s more info on POT here: http://www.katsbits.com/tutorials/textures/make-better-textures-correct-size-and-power-of-two.php

Thanks! I’ll try this solution! :slight_smile: