# OpenGL [solved] Why some items wont show.

## Recommended Posts

Hi. I have a problem where I am trying to draw a unicycle. I modelled a wheel as a scaled sphere at first, and am now trying to add a tyre. (In the code below the wheel is scaled extra small so I may better see the tyre) Due to assignment constraints I have to use a tree method of connecting the items, and am currently having the wheel -> tyre (cyclinder) -> one rim (disc) -> other disc. Now I know that if there is a problem with the tree then the objects wont display, however my problem is that only the top and bottom items in the tree are displayed (IE the scaled down wheel/sphere and one rim) I have enclosed a Small Compilable Example below, although with openGL it appears there is no such thing as a small example. (Also hopefully the [ code ] [ /code ] tags work as there isn't a preview button.) So my question is does anything strike you as a good reason as to why some members of the tree are not displaying. I have attempted to play around with the rotate and translate functions but haven't come up with anything yet. The C code below can also be found here: http://myboxoftricks.homedns.org/sce.c If anyone has any ideas I would appreciate it. Kind regards, Mitch. EDIT: I've removed the code as i reckon I might be scaring people off, obviously people are looking but not replying. I cant imagine that no-one has used a tree structure before, so is there anything I can do that would make my question easier to ask? [Edited by - spudtheimpaler on April 29, 2006 4:20:48 PM]

##### Share on other sites
Just bumping the thread to indicate I've changed it.

##### Share on other sites
By tree method I assume you mean an object hierarchy of some sort. Are you using glPushMatrix() and glPopMatrix()? Proper use of these functions is usually the first step towards applying hierarchical transforms.

Another potential problem is order of operations. Generally you want to rotate and then translate, which translates into calling glTranslate*() before glRotate*() in your code. This is a common thing to get wrong, and usually results in objects not appearing where they're supposed to.

Maybe you could post just the bits of code where you set up the relevant transforms. The best tags to use for large blocks of code are probably [ source ][ /source ] (without the spaces).

##### Share on other sites
Quote:
 Original post by jykBy tree method I assume you mean an object hierarchy of some sort. Are you using glPushMatrix() and glPopMatrix()? Proper use of these functions is usually the first step towards applying hierarchical transforms.

I am indeed using those methods to form an object hierarchy (Sorry, I've been thrown into the deep end, so unfamiliar with many terms, functions etc).

Quote:
 Original post by jykAnother potential problem is order of operations. Generally you want to rotate and then translate, which translates into calling glTranslate*() before glRotate*() in your code. This is a common thing to get wrong, and usually results in objects not appearing where they're supposed to.

I was putting those the wrong way around, however it hasn't fixed the problem. I wasn't even aware it was an issue, however, so thank you for pointing it out.

Quote:
 Original post by jykMaybe you could post just the bits of code where you set up the relevant transforms. The best tags to use for large blocks of code are probably [ source ][ /source ] (without the spaces).

ok. Here we have the functions for each item on the hierachy:

////////////////////////  My Wheel Function  //////////////////////////void wheel(){   glPushMatrix();      glMaterialfv(GL_FRONT, GL_SPECULAR, wheel_specular);	  glMaterialfv(GL_FRONT, GL_AMBIENT, wheel_ambient);      glMaterialfv(GL_FRONT, GL_DIFFUSE, wheel_diffuse);  	  glTranslatef(0,-4,0);	  glScalef(0.1, 0.1, 0.1*WHEEL_WIDTH);//Change scale from 1,1,wheel_width      gluSphere(wheel_quad, WHEEL_RADIUS, 30, 30);   glPopMatrix();}////////////////////////  My Tyre Function  ///////////////////////////void tyre(){   glPushMatrix();      glMaterialfv(GL_FRONT, GL_SPECULAR, tyre_specular);	  glMaterialfv(GL_FRONT, GL_AMBIENT,  tyre_ambient);      glMaterialfv(GL_FRONT, GL_DIFFUSE,  tyre_diffuse);   	  glTranslatef(0,-4,-0.2);      glRotatef(0.0,0, 1.0, 0);//	  glScalef(1,1,1);      gluCylinder(tyre_quad, WHEEL_RADIUS, WHEEL_RADIUS, TYRE_WIDTH, 30, 30);   glPopMatrix();}void tyre_disc_left(){   glPushMatrix();      glMaterialfv(GL_FRONT, GL_SPECULAR, tyre_specular);	  glMaterialfv(GL_FRONT, GL_AMBIENT,  tyre_ambient);      glMaterialfv(GL_FRONT, GL_DIFFUSE,  tyre_diffuse);   	  glTranslatef(0,-4.0,-0.2);      glRotatef(0.0,0, 1.0, 0);//	  glScalef(1,1,0.1);      gluDisk(tyre_disc_left_quad, WHEEL_RADIUS/TYRE_WIDTH_DIVIDER, WHEEL_RADIUS, 30, 30);   glPopMatrix();}void tyre_disc_right(){   glPushMatrix();      glMaterialfv(GL_FRONT, GL_SPECULAR, tyre_specular);	  glMaterialfv(GL_FRONT, GL_AMBIENT,  tyre_ambient);      glMaterialfv(GL_FRONT, GL_DIFFUSE,  tyre_diffuse);   	  glTranslatef(0,-4,0.2);     glRotatef(00.0,0, 1.0, 0);//	  glScalef(1,1,0.1);      gluDisk(tyre_disc_right_quad, WHEEL_RADIUS/TYRE_WIDTH_DIVIDER, WHEEL_RADIUS, 30, 30);   glPopMatrix();}

with a display function that looks like this

void display(void){    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);    glLoadIdentity();    glColor3f(1.0, 1.0, 1.0);//    traverse(&torso_node);    traverse(&wheel_node);    glutSwapBuffers();}

and the traverse function (unaltered from that given to us by the lecturer)

void traverse(treenode* root){   if(root==NULL) return;   glPushMatrix();   glMultMatrixf(root->m);   root->f();   if(root->child!=NULL) traverse(root->child);   glPopMatrix();   if(root->sibling!=NULL) traverse(root->sibling);}

and the hierarchy set up as per:

////////////////////////  My own quadrics  ////////////////////////////		wheel_quad = gluNewQuadric();		gluQuadricDrawStyle(wheel_quad, GLU_FILL);						tyre_quad = gluNewQuadric();		gluQuadricDrawStyle(tyre_quad, GLU_FILL);		tyre_disc_left_quad = gluNewQuadric();		gluQuadricDrawStyle(tyre_disc_left_quad, GLU_FILL);		tyre_disc_right_quad = gluNewQuadric();		gluQuadricDrawStyle(tyre_disc_right_quad, GLU_FILL);[snip...]////////////////////////  My own Tree  ////////////////////////////////////////////////////////  Start with the wheel  ///////////////////////		glLoadIdentity();        glTranslatef(0,-4.0,0);        glRotatef(theta[0], 0.0, 1.0, 0.0);		glGetFloatv(GL_MODELVIEW_MATRIX,wheel_node.m);		wheel_node.f = wheel;		wheel_node.sibling = NULL;		wheel_node.child =  &tyre_node;//&head_node;		glLoadIdentity();		////////////////////////  Next the tyre  //////////////////////////////		glLoadIdentity();        glTranslatef(0,0,-0.2);		glRotatef(theta[1], 0, 1, 0);		glGetFloatv(GL_MODELVIEW_MATRIX,tyre_node.m);		tyre_node.f = tyre;		tyre_node.sibling = NULL;		tyre_node.child = &tyre_disc_left_node;		glLoadIdentity();////////////////////////  Add the Tyre Rims  //////////////////////////		glLoadIdentity(); 	    glTranslatef(0, 0,0);		glRotatef(theta[2], 0, 1, 0);//change this?		glGetFloatv(GL_MODELVIEW_MATRIX,tyre_disc_left_node.m);		tyre_node.f = tyre_disc_left;		tyre_node.sibling = NULL;		tyre_node.child = &tyre_disc_right_node;		glLoadIdentity();		glLoadIdentity(); 	    glTranslatef(0,0,0.4);		glRotatef(theta[3], 0, 1, 0);//change this?		glGetFloatv(GL_MODELVIEW_MATRIX,tyre_disc_right_node.m);		tyre_node.f = tyre_disc_right;		tyre_node.sibling = NULL;		tyre_node.child = NULL;		glLoadIdentity();

As mentioned the compilable example is as [link removed by spudtheimpaler: posted this a while ago, need space on the server]

Hopefully the above will help to clarify :) This has brought me to a complete halt and I know it is simply my annoyance that is blinding me to the obvious answer.

Many thanks :)

Mitch

[Edited by - spudtheimpaler on May 21, 2006 12:37:29 PM]

##### Share on other sites
Solved.

glLoadIdentity(); 	    glTranslatef(0, 0,0);		glRotatef(theta[2], 0, 1, 0);//change this?		glGetFloatv(GL_MODELVIEW_MATRIX,tyre_disc_left_node.m);		tyre_node.f = tyre_disc_left;		tyre_node.sibling = NULL; //**		tyre_node.child = &tyre_disc_right_node;		glLoadIdentity();

//** tyre_node.sibling etc should be tyre__disc_left_node.blah

Thanks for your help though :)

Mitch.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627674
• Total Posts
2978558
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 11
• 11
• 10
• 12
• 22