PDA

View Full Version : Two objects



Iulian
03-12-2012, 04:46 PM
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...

tonyo_au
03-12-2012, 05:51 PM
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

Iulian
03-13-2012, 02:14 AM
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. :P

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

nsdev
03-13-2012, 03:59 AM
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).