fragment shader opengl functions

I began to experiment with shaders and found some code online which lets you set texture wrapping modes in opengl glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); But it seems that I cannot use any of this gl* functions inside shaders.

Any ideas on this?

learnopengl.com/#!Getting-started/Textures

You can create your own texture wrapping using the fract function (returns the fractionl part of a float, eg the same as %1, except it can be “overloaded”, like all openGL functions, with a vector). eg:

lowp vec4 pixel = texture2D( texture, fract(vTexCoord) );

You then set the texCoords to be object position / texture size.

I’m sure I read somewhere that using fract isn’t necessary, if the texture is a multiple of 8 in size, eg 512 x 512. I haven’t tested this though.

I think I understood. thank you. So to answer my next question: it is not possible to use any of those opengl function calls inside shaders - right?

No, those are Open GLES commands, rather than Open GLES Shader Language commands, so they are taken care of by the Codea mesh/ shader API. Often there’ll be an equivalent command in the Codea API for the more commonly used Open GL commands, eg the mesh buffer commands, blendmode, or the frustrum settings in the perspective command (or the new support for instanced drawing added to Codea 2.3.2).

you helped me a lot! thank you sir!)))

You’re very welcome. @Ignatz 's ebooks / blog series on shaders and 3D are an excellent resource, if you haven’t already read them.

Generally, it’s not too hard to port most Open GL code you find online to Codea. The shader language is the same, and a lot of the time the Codea mesh API does everything you need. This ebook, tho aimed at Unity, is quite a good resource

https://en.wikibooks.org/wiki/GLSL_Programming/Unity

I saw his ebooks before, but wasn’t ready to take this step. now I am :slight_smile: - I will try my best with shaders, so thank you again for your kind help!

@se24vad - shaders are not as scary as they look, trust me. I am hopeless with C, but I managed ok.

Making a texture tile (i.e. repeat) itself over and over requires one line of shader code. I have it in my shader ebook, and it is my favorite line of code in all of
Codea, because it is so useful.

very kind of you @Ignatz, thank you very much. the community is the best part of codea: so helpful and so much friendly!

agreed, the community here is fantastic