• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

## Recommended Posts

Let''s say I had a quadric and a line I drew it like this:
  glColor3f(1.0, 1.0, 1.0); glBegin (GL_LINES); glVertex3f (x, y, z); glVertex3f (0.0, 0.0, 0.0); glEnd(); glColor3f (1.0, 0.0, 0.0); glTranslatef (x, y, z); gluSphere (sphere, 1.0, 12, 12); 
Theoretically, the sphere should be drawn to the end of the line that isn''t at the origin, right? But when I actually try this code the sphere ends up in lala land flying around the screen. What am I doing wrong? Major thanks in advance -- Peace, Capt. Jean-Luc Pikachu

##### Share on other sites
I think the last two lines should be like this:
...
glPushMatrix();
glTranslatef(...);
glutSphere(...);
glPopMatrix();
...
Maybe you can try it.

##### Share on other sites
quote:
Original post by Lang Fox
I think the last two lines should be like this:
...
glPushMatrix();
glTranslatef(...);
glutSphere(...);
glPopMatrix();
...
Maybe you can try it.

that may be just useful if you wanna draw something after this code, but the sphere itself shouldn''t be affected .... dunno why this doesn''t work, but i dunno glut well, so that may be the point for me

@\$3.1415rin

##### Share on other sites
Thanks for trying to reply. I tried AuxSphere, gluSphere, and glutSphere, but no go on any of them =( Saving the matrix before & restoring after doesn''t change anything.

--
Peace,
Capt. Jean-Luc Pikachu

##### Share on other sites
Finally got it!

  glColor3f(1.0, 1.0, 1.0);glBegin (GL_LINES); glVertex3f (x, y, z); glVertex3f (0.0, 0.0, 0.0);glEnd();glMatrixMode (GL_PROJECTION);glPushMatrix(); glLoadIdentity(); glOrtho (-150, 150, -50, 50, -50, 350); glMatrixMode (GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); gluLookAt (70, 20, -70, 0, 0, 0, 0, 1, 0); glColor3f (1.0, 0.0, 0.0); glTranslatef (x, y, z); gluSphere (sphere, 1.0, 12, 12); glMatrixMode (GL_MODELVIEW); glPopMatrix(); glMatrixMode (GL_PROJECTION);glPopMatrix();

The glOrtho & gluLookAt calls are for the viewing volume that I normally use. I mean, it works like this, but it''s strange that I have to reload my viewing preferences... I guess they''re getting messed up somewhere, but calls to glBegin/glEnd don''t seem to mind. Weird.

Thanks for the help =)

--
Peace,
Capt. Jean-Luc Pikachu

##### Share on other sites
quote:
Original post by Jean-Luc Pikachu
The glOrtho & gluLookAt calls are for the viewing volume that I normally use. I mean, it works like this, but it''s strange that I have to reload my viewing preferences... I guess they''re getting messed up somewhere, but calls to glBegin/glEnd don''t seem to mind. Weird.

Look around in your code and check to see if you surpassing the available stack depth with the push and pops in the GL_PROJECTION stack? I believe the OpenGL Spec for the projection stack only calls for a depth of 2 ( your results may vary )

##### Share on other sites
You only have to call your projection calls once.

Your problem originally was that you were translating every time a new frame was swapped. You need a call to glLoadIdentity(); to stop that. Try something like this:

  int PreRender(){glMatrixMode (GL_PROJECTION);glLoadIdentity();glOrtho (-150, 150, -50, 50, -50, 350);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt (70, 20, -70, 0, 0, 0, 0, 1, 0);}int RenderScene(){glPushMatrix();glColor3f(1.0f, 1.0f, 1.0f);glBegin (GL_LINES); glVertex3f (float(x), float(y), float(z)); glVertex3f (0.0f, 0.0f, 0.0f);glEnd();glPopMatrix();glPushMatrix();glColor3f (1.0f, 0.0f, 0.0f);glLoadIdentity();glTranslatef (float(x), float(y), float(z));gluSphere (sphere, 1.0, 12, 12);glPopMatrix();}

This should be sufficient enough to produce the results that you originally intended.

~Dwarf

##### Share on other sites
Actually you''re both semi right. Seems one of the routines I wrote that I was calling before time left the matrix mode as GL_PROJECTION. Once I fixed that, I just had to take your advice on loading identity and POW, everything worked.

I''m a dumbass, thanks for sticking with me!

--
Peace,
Capt. Jean-Luc Pikachu

• ### Forum Statistics

• Total Topics
627707
• Total Posts
2978721

• 21
• 14
• 12
• 22
• 35