1

I am debugging an OpenGL program:

Is there some kind of toString() functionality for matrices and vectors (mat3, mat4, vec3 &c)?

I'm trying to avoid constructing nested for-loops with cout or printf.

But if that's the only way to do this, I"d love to hear advice on best practices. I'm pretty new to C++ and am interested to hear about it.

What would be really cool is output to a laTeX / ConTeXt logfile.

That leads to a more extended version of the question: is there some reflection functionality for these objects? I'd like to know if the particular matrix I'm interested in is specified column-major or row-major, what/where its parent class is, &c.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Wylie Kulik
  • 696
  • 5
  • 17
  • Did my answer help for the first part? the second part should be put in a new question and this one marked as correct if the provided answer is suitable. – const_ref Nov 20 '12 at 09:28
  • "*I'd like to know if the particular matrix I'm interested in is specified column-major or row-major*" It's GLM: it's always column-major ordering, just like OpenGL takes them. And what do you plan to do with that information anyway? Same question goes for the whole "parent class" thing; why do you *need* to know? And what makes you think they have parent classes to begin with? – Nicol Bolas Nov 20 '12 at 09:42
  • @NicolBolas He doesnt state that he is using glm. He could be using his own vector/matrix library – const_ref Nov 20 '12 at 10:59
  • we're using GLM, but part of the code-base is not glm, or something. A bit confusing. This is all through the edX BerkeleyX class by the way. – Wylie Kulik Nov 20 '12 at 13:39

1 Answers1

1

Overload the ofstream << operator for your matrix/vector class and then inside format it the way you want i.e. output << "(" << vector.x << " ", " << vector.y << etc. Then in your main program you can simply do std::cout << myVector << std::endl;

http://www.learncpp.com/cpp-tutorial/93-overloading-the-io-operators/

The link shows how it can be implemented

const_ref
  • 4,016
  • 3
  • 23
  • 38
  • i was wondering if there is some native (already implemented) such functionality. modifying gl classes is wouldn't be a high priority right now. – Wylie Kulik Nov 20 '12 at 13:51
  • 1
    @JoshuaCullick You don't need to modify any classes. The << operator can be a non-member function, overloaded to accept a parameter of your matrix type. It's really just a couple of stand-alone functions. – s3rius Nov 20 '12 at 16:13
  • 1
    @JoshuaCullick: OpenGL doesn't *have* classes. – Nicol Bolas Nov 20 '12 at 17:09