radar-like application

Hi,
I am trying to create a kind of “radar” application (black screen, red static points and text, and a green rotating line, with its fixed point in the center of the screen).
The problem is that points are not static. They rotate, together with the line.
This is the code I am using:

GLvoid Render(System::Void) {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
   glPointSize(5.0f);
   glBegin(GL_POINTS);
   glColor3f(1.0f, 0.0f, 0.0f);
   glVertex2f(-350.0f, 0.0f);
   glEnd();
   
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadIdentity();
   gluOrtho2D(0, wid, 0, hei);
   glScalef(1, -1, 1);
   glTranslatef(0, -hei, 0);
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   glLoadIdentity();
   glColor3f(1.0f, 0.0f, 0.0f);
   char* c = "point";
   glRasterPos2f(15.0f, 235.0f);
   for (; *c != '\0'; c++)
      glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *c);
   glPopMatrix();
   glMatrixMode(GL_PROJECTION);
   glPopMatrix();
   glMatrixMode(GL_MODELVIEW);
   
   //glPushMatrix();
   glRotatef(-1.0f, 0.0f, 0.0f, 1.0f);
   glLineWidth(3.0f);
   glBegin(GL_LINES);
   glColor3f(0.0f, 0.5f, 0.0f);
   glVertex2f(0.0f, 0.0f);
   glVertex2f(500.0f, 0.0f);
   glEnd();
   //glPopMatrix();

   SwapBuffers(m_hDC);
}

remove the pushmatrix/popmatrix. Totally useless, and making some of your code unused.

Last push/pop are into a comment; if I remove also the previous push/pop, I do not see anything

ps: I paste also my initgl function… can be useful…


GLvoid InitGL(GLvoid) {
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glViewport(0, 0, this->wid, this->hei);
   gluOrtho2D(-(this->wid / 2), this->wid / 2, -(this->hei / 2), this->hei / 2);
   glShadeModel(GL_SMOOTH);
   glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
   glClearDepth(1.0f);
   glEnable(GL_DEPTH_TEST);
   glDepthFunc(GL_LEQUAL);
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}

Is also the initGL wrong?
Thanks

Just before you draw the line you do a glRotatef to rotate the modelview matrix, then when Render is called again you draw the points with this same matrix so they are rotated as well.

To draw fixed points just move the point-drawing code after the
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
At this point you have pushed the rotated matrix onto the stack and loaded the Identity matrix (which is stationary) so when you draw the text it is stationary.

The push/pop that you have commented out didn’t work because its the wrong way around, you need to push the matrix used to draw the line to save its position while you draw the fixed objects.
Currently the code i mentioned above does this.
(It needs to be here rather than at end of function because otherwise the first pass would pop when it hadn’t pushed anything yet)

The rotation matrix is restored just before you rotate it in the following lines of code:
glPopMatrix(); //This restores the rotation matrix
glMatrixMode(GL_PROJECTION);
glPopMatrix(); //This restores projection matrix defined in Init
glMatrixMode(GL_MODELVIEW);

I’m not sure why you are changing both the projection matrix and the modelview matrix.
If you need to display the points with the same projection matrix as the rotating line then you need to rearrange the code to something like:
// Save rotation matrix and set a fixed modelview
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// Draw points
glPointSize(5.0f);
glBegin(GL_POINTS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(-350.0f, 0.0f);
glEnd();
// Change projection matrix to draw text
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, wid, 0, hei);
glScalef(1, -1, 1);
glTranslatef(0, -hei, 0);

:sorrow: :sorrow: :sorrow:
I was not able to find the right code disposition… I am sorry!!! :confused:
The code I rearranged does not work. Can you paste the right render/init functions?
Thanks for the patience