1

This is my source If I build this source without the function I can see only 2 lines. But I want to see the 'z'axis.

So I added the gluLookAt() function but I can see just black screen.

What's wrong with my code? Is the camera's point of view is wrong? It is created on the MFC dialog box. Please help me.

void CopglDlg::OnTimer(UINT_PTR nIDEvent)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();

gluLookAt(3.f, 3.f, 3.f, 0.f, 0.f, 0.f, 0.f, 0.f, 1.f);

glBegin(GL_LINE_LOOP);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glVertex3f(-1.0, 0.0, 0.0);
glEnd();

glBegin(GL_LINE_LOOP);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glVertex3f(0.0, -1.0, 0.0);
glEnd();

glBegin(GL_LINE_LOOP);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, -1.0);
glEnd();

glFlush();
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
ICETOP
  • 27
  • 2
  • Has any of the answers answered your question or is there still something unclear? Note, if an answer to your question has solved your issue completely, then you should accept the answer. (check mark at the left of the answer). – Rabbid76 Nov 16 '17 at 17:01

2 Answers2

3

When in OpenGL a vertex (point) is processed, it gets transformed by the modelview matrix and the projection matrix.

The projection matrix describes the mapping from 3D points of a scene, to 2D points of the viewport. The projection matrix transforms from view space to the clip space, and the coordinates in the clip space are transformed to the normalized device coordinates (NDC) in the range (-1, -1, -1) to (1, 1, 1) by dividing with the w component of the clip coordinates. All the geometry which is out of the clip space is clipped and unvisible.

The modelview matrix is a combination of the model matrix and the view matrix.
The view matrix describes the direction and position from which the scene is looked at. The view matrix transforms from the wolrd space to the view (eye) space.
The model matrix defines the location, oriantation and the relative size of a mesh in the scene.

In OpenGL all matrix operations, are applied to the matrix stack you have specified by glMatrixMode.

In your case you did not set up a projection matrix, so the projection matrix is by default the identity matrix. This means the far plane is by default at 1 and every thing what is farer away from your eye position (3.0, 3.0, 3.0) than 1, gets clipped by the far plane and is not visible.

You can either change the view matrix, so that you can see out from the center (Note, if the projection matrix is the identity matrix, then the projection is an orthographic projection, the near plane is at -1 and the far plane at +1, so the area around the eye position is in the clip space):

glMatrixMode(GL_MODELVIEW);
gluLookAt(0.0f, 0.0f, 0.0f, -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f);

Or you set up a projection matrix with a far plane, that is far enough away to include the area where your lines are in (see glOrtho):

glMatrixMode(GL_PROJECTION);
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 10.0 );

glMatrixMode(GL_MODELVIEW);
gluLookAt(3.0f, 3.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
0

OpenGL only shows you what is inside an unitary cube. Once you moved your camera 3 steps on each direction, your lines does not fit inside this new cube.

In order to see it, I sugest to move your camera near your orign point:

gluLookAt(.5f, .5f, .5f, 0.f, 0.f, 0.f, 0.f, 0.f, 1.f);

Or create a new visualization volume, by stablishing an orthographic projection

Amadeus
  • 10,199
  • 3
  • 25
  • 31