Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Matrices in GLSL Not Working

Tags:

opengl

glsl

I have this shader code (GLSL):

#version 420

in vec4 vertex;

uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;

void main()
{
    gl_Position = modelViewMatrix * projectionMatrix * vertex;
}

If I don't set modelViewMatrix and projectionMatrix, it runs without error. If I do, OpenGL throws an Invalid Operation exception when I try to draw.

I set the matrices via this code:

glUniformMatrix4fv(location, 1, false, sendArray); I have verified that "location" and "sendArray" contain the proper data. What's going on here?

EDIT: the problem appears to be in the glUniformMatrix4fv call, but I don't know what's wrong with it.

The code to set up location is as follows:

GLint location;

GLint location = glGetUniformLocation(this->programID, uniform.c_str());

if (location == -1)
{
    throw ShaderVariableNotFoundException(uniform, this->programID);
}

like image 818
Publius Avatar asked Dec 07 '22 14:12

Publius


1 Answers

I fixed it, but I'm loathe to tell you all the solution because of how embarrassing it is...

I...

I forgot to bind the shader program.

I'm so sorry for wasting all of your time.

like image 77
Publius Avatar answered Feb 11 '23 01:02

Publius