glGet

I cannot for the life of me figure out why glGet is not working for me. To illustrate, I just wrote a quick and dirty tester program:

  
#include<stdio.h>
#include"GL/glu.h"
#include"GL/gl.h"
#include"stdlib.h"

int main()
{
    float* mat = (float*)malloc((16*sizeof(float)));

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glGetFloatv(GL_MODELVIEW_MATRIX, mat);

    int i,j;
    i = j = 0;

    for(;i < 16;)
    {
        printf("[ ");
        for(j = 0; j < 4; j++)
        {
            printf("%f ", mat[i]);
            i++;
        }
        printf(" ]
");
    }

    int mode = 0;

    glGetIntegerv(GL_MATRIX_MODE, &mode);
    printf("%d 
", mode);
    return 0;
}           

mat remains unchanged, and I get all zeros in the print out.

You need to have a OpenGL render context current before you can call into the API.

Yeah…I’m so much of a beginner that I don’t know what you’re talking about. I (obviously) assumed including gl.h would be context enough. What, other initialization would I require?

Check out GLUT:
http://www.xmission.com/~nate/glut.html

It’s a nice little wrapper that handles window and context creation for you, among other things like input event notifications. Very easy to install and use. Be sure to read the ReadMe file for instructions on where to put everything. There are countless demos that utilize GLUT, so there is no shortage of examples.

Have a peek at the sticky Wiki, all this is in there, and more.