How to write to a texture in a compute shader?

Any advice?
I am trying to write a compute shader that modifies a texture that is later used as a ‘conventional’ texture/sampler2D in the rendering shader. The render shader applies the textures to a vbo mesh in the usual vert/frag way:

ofApp::setup(){
    ofDisableArbTex();
    ...
    ofFboTex->getTexture().loadData(simworld_colors.data(), worldSize.x, worldSize.y, GL_RGB);
}

ofApp::draw(){
   ...
   shaderRender.begin();
   shaderRender.setUniformTexture("tex0", ofFboTex->getTexture(), 0);
   vboTerrain.draw();
}

renderShader.frag.glsl:
uniform sampler2D tex0;
main(){
    out_fragColor = texture(tex0, vary_texCoord);
}

This part is working.

Before the draw/render I want my compute shader to modify the texture.
It needs to do something like… what?

ofApp::update(){
    ...
    shaderCompute.begin();
    // This seems wrong...
    shaderCompute.setUniformTexture("tex0", ofFboTex->getTexture(), 0);
    // or this?
    ofFboTex->getTexture().bindAsImage(0, GL_WRITE_ONLY);
    shader.dispatchCompute(worldSize.x, worldSize.y);
}

computeShader.compute.glsl:
layout(local_size_x = 1, local_size_y = 1) in;
layout(rgba32f, binding=0) uniform writeonly image2D tex0;
main(){
    texPos = ivec2(2, 2); //calcTexCoord(gl_GlobalInvocationID, ...);
    newColor = vec4(1.0, 1.0, 0.0, 1.0);; //computeColor(...);
    imageStore(tex0, texPos, newColor);
}

But this does not seem to affect the texture buffer.

I have looked at a few examples:
How vert/frag shader can behave like compute unit by doing ping-pong renders to a texture as in
examples/gl/gpuParticleSystemExample
This is how my code currently works.

How a compute shader can do ping-pong writes to a image2D as in
examples/gl/computeShaderTextureExample
This is very close to how I want my code to work, I just want to write to an ‘actual texture’.

How a compute shader can write to ofVbo mesh color attributes as in
examples/gl/computeShaderParticlesExample
But I don’t want to write vertex color attributes.

Some things to help you proceed.

shaderCompute.begin();

Do not forget to use shaderCompute.end(); after dispatchCompute.

    // This seems wrong...
    shaderCompute.setUniformTexture("tex0", ofFboTex->getTexture(), 0);
    // or this?
    ofFboTex->getTexture().bindAsImage(0, GL_WRITE_ONLY);

The latter is correct and only works for compute shaders. Here you tell OpenGL to write to ofFboTex.

If that doesn’t work, please share the full source code and specify more details about what you intend to do and what you have tried to make it work (e.g. if you are just writing a single color to a texture a regular shader will do just fine)

Thanks @lshoek. So the

    ofFboTex->getTexture().bindAsImage(0, GL_WRITE_ONLY);

is correct. I found out the problem was that the fbo texel type was mismatched from the compute shaders expected type: The fixed version looks like this.

 ofFboTex.allocate(worldSize.x, worldSize.y, GL_RGBA32F);// Was GL_RGB
 ofFboTex.getTexture().loadData(simworld_colors.data(), m_worldSize.x, m_worldSize.y, GL_RGBA32F);
// Needs to match the compute shader:
layout(rgba32f, binding=0) uniform writeonly image2D tex0;