U_time in oF with GLSL 1.2

Hello,

So, I’m even newer to GLSL than to oF and am trying to load a shader I made via a tutorial into oF. The shader is 023_morphGrid.frag, found in the attached zip. It works fine in the GLSL plugin I have for Atom and I can get it to appear in oF, but the image is static- it should be in motion via u_time.

This shader seems to be in the language of OpenGL 2 (GLSL 1.2) and I can get it to show with

	ofGLWindowSettings settings;
	settings.setGLVersion(1, 2);
	ofCreateWindow(settings);
ofRunApp(new ofApp());

or by just using the default

ofSetupOpenGL(1024,768,OF_WINDOW);

since GLSL 1.2 seems to be the default anyway. Also, since ofShader.load() asks for a .vert-file as well, I just Googled a basic GL 1.2 .vert file and renamed it to 023_morphGrid.vert. Maybe this is the problem?

I tried updating the u_time via oF by writing

void ofApp::update(){
	shader.setUniform1f("u_time", ofGetElapsedTimef());
}

but that doesn’t work either. Sorry that I’m not sure if this is a problem with my GLSL ignorance or my oF ignorance.

morphGridShader.zip (709 Bytes)

You need to call this between the shader.begin() and shader.end() calls. There is no need to do it in the update funciton. you can do it in ofApp::draw(). Where you should be already calling the begin and end funcs

That did it! Thanks, Roy!

1 Like