Hi I'm new to OpenGL(idk if I have already 4 months of learning it it's called new), and I have passed successfully my matrix to the shader, my matrix was an temporary GLfloat.
SO I started my class by building an old in the book trick, of overloading operators
#pragma once
#include <GL\glew.h>
class Matrix
{
public:
Matrix(GLfloat* arrays);
~Matrix();
class Proxy
{
public:
Proxy(GLfloat* arr);
GLfloat operator[](int index);
private:
GLfloat* arr;
};
GLfloat** array_;
Proxy operator[](int index);
};
//cpp file
#include "..\headers\Matrix.h"
Matrix::Matrix(GLfloat* arrays)
{
GLfloat* matrixtemp = arrays;
array_ = new GLfloat*[4];
for (int i = 0; i < 4; i++)
array_[i] = new GLfloat[4];
for (int i = 0; i < 16; i++)
{
array_[i % 4][i / 4] = matrixtemp[i];
}
}
Matrix::~Matrix()
{
}
Matrix::Proxy::Proxy(GLfloat * arr):
arr(arr)
{
}
GLfloat Matrix::Proxy::operator[](int index)
{
return arr[index];
}
Matrix::Proxy Matrix::operator[](int index)
{
return Proxy(array_[index]);
}
I have debugged if it works, and it does. But when I have to introduce it to my Shader function(s->passUniformMatrix4(&m[0][0], "myMatrix");//this is defined like void Shader::passUniformMatrix4(const GLfloat * value, const char* name) )
and I get 2 errors
1 2
Error C2102 '&' requires l-value
Error (active) E0158 expression must be an lvalue or a function designator
I repeat: I have debugged the function and it inits very well, it does return the proper value, but I get this error when used in this context. If it wasn't initialized it would compile but crash my program, that's what I believe)
I think you don't need to know OpenGL to solve my problem.
I think you don't need to know OpenGL to solve my problem.
I know neither OpenGL nor how to solve your problem, but there’s something I’d like to understand better in your code, if I may ask:
(s->passUniformMatrix4(&m[0][0], "myMatrix");//this is defined like void Shader::passUniformMatrix4(const GLfloat * value, const char* name)
It seems the first argument of “passUniformMatrix4” should be a pointer.
So why are you passing the address of a bidimensional array?
And why do you specify all dimensions to be 0?
array_ = new GLfloat*[4];
for (int i = 0; i < 4; i++)
array_[i] = new GLfloat[4];
Beware that &array_[0][0] cannot be treated as a pointer to the first element of an array of 16 elements, because the structure is not contiguous -- it looks more like this:
3) Is what you posted your real code or a simplified example?
I mean, if you know the dimension of your ‘array_’ from the beginning, why don’t you simply write:
2)I deleted it because it would get very many down sides and reduce my rep, getting me away some privileges.
3)Yes, I know, but I find matrices very useful, and in the future reuse the code, with unknown sizes of rows and columns