Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7500071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:03:20+00:00 2026-05-29T20:03:20+00:00

I have a problem when rendering cubes in OpenGL.I am drawing two cubes, one

  • 0

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.

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.

enter image description here

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.

Also the cube is not behaving properly.

enter image description here

After I rotate it a little bit around the x axis (current horizontal line).

The cube has missing faces and is not rendering correctly.
What am I doing wrong?

I have coded the following
Note that rotateX,rotateY,rotateZ are mapped to keys, and are my global rotation variables.

//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();
}

The code for the drawNiceCube() is just using GL_QUADS, while the drawWireCube is built in in GLUT.

EDIT:
I have posted the full code at http://pastebin.com/p1kwPjEM, sorry if it is not well documented.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:03:23+00:00Added an answer on May 29, 2026 at 8:03 pm

    datenwolf solved my problem. I quote him:

    “@JonathanSimbahan: Parts of your code are redundant, but something is missing: You forgot to call Init(); after creating your GLUT window, hence depth testing and all the other state never get enabled. I for one suggest you don’t use Init at all and move it’s code into the drawing code, where it actually belongs.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with directX 9. I have a problem while rendering triangles using
I have a problem. I am calculating position of some points for opengl rendering.
I have a problem with the rendering of a cube. I don't know why
I have a problem with rendering my html page by the same browsers in
Ok, here's a problem I'm having. I have Lua bindings to a rendering engine
I have some weird problem in rendering some xhtml in IE 8 http://img709.imageshack.us/i/scrj.png/ .
I have a problem with my matrix not rendering properly in HTML. It's a
i have a problem with rendering image on RDL file in reporting services (SQL
today I have a (simple) rendering problem for you. My current project gets datas
I have been having a font rendering problem with GVim on Ubuntu for quite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.