what to use instead of glGetAttribLocation for gl versions < 2.0 - opengl

is there a way to get the id of a variable if the opengl version is smaller than 2.0?
glGetAttribLocation is only available since 2.0
thanks!

Assuming you're using GLSL via the ARB extensions (GL_ARB_shader_objects, GL_ARB_vertex_shader and GL_ARB_fragment_shader), you need to use glGetAttribLocationARB, from the GL_ARB_vertex_shader extension.
If you are not using those extensions and not using OpenGL >= 2.0, then you don't need to use glGetAttribLocation since it requires a vertex shader to be present.

GLSL is only available since GL 2.0. That's when glGetAttribLocation was added.
If you can get to the entrypoints to create a GLSL vertex shader, then you can, in the same way, get access to the glGetAttribLocation entrypoint.

Related

Is it possible to write vertex array code that's portable between OpenGL 2.x and 3.x?

The OpenGL 3.0 spec says:
E.1 Profiles and Deprecated Features of OpenGL 3.0
...
Client vertex arrays - all vertex array attribute pointers must refer
to buffer objects (section 2.9.2). The default vertex array object
(the name zero) is also deprecated. Calling VertexAttribPointer when
no buffer object or no vertex array object is bound will generate an
INVALID_OPERATION error, as will calling any array drawing command
when no vertex array object is bound.
The ref page for glEnableVertexAttribArray says:
GL_INVALID_OPERATION is generated by glEnableVertexAttribArray and glDisableVertexAttribArray if no vertex array object is bound.
The message I'm hearing is that comprehensive vertex array code that's fully portable between OpenGL 2.x and OpenGL 3.x/3.2+ is impossible, since 2.x can't use VAOs (which the API surface can strictly enforce -- thanks GLAD!), and 3.x must use VAOs (which...some drivers maaaybe enforce?)
It seems to me that robust code must branch between dedicated 2.x and 3.x codepaths (detected at runtime) at some point. Is this true?
When you use a compatibility profile OpenGL Context, then you can run the code of all previous OpenGL versions. Vertex array object 0 is valid and you can use fixed function attributes, immediate mode (glBegin/glEnd sequences) or even mix them all together.
Compare OpenGL 4.6 API Core Profile Specification and OpenGL 4.6 API Compatibility Profile Specification.
The specification of all OpenGL versions can be found at Khronos OpenGL registry.

Can GPU support and test shader code of an older version?

Say I want to test shader code of an older version, which is GLSL 1.2.
The GPU on the machine actually can support GLSL 4.0 (from the hardware specification).
Yes, you should be able to run shaders for a lower version.
Just make sure to identify the glsl version the code is written against in the very first line of every shader source, e.g. #version 120
The OpenGL context should also use the compatibility profile, the core profile does not contain deprecated functionality.
You need to create an OpenGL context in compatibility mode, which probably is the default.

OpenGL compute shader extension

I have a problem with creating compute shader.
My program seems to not know GLenum type GL_COMPUTE_SHADER when I'm trying to create shader with glCreateShader() func.
My graphics card is kinda low-end but when I check for GL_ARB_compute_shader extension it is present so that shouldn't be a problem I guess.
Is there something that I have to do to enable this extension or is there another problem and I have to use OpenCL?
OpenGL Compute Shaders are new in version 4.3. I'm guess you have headers that predate that version. However, even if you got newer headers, your GPU or driver may be too old to support OpenGL 4.3. What version does your hardware return for glGetString(GL_VERSION)?

How to use glPixelTransfer, glTexEnv and glRasterPos in openGL 3.1?

glPixelTransfer, glTexEnv and glRasterPos have been deprecated in OpenGL 3.1. What is it replaced with? If not replaced, how can I get a similar effect? I would like to use these functions.
What is it replaced with?
Framebuffer objects and fragment shaders.
P.S. If you don't want to mess with shaders, you can keep using older OpenGL version, you know.

How do you get the modelview and projection matrices in OpenGL?

I am trying to use the OpenGL Shading Language (GLSL) version 1.5 to make vertex and geometry shaders.
I have learned that in GLSL version 1.5, the built-in variables like gl_ModelViewProjectionMatrix are deprecated so you have to pass them in manually. If I have already set the modelview and projection matrices (using gluLookAt and gluPerspective for example) then how do I get the matrices to pass into the vertex and geometry shaders? I've done some searching and some sites seem to mention a function glGetMatrix(), but I can't find that function in any official documentation, and it doesn't seem to exist in the implementation I am using (I get a compilation error unknown identifier: glGetMatrix when I try to compile it with that function).
Hey, let's slow down a bit here :) Yes, that's true that you receive the matrix by glGetFloatv(GL_MODELVIEW_MATRIX, ptr)... But that's definitely not the thing you should do here!
Let me explain:
In GLSL, built-in variables like gl_ModelViewProjectionMatrix or functions like ftransform() are deprecated - that's right, but that's only because the whole matrix stack is deprecated in GL 3.x and you're supposed to use your own matrix stack (or use any other solution, a matrix stack is helpful but isn't obligatory!).
If you're still using the matrix stack, then you're relying on functionality from OpenGL 2.x or 1.x. That's okay since all of this is still supported on modern graphics cards because of the GL compatibility profile - it's good to switch to a new GL version, but you can stay with this for now.
But if you are using an older version of OpenGL (with matrix stack), also use an older version of GLSL. Try 1.2, because higher versions (including your 1.5) are designed to be compatible with OpenGL3, where things such as projection or modelview matrices no longer exist in OpenGL and are expected to be passed explicitly as custom, user-defined uniform variables if needed.
The correspondence between OpenGL and GLSL versions used to be a bit tricky (before they cleaned up the version numbering to match), but it should be more or less similar to:
GL GLSL
4.1 - 4.1
4.0 - 4.0
3.3 - 3.3
3.2 - 1.5
3.1 - 1.4
3.0 - 1.3
2.x and lower - 1.2 and lower
So, long story short - the shader builtin uniforms are deprecated because the corresponding functionality in OpenGL is also deprecated; either go for a higher version of OpenGL or a lower version of GLSL.
To get either matrix you use the constants GL_MODELVIEW_MATRIX or GL_PROJECTION_MATRIX with glGetxxxx:
GLfloat model[16];
glGetFloatv(GL_MODELVIEW_MATRIX, model);
float modelview[16];
glGetFloatv(GL_MODELVIEW_MATRIX, modelview);