I’m updating GLSL shaders to change from GL_TEXTURE_2D access to GL_TEXTURE_RECTANGLE. The compiler says I have to move up to #version 140. When I declare the version, I get the following errors/warnings:

0(68) : error C7533: global variable gl_TexCoord is deprecated after version 120
0(68) : error C7531: global function texture2DRect requires “#extension GL_ARB_texture_rectangle : enable” before use
0(103) : error C7533: global function texture1D is deprecated after version 120
0(146) : warning C7533: global variable gl_FragColor is deprecated after version 120

I can’t find much information about GLSL 1.4 and higher as concerns texture access. Can someone tell what I use to replace the calls to glTexCoord and glTexture1D()?

Well, with version 1.30, certain built-ins have been deprecated and finally removed in 1.40 and up. gl_TexCoord was a predefined varying vec4. You can simply replace it with a vector of your own. It’s the same for gl_FragCoord, which was previously used to indicate what to write to the current color buffer(s). You have to either set the location (i.e. the render target) to write to explicitly within the shader (see below) or on the application level using glFragDataLocation().

// in the vertex shader
out vec2 TexCoord;

// in the fragment shader
in vec2 TexCoord;
layout(location = 0) out vec4 FragCoord;

The texture lookup calls have been unified to simply “texture()” from GLSL 1.30 and up. You can have a look at as a reference.

Basicly, you have to do it all yourself. You send the texcoordinates as explicit attributes for your objects, so you’ll need something like this in the vertex shader

in vec2 in_texCoord;
out vec2 out_texCoord;

and pass the texture coordinates from the VS to the FS. This applies to pretty much any built in except the ones found at the end of the man reference pages for the version you are targeting.

I do have a question for you, however. Why are you moving from texture2D to texture rectangles?

If you need to access exact texels within a texture remember you can do it with textureOffset() or query textureSize() within the shader you are working with and pretty much do everything you can do with a rectangle. If it’s for data packets, maybe a texture buffer would be better.

Oh, and since you are upgrading (and without knowing what you are targeting), you could consider jumping to 3.30 (so #version 330).

Thanks Thokra and Ed Daenar. OpenGL is always a stretch for my brain. My application is film scanning, and I think in logical pixels. Most of my work is GLSL rendering to FBO’s for film image processing work. I wanted to move to Texture Rectangle, as I’m doing more with image translation and don’t want to risk image degradation with sub-pixel translation. I’ll read up on textureOffset(). I already use textureSize() for my convolution operations. If you think it is safe to use the textureOffset() and textureSize() functions for texture manipulation without filtering degradation of the source image (which is from image file format film scans of defined pixels (ie 2048 x 1556), I’m glad to stay away from Texture Rectangle.

Just one correction, thokra meant here gl_FragColor not gl_FragCoord. gl_FragCoord is a built-in input of the fragment shader and contains the screen space fragment coordinates and it is not deprecated but still supported.

It would perhaps be simpler for you to use GL_ARB_texture_rectangle instead.

Unless if you don’t have to much code to upgrade to #version 140.

V-Man (Or anybody else):
What significance of GL_ARB_texture_rectangle? How is it different from the #version 140 core texture rectangle?


What significance of GL_ARB_texture_rectangle? How is it different from the #version 140 core texture rectangle?

It’s an extension, so you have to explicitly enable the extension in your shader.

GL_ARB_texture_rectangle was added during GL 2.0 or 2.1. It was basically the same as GL_EXT_texture_rectangle except that define support for GLSL.

I believe the syntax to enable the extension is

//Fragment shader
#version 110
#extension GL_ARB_texture_rectangle : enable

void main()
//my code

In the above, the GLSL version is 1.10, the version released with GL 2.0. It also supports gl_TexCoord and the other oldies you are using.