# OpenGL Problems redering...possibly with glpush/popstack

This topic is 5113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I'm very new at this so please excuse my stupidity. I'm trying to draw an arm of a robot. But openGL is only drawing the first object I draw correctly. The rest of them are black, not connected to the first object, but connected to each other. When I remove the glpush/popmatrix functions from the code, they start attaching to each other, are the right color, but each object drawn after the other gets smaller and smaller. I don't know why....I've been fooling around with this for too long and it still isn't working. Oh, I am using glut in visual c++...in case that information matters. Any suggestions on how I could get this to work will be very, very, appreaciated! The following are some snippets from my code if it helps:
***********************
From the display function.
**************************

glPushMatrix();
gluPerspective(65.0, 1/1, 1.0, 20.0);
glTranslatef(0.0, 0.0, -5.0);

glRotatef( SceneRotateX, 1.0, 0.0, 0.0);
glRotatef( SceneRotateY, 0.0, 1.0, 0.0);
// This is where I draw the arm.
arm.am_DrawArm(0.0f, 0.0f, 0.0f);

glPopMatrix();


******************************
The am_DrawArm function
******************************
void CArmModel::am_DrawArm(float xpos, float ypos, float zpos)
{
glPushMatrix();

glTranslatef(-myRobot[UPPER_ARM].length, 0.0, 0.0);
glRotatef(myRobot[UPPER_ARM].rotation, 0.0, 0.0, 1.0);

am_Shoulder(myRobot[SHOULDER].length/2.0, 0.0, 0.0);
am_UpperArm(myRobot[UPPER_ARM].length/2.0, 0.0, 0.0);
am_Elbow(myRobot[UPPER_ARM].length/2.0, 0.0, 0.0);
am_LowerArm(myRobot[LOWER_ARM].length/2.0, 0.0, 0.0);
.....
glPopMatrix();
}


***************************
the arm functions
***************************

**************************************************************
I wouldn't thing that commenting out the glPushMatrix and glPopMatrix should work, but it sort of does. Of course when I draw the fingers, commenting them out doestn't work.
**************************************************************

void CArmModel::am_Shoulder(float xpos, float ypos, float zpos)
{
glTranslatef(xpos, ypos, zpos);
//glPushMatrix();
glColor3f(0.99,0.77,0.72);
glScalef(myRobot[SHOULDER].length, myRobot[SHOULDER].height,
myRobot[SHOULDER].width);
glutSolidSphere(0.6,100,100);
//glPopMatrix();
}

void CArmModel::am_UpperArm(float xpos, float ypos, float zpos)
{
glTranslatef(xpos, ypos, zpos);
//	glPushMatrix();
glColor3f(0.99,0.72,0.67);
glScalef(myRobot[UPPER_ARM].length, myRobot[UPPER_ARM].height,
myRobot[UPPER_ARM].width);
glutSolidCube(1.0);
//	glPopMatrix();
}

void CArmModel::am_Elbow(float xpos, float ypos, float zpos)
{
glTranslatef(xpos, ypos, zpos);
//	glPushMatrix();
glColor3f(0.99,0.77,0.72);
glScalef(myRobot[ELBOW].length, myRobot[ELBOW].height,
myRobot[ELBOW].width);
glutSolidSphere(0.55,100,100);
//	glPopMatrix();
}

void CArmModel::am_LowerArm(float xpos, float ypos, float zpos)
{
glRotatef(myRobot[LOWER_ARM].rotation, 0.0, 0.0, 1.0);
glTranslatef(xpos, ypos, zpos);

//	glPushMatrix();
glColor3f(0.99,0.75,0.70);
glScalef(myRobot[LOWER_ARM].length, myRobot[LOWER_ARM].height,
myRobot[LOWER_ARM].width);
glutSolidCube(1.0);
//	glPopMatrix();
}

.......



evolutional - Added source tags [Edited by - evolutional on September 15, 2004 12:10:15 PM]

##### Share on other sites
the reason the parts are getting smaller and smaller is you are compounding the scale factor on each arms (so if the first scale makes the cube 1/2 size and the next scale factor is also 1/2 then the cube will infact end up 1/4 size (assuming my maths is correct [grin]).

So, the useage of glpush/glpop was right in this instance, the problem lays else where in the code, as to where I dunno [smile]

note: when posting source code its a better idea to post is in a [ source ] [ /source ] block (without the spaces before and after the brackets). Its also a good idea not to post everything in one block as well [smile]

##### Share on other sites
Try to follow a hierarchy of your model legs,arms etc.
Watch for push-pop pairs this could be a problem poping twice or
not at all.
The model gets smaller and smaller because you commented those glPush and glPops so you scale in fact twice...
I really can't see where it's the problem.Try a glLoadIdentity()at the beginning the RenderScene function ,i don't think it will work but it worths a try

##### Share on other sites

Hello,

Thanks for the help. I solved one problem. You guys were right: it wasn't a push/pop problem. It was more of a problem with my perspective and views.

I still have another problem:

My object now looks and moves the way it should, but the coloring is all wrong. Without any lighting except the default, my object is black (no coloring) and it looks more like a shadow i.e. i can't see the individual pieces of the object.

When I give it white ambient lighting, the color is a washed out version of what it should be...but I can see the individual objects that make up the arm.

Any ideas on how to fix this problem?

Thanks.

ps. Sorry about the long source post. New to the message boards too.

##### Share on other sites

opps. Sorry. I should also mention that I've played around with different lighting colors, moving the object back and forth, and changing the projection perspective parameters. No luck.

Thanks again.

##### Share on other sites
A lot of my lighting problems have been down to incorrectly setting up normals for my vertices, having wrong lighting attenuation values or having bright ambient coloured lighting. It may be a good idea to look at this area of your program in the first instance as you didn't post this code up previously.

##### Share on other sites

How would I change the lighting attenuation? Or make sure my ambient lighting isn't too bright? (I'm using white light)

Thanks again.

##### Share on other sites
I took out a call I had to glLightfv and that fixed my problem.

Thank you all for your help!

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5
frob
13

• 9
• 15
• 10
• 9
• 17
• ### Forum Statistics

• Total Topics
632602
• Total Posts
3007364

×