Two objects

Hello… I have just started using GLUT, and I can’t figure out how I can make to have on the screen two object at the same time, that are “activated” by keyboard…

Lets say i have 2 cubes, one appears on ‘a’ one on ‘b’… But when I press ‘b’, the 1st one dissapears… I can’t really figure it out…

GLUT does not control OpenGL drawing; you control what is drawn by the code inside the procedure set in glutDisplayFunc. If you want 2 cubes draw you must draw 2 cubes each time that procedure is called. You may need to post this procedure if you want more information


if(tasta=='a'){
     glColor3f(0.0f, 1.0f, 1.0f);
     glPushMatrix();
     glTranslatef(-5,0.0f,-30);
     glutSolidCube(5);
     glPopMatrix();
     }
     
if(tasta=='s'){
     glColor3f(1.0f, 1.0f, 1.0f);
     glPushMatrix();
     glTranslatef(0,0.0f,-30);
     glutSolidCube(5);
     glPopMatrix();
     }

So this is how it looks like… If you need more of the code just tell. :stuck_out_tongue:

And same problem with an cube that is rotating around (0,0,0), i want to keep all the possitions.

As tonyo_au already pointed out you see only one cube as you only draw one: as the variable “tasta” may only hold one value it may be either ‘a’ or ‘s’ (or something else in which case probably nothing is displayed).