5
\$\begingroup\$

I'm attempting to manually setup a matrix in my vertex shader purely because I like to learn as much as possible about anything I do usually.

So the problem is that I'm getting an GL_INVALID_OPERATION when too me my code seems clear as crystal complete.

const GLfloat modelviewmatrix[] = {
    1.0f , 0.0f , 0.0f , 0.0f,
    0.0f, 1.0f, 0.0f , 0.0f ,
    0.0f, 0.0f, 1.0f, 0.0f,
    0.0f, 0.0f, 0.0f, 1.0f
};

GLint locationID = glGetUniformLocation(ShaderPrograms, "modelviewMatrix");

std::cout << "location->" <<locationID << std::endl;
glUniformMatrix4fv(locationID, 1, GL_FALSE, modelviewmatrix);

GLenum error;

error = glGetError();

if (error != GL_NO_ERROR)
{
    std::cout << "not working" << std::endl;
}

if (error == GL_INVALID_OPERATION)
{
    std::cout << "INVALID OPERATION" << std::endl;
}
if (error == GL_NO_ERROR)
{
    std::cout << "No Error! -> CODE CHECKING <-" << std::endl;
}

if (error == GL_INVALID_VALUE)
{
    std::cout << "NO VALUE" << std::endl;
}

if (error == GL_OUT_OF_MEMORY)
{
    std::cout << "NO MEMORY" << std::endl;
}

if (error == GL_STACK_OVERFLOW)
{
    std::cout << "NO OVERFLOW" << std::endl;
}


if (error == GL_INVALID_FRAMEBUFFER_OPERATION)
{
    std::cout << "invalid framebuffer <-" << std::endl;
}

if (error == GL_OUT_OF_MEMORY)
{
    std::cout << "Out of Memory" << std::endl;
}

//VERTEX SHADER

#version 330 core

layout (location = 0) in vec3 position;

uniform mat4 modelviewMatrix;
uniform mat4 projection;

void main()
{

    gl_Position = modelviewMatrix * vec4(position.x, position.y, position.z, 1.0);
}

What could be causing the problem , why is it causing it . how did you find out and what did you use too figure it out please?.

OpenGL 3.30+ , GLSL 3.30 core , Win10 64bit.

figured out what the problem was I was using glUseProgram after I was doing uniforms instead of doing that before.

full source here -> http://pastebin.com/zD7YEDjp

\$\endgroup\$
3
  • \$\begingroup\$ I'm not sure of you know what stackoverflow means based on the debug message. \$\endgroup\$
    – Bálint
    Apr 20, 2016 at 17:53
  • \$\begingroup\$ Also, you can write vec4(position, 1.0), and openGL fills out the gaps. \$\endgroup\$
    – Bálint
    Apr 20, 2016 at 17:54
  • \$\begingroup\$ Bálint -> I was always wondering if I could do that or not thanks for clarifying for me. Logic is too be aware of as much as possible. \$\endgroup\$ Apr 20, 2016 at 17:55

2 Answers 2

6
\$\begingroup\$

figured out what the problem was I was using glUseProgram after I was doing uniforms instead of doing that before.

\$\endgroup\$
4
\$\begingroup\$

You get invalid operation, because you don't use the uniform "projection" in the shader, thus OpenGL deletes it to save memory.

This can be solved by simply referencing it with projection;, you don't need to use it.

Like this:

#version 330 core

layout (location = 0) in vec3 position;

uniform mat4 modelviewMatrix;
uniform mat4 projection;

 void main()
{

    gl_Position = modelviewMatrix * vec4(position.x, position.y, position.z, 1.0);
    projection;
}
\$\endgroup\$
16
  • \$\begingroup\$ Where does it say I must use every uniform in my shader it's their as my second problem to solve hopefully all by myself?. \$\endgroup\$ Apr 20, 2016 at 17:56
  • \$\begingroup\$ I tried removing it and doesn't work so clearly that's not fixing the problem lol. \$\endgroup\$ Apr 20, 2016 at 18:00
  • \$\begingroup\$ @Dominic Hughes if you don't use it, it pretty mich doesn't exist as a uniform, thus glGetUniformLocation returns -1, and you get an invalid operation from glUniformMatrix4fv. \$\endgroup\$
    – Bálint
    Apr 20, 2016 at 18:01
  • \$\begingroup\$ The compiler's free to remove uniforms you don't use; it's pretty common. It's not the only reason you might get an invalid operation though. Have you read the docs for glUniform*, @DominicHughes? They enumerate the possible scenarios, and you're not currently checking for all of them. \$\endgroup\$
    – user1430
    Apr 20, 2016 at 18:01
  • \$\begingroup\$ @DominicHughes not remove it REFERENCE IT \$\endgroup\$
    – Bálint
    Apr 20, 2016 at 18:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .