[Values of glGetFLoatv]

Hello,

I tried to retrieve the values of the GL_MODELVIEW_MATRIX using glgetfloatv which returns an array of 16 values : glGetFloatv (GL_MODELVIEW_MATRIX, m);
qDebug()<<“gl_modelview”<<m;
I wanted to see what the function returns and logically I should get either an array or a matrix but all I got was this strange value : gl_modelview 0xf5d39fbcc0.

And what’s really strange is everytime I run my application, I get different values.
I’m confused. Can someone please tell me why I couldn’t get an array or a matrix ?

This is mostly a question about how arrays work in C/C++ - both are strongly typed languages, i.e. the types of objects matter and if you post code you should include the types unless they are unambiguously obvious.

Presumably the relevant snippet of code looks like:

float m[16];
glGetFloatv(GL_MODELVIEW_MATRIX, m);
qDebug() << "GL modelview matrix: " << m;

In C/C++ arrays decay to “pointer to the first element” in many uses, in particular when passing them as argument to a function. Here, you are calling operator<<(std::ostream& os, float*) (or something similar depending on what exactly the stream object returned by qDebug() is). Note that there is just a float* passed and the function (i.e. operator<<) has no chance of knowing that the pointer points to an array of floating point values, much less how many there are. So, all it can do is print the value of the pointer itself (not what it points to) aka the address where the array is - it could print the first float value, but if you wanted that you could have dereferenced the pointer yourself: qDebug() << "..." << *m;
It changes every time you run the program because your program’s stack is at a different address in memory every time.

Graphics programming is to sizeable extent about managing memory for the resources you want the GPU to consume while rendering. Having a solid understanding how memory on the CPU works and how to manage it from your chosen programming language is an important building block.

1 Like

You got the memory address of a pointer to m.

1 Like

So what I’ve understood is that glGetFloatv doesn’t retrieve the matrix values ? is that right ?

It does retrieve the values, you are not printing them.

1 Like

I’m not being rude here.

This is not an OpenGL question, this is a very basic “how arrays and pointers work in C/C++” concept. You don’t need help in an OpenGL forum at your stage of learning, you need help with these basic programming fundamentals. Because once you do learn them, you’ll not only understand what’s happening here, but you’ll also understand what happens elsewhere. So you’d be better served by improving your knowledge of C/C++ before you try to proceed any further in OpenGL, because so much of OpenGL is dependent on that knowledge.

2 Likes

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.