PDA

View Full Version : gltranslate and black screen



yakovm
04-08-2010, 02:34 PM
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(left,right,bottom,top,0.9,2*diam + 2);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GLfloat LightPosition1[]= { 0.0f, 0.0f, 0.0f, 1.0f };
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition1); //stick the light to the viewer
gluLookAt (0.0,0.0,m_modelsCompainer->getCenter()[2]+diam + 1,
m_modelsCompainer->getCenter()[0],m_modelsCompainer->getCenter()[1],m_modelsCompainer->getCenter()[2],0.0, 1.0, 0.0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, colorVec);
glPushMatrix();
glLoadIdentity();
glTranslatef((GLfloat)0,(GLfloat)0,(GLfloat)1);
//render the mesh here
glPopMatrix();

Why I am getting black screen?
when performing transformation in modelview mode,does the transformation is performed in local coordinate system of the object

Kelvin
04-08-2010, 10:42 PM
Why I am getting black screen?


The gluLookAt command in your code snippet doesn't actually do anything, because before you draw anything with the matrix it builds, you call glLoadIdentity, which wipes it out.

The mesh is only affected by the glTranslate call. The gluLookAt is just a convenient way to build a multiplying a viewing transform into the current matrix. You can think of it as "moving the eye", but it may be better to think of it as moving the world into position in front of the eye. That helps you realize that you have to draw the mesh with the gluLookAt matrix in effect for it to do anything.

Also, by definition the eye looks down the negative Z axis, which can trip people up sometimes. Your translate call pushes the mesh toward the eye, not away. It's very possible that the mesh has crossed the near plane (or maybe even passed through the eye point to behind the viewer (depending on the size of the mesh).



when performing transformation in modelview mode,does the transformation is performed in local coordinate system of the object

You can look at it that way, but I find it confusing, and prefer to think of a "grand, fixed coordinate system". The OpenGL Programming Guide (Red Book) has a discussion of the different ways of thinking about the transformation. See "Thinking about Transformations" on this page: http://www.glprogramming.com/red/chapter03.html

I imagine that the more "obvious" way of thinking about transforms depends on what you are using them for.