In the visualization of fft using glsl, rewrite from glsl 120 to 150

I am trying to make fft texture using GLSL. However, although it was created in the current version 150, thought that I wanted to rewrite it to version 120, it does not work well, I will paste the source code below, so please let me know if you know what is the cause. I am delighted.

glsl150.vert

#version 150
uniform mat4 modelViewProjectionMatrix;
in vec4 position;
in vec2 texcoord;

out vec2 vTexCoord;

void main(){
    vTexCoord = texcoord;
    gl_Position = modelViewProjectionMatrix * position;
}

glsl150.frag

#version 150
uniform sampler2DRect tex;
uniform float rawFft[256];
in vec2 vTexCoord;

out vec4 outputColor;

void main(){

    if (vTexCoord.y < 1.0) {
        int i = int(vTexCoord.x);
        outputColor.r = rawFft[i];
    } else {
        vec2 st = vTexCoord;
        st.y -= 1.0;
        outputColor.r = texture(tex, st).r;
    }
    outputColor.a = 1.0;
}



glsl120.vert

#version 120
#extension GL_ARB_texture_rectangle : enable

void main(){
    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = gl_Vertex;
}

glsl120.frag

#version 120
#extension GL_ARB_texture_rectangle : enable

uniform sampler2D tex;
uniform float rawFft[256];

vec4 outputColor;

void main(){

    if (gl_TexCoord[0].y < 1.0) {
        int i = int(gl_TexCoord[0].x);
        outputColor.r = rawFft[i];
    } else {
        vec2 st = gl_TexCoord[0].st;
        st.y -= 1.0;
        outputColor.r = texture2D(tex, st).r;
    }
    outputColor.a = 1.0;

    gl_FragColor = outputColor;
}

I want to make the result which is out in 150 work even with 120. What is wrong?

have you disabled rectangular textures? if you want to use 2d textures in OF you have to call ofDisableArbTex() before loading the textures

I did not call it, but since I did not load the texture itself, I did not need to call it.
And even if called, the result did not change …

void ofApp::setup(){
    for (int i = 0; i < 2; i++) {
        soundTex[i].allocate(fftSize, historySize, GL_R16);
        soundTex[i].begin();
        ofClear(0);
        soundTex[i].end();
    }

    Shader.load("shader/scene/glsl120");
    
    sound.load("sound.mp3");
    sound.play();
}

void ofApp::update(){
    ofSoundUpdate();
    float * val = ofSoundGetSpectrum(512);
    
    soundTex[current].begin();
    ofClear(0);
   
    Shader.begin();
    Shader.setUniform1fv("rawFft", val, fftSize);
    soundTex[1-current].draw(0,0);
    Shader.end();    
    soundTex[current].end();
    current = 1 - current;
    
}
void ofApp::draw(){    
    soundTex[0].draw(0,0, 256, 256)
}

Do you know the cause?

By loading i wanted to say any allocation of any type on a texture in OF. If you are using texture2D in the shader you have to call it otherwise the texture coordinates will be in pixels instead of normalized. Try calling it at the very beginning of setup before anything else.

Also you can use glsl 150 or higher if you setup the application to use opengl 3 or more in main.cpp like:

#include "ofMain.h"
#include "ofApp.h"

//========================================================================
int main(){
	  ofGLFWWindowSettings settings;
	  settings.setGLVersion(3,3);
	  ofCreateWindow(settings);
	  ofRunApp(new ofApp);
}