PDA

View Full Version : glGetDoublev returns 0-Matrix



e1sbaer
01-19-2005, 11:35 AM
I've used the glGetDoublev function to get the modelview matrix but the function returns me an array with every value set to 0. I tried also to get the porjection matrix and get the same result. Here's a function that calls glGetDoublev before a call of gluLookAt and after that call. Both calls of glGetDoublev returns this result:

void setModelview(void)
{
GLdouble temp[16];
// setup model matrix
glGetDoublev(GL_MODELVIEW_MATRIX, temp); // get modelview-matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glGetDoublev(GL_MODELVIEW_MATRIX, temp); // get modelview-matrix
}

I've no more ideas why this happens...

I've noticed the failure occurs ONLY when I call glGetDoublev with parameter GL_MODELVIEW_MATRIX and NOT with parameter GL_PROJECTION_MATRIX.

CWiC
01-19-2005, 09:44 PM
Are you sure that OpenGL context already created and active at time you call correspondent functions?

e1sbaer
01-21-2005, 10:33 AM
hmmm, I don't know. I'm very new to GL. There is the function displayWorld as follows:

{
GLdouble temp[16];
GLfloat _directionalVec[] = { 0.0, 0.0, 1.0, 0.0 };


setTexture();

setModelview();

glClearColor(0.2, 0.2, 0.2, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// set Light position
glLightfv(GL_LIGHT0, GL_POSITION, _directionalVec);

// shift object
glTranslatef(_shiftX, _shiftY, _shiftZ);

// rotate Object
glRotatef(_rotObjectX, 1.0f, 0.0f, 0.0f);
glRotatef(_rotObjectY, 0.0f, 1.0f, 0.0f);

// show coordinate system
if(_showCoordinates == ON)
{
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glBegin(GL_LINES);
glColor3ub(255, 0, 0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(5.0, 0.0, 0.0);

glColor3ub(0, 255, 0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 5.0, 0.0);

glColor3ub(0, 0, 255);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 5.0);
glEnd();
}

// show center of spherical mapping
if(_showOrigin == ON)
{
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glColor3f(1.0, 1.0, 0.0);
glPushMatrix();
glTranslatef(_origin[0], _origin[1], _origin[2]);
glutSolidSphere(1.0f, 20, 20);
glPopMatrix();
}

// shade and draw the geometry
drawOffModel();

glutSwapBuffers();
}the function setModelview() is called in the upper part and the drawOffModel function (which draws the model) is the last line before glutSwapBuffers() is called to output the result.
GL works from the last call to the first so there should be a modelviewmatrix at the moment I call the glGetDoublev(GL_MODELVIEW_MATRIX,.. ) function (or is this wrong?).

e1sbaer
01-25-2005, 03:26 AM
I don't know what the problem is, but if I shift the model arround then the modelview matrix is not filled with 0 any longer. Someone knows an answer on it?

The next problem I have is thet when I call glGetIntergerv(GL_VIEWPORT, viewport); the returned values are:
viewport[0] => 0
viewport[1] => 512
viewport[2] => -858993460
viewport[3] => -858993460
It's easy to see that there is a failure because width and height is negative. The values should be:
viewport[0] => 0
viewport[1] => 0
viewport[2] => 1024
viewport[3] => 512

thanks for help

Aeluned
01-25-2005, 05:40 AM
every time I've seen this problem, it's been because the context wasn't current.

double and triple check that your context is current before making the calls to glGet*.

e1sbaer
01-25-2005, 06:18 AM
how could this be? I call this function by a popup menu entry.

CWiC
01-26-2005, 06:59 AM
which compiler/debugger you use and how you look into variable's values? Values -858993460 tells that those variable stay uninitialized... It seems to me like you look for variables values in VC7.NET IDE with "release" build option. But in any case I suggest to make some kind of output into file and take a look at values there and not in debugger, just for sure...

e1sbaer
01-26-2005, 09:50 AM
the compiler I use is the one that comes with visual c++ 2005 beta. the variable is initialized with 0 but this is the output of the glGetIntegerv call. after the call I output the values with printf("Value of viewport: %i, %i, %i, %i", viewport[0], viewport[1],...);