Trying to do the modell-view with coordinate calculation per hand and fail for reasons I don't understand

I try to calculate the modell-view-matrix multiplication with some coordinates by hand but for some reason this two code fragments don’t give the same visual output when used at the very same place in my source code and I don’t understand why. The current matrix of course is the modell-view one.

Source with calculation made by OpenGL
glPushMatrix();
	glTranslatef(_xAnfang + (_xAktuell-_xAnfang)/2, 
				_yAnfang + (_yAktuell-_yAnfang)/2,
				0);
	glRotatef(grad, 0, 0, 1);
	glTranslatef(-(_xAnfang + (_xAktuell-_xAnfang)/2),
				-(_yAnfang + (_yAktuell-_yAnfang)/2),
				0);

	glRectf(_xAnfang - 1.5,
			_yAnfang + (_yAktuell - _yAnfang)/2 - 0.5,
			_xAnfang - 0.5,
			_yAnfang + (_yAktuell - _yAnfang)/2 + 0.5);
glPopMatrix();
Source with calculation made by hand
float __xAnfang, __yAnfang, __yAktuell;
float modelviewMatrix[16];

glPushMatrix();
	glTranslatef(_xAnfang + (_xAktuell-_xAnfang)/2, 
				_yAnfang + (_yAktuell-_yAnfang)/2,
				0);
	glRotatef(grad, 0, 0, 1);
	glTranslatef(-(_xAnfang + (_xAktuell-_xAnfang)/2),
				-(_yAnfang + (_yAktuell-_yAnfang)/2),
				0);

	glGetFloatv(GL_MODELVIEW_MATRIX, modelviewMatrix);

	__xAnfang = (_xAnfang * modelviewMatrix[0]) + (_yAnfang * modelviewMatrix[4]);
	__yAnfang = (_xAnfang * modelviewMatrix[1]) + (_yAnfang * modelviewMatrix[5]);

	__yAktuell = (_xAktuell * modelviewMatrix[1]) + (_yAktuell * modelviewMatrix[5]);
glPopMatrix();

glRectf(__xAnfang - 1.5,
		__yAnfang + (__yAktuell - __yAnfang)/2 - 0.5,
		__xAnfang - 0.5,
		__yAnfang + (__yAktuell - __yAnfang)/2 + 0.5);

Can someone explain to me why this isn’t working? Thanks in advance.

Greetings,
max05

Why would you expect them to produce the same result?

Without making any assumptions about the actual model-view matrix being used, there are two reasons why they wouldn’t:

  1. Your “by hand” transformation in the second version doesn’t consider the translation component in modelviewMatrix[12] and modelviewMatrix[13]. The vertices generated by glRect have Z=0 (so you can ignore the third column), but W=1 (so you can’t ignore the fourth column).
  2. Even ignoring the W component, the coordinates passed to glRectf aren’t linear expressions in the variables, so transforming the expression isn’t the same as transforming the variables used in the expression. And even if they were linear, they wouldn’t be once you consider W.