Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL cube not rendering properly
    primarykey
    data
    text
    <p>I have a problem when rendering cubes in OpenGL.I am drawing two cubes, one is a wire cube and is centered around the origin, while the other is offset from the origin and is solid. I have mapped some keys to rotate the objects by some degrees wrt to the origin, so the whole scene can rotate around the origin.</p> <p>The problem is, when I render the scene, when the wire cube is supposed to be infront of the other solid cube, it does not display itself correctly.</p> <p><img src="https://i.stack.imgur.com/ZnboZ.jpg" alt="enter image description here"></p> <p>In the image above, the colored cube is supposed to be behind the wire cube. i.e. the green wire cube should be on top. </p> <p>Also the cube is not behaving properly.</p> <p><img src="https://i.stack.imgur.com/i3Rfr.jpg" alt="enter image description here"></p> <p>After I rotate it a little bit around the x axis (current horizontal line).</p> <p>The cube has missing faces and is not rendering correctly. What am I doing wrong?</p> <p>I have coded the following Note that rotateX,rotateY,rotateZ are mapped to keys, and are my global rotation variables.</p> <pre><code>//The Initialize function, called once: void Init(){ glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background glClearDepth(1.0f); // Depth Buffer Setup glEnable(GL_DEPTH_TEST); // Depth Buffer Setup // Enables Depth Testing glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations glEnable(GL_LIGHTING); } void draw(){ //The main draw function glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity (); gluPerspective(45, 640/480.0, .5, 100); glMatrixMode(GL_MODELVIEW); //select the modelview matrix. glLoadIdentity (); gluLookAt(0,0,5, 0,0,0, 0,1,0); glRotatef(rotateX,1,0,0); glRotatef(rotateY,0,1,0); glRotatef(rotateZ,0,0,1); drawScene(); // this just draws the main axis lines, glutWireCube(1); glPopMatrix(); glPushMatrix(); glTranslatef(-2,1,0); drawNiceCube(); glPopMatrix(); glutSwapBuffers(); } </code></pre> <p>The code for the drawNiceCube() is just using GL_QUADS, while the drawWireCube is built in in GLUT. </p> <p>EDIT: I have posted the full code at <a href="http://pastebin.com/p1kwPjEM" rel="nofollow noreferrer">http://pastebin.com/p1kwPjEM</a>, sorry if it is not well documented.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload