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 8882775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:39:43+00:00 2026-06-14T20:39:43+00:00

In this code I try to draw a cube.I try to draw all faces

  • 0

In this code I try to draw a cube.I try to draw all faces vertices anticlockwise.
The problem is that if I don’t rotate the cube only the red face is drawn, if instead I rotate it of 5 degrees, I just see a part of the cube.

#import <OpenGL/OpenGL.h>
#import <GLUT/GLUT.h>

int width=500, height=500, depth=500;

void init()
{
    glEnable(GL_DEPTH_TEST);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(200, 200,-200, 200, 200, 0, 0, 1, 0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0,width,0,height);
    gluPerspective(90, 1, -100, 100);
    glViewport(0, 0, width, height);
}

void drawCube()
{
    int vertices[8][3]= { {100,100,0} , {300,100,0}, {300,300,0}, {100,300,0}, {100,100,300} , {300,100,300}, {300,300,300}, {100,300,300} };
    glBegin(GL_QUADS);

    glColor4f(1, 0, 0, 0);
    glVertex3iv(vertices[0]);
    glVertex3iv(vertices[1]);
    glVertex3iv(vertices[2]);
    glVertex3iv(vertices[3]);

    glVertex3iv(vertices[4]);
    glVertex3iv(vertices[5]);
    glVertex3iv(vertices[6]);
    glVertex3iv(vertices[7]);

    glColor4f(0, 1, 0, 0);
    glVertex3iv(vertices[1]);
    glVertex3iv(vertices[5]);
    glVertex3iv(vertices[6]);
    glVertex3iv(vertices[4]);

    glVertex3iv(vertices[0]);
    glVertex3iv(vertices[4]);
    glVertex3iv(vertices[7]);
    glVertex3iv(vertices[3]);

    glColor4f(0, 0, 1, 0);
    glVertex3iv(vertices[3]);
    glVertex3iv(vertices[2]);
    glVertex3iv(vertices[6]);
    glVertex3iv(vertices[7]);

    glVertex3iv(vertices[0]);
    glVertex3iv(vertices[1]);
    glVertex3iv(vertices[5]);
    glVertex3iv(vertices[4]);

    glEnd();
}


void display()
{
    glClearColor(0.0, 0.0, 0.0, 0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(200,200,150);
    glRotatef(5, 0, 1, 0);
    glTranslatef(-200,-200,-150);
    drawCube();
    glutSwapBuffers();
}

void idle(void)
{
}

int main(int argc, char * argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(width, height);
    glutCreateWindow("Test");
    glutDisplayFunc(display);
    glutIdleFunc(idle);
    init();
    glutMainLoop();
    return 0;
}

This is what I see:

Window

But I should see a rotated cube, so I should see the part of the other face on the right.My doubt is that I’m going wrong with drawing the vertices in anticlockwise order, or something else.

PS: the code is outdated, because at my university I don’t have the possibility to study the newest version of OpenGL, and I must use GLUT.

  • 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-06-14T20:39:44+00:00Added an answer on June 14, 2026 at 8:39 pm

    Couple problems:

    1. Your projection matrix setup is not sensical.

      Firstly, you should decide if you want an orthographic, or a perspective projection.

      If you want orthographic, use gluOrtho2d. If you want a perspective projection, use gluPerspective. Using both will generate a bizarre transformation that’s certainly not what you want.

    2. gluPerspective can’t have a negative near plane. The near plane should be greater than zero, perhaps something small like 1, with a far plane defining how far away from the camera you want the back clip plane to be. Since you seem to be using units in the hundreds, I might recommend a back plane of 1000 or so.

    3. You’re calling gluLookAt, but erasing the view matrix by calling glLoadIdentity in display(). If you want a view matrix, don’t erase it after you program it.

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

Sidebar

Related Questions

in this code i'm try to draw simple olympic ring and rotate it... the
I try to draw some lines with different colors. This code tries to draw
i try to draw arc in view i use this code. - (void)viewDidLoad {
I have this code try { //AN EXCEPTION IS GENERATED HERE!!! } catch {
I have this code: try { var _o, _l, i, _d = new Array(),
I have this snipped code: try{ JAXB.xmlJavaConverter(clientCommand); } catch (Exception e){ nServerFifo.add(clientCommand); } I
I've written this code to try and send a url as a post value
Why is this code correct: try { } catch(ArrayOutOfBoundsException e) {} and this wrong:
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
When I try this code: dict_a = dict_b = dict_c = {} dict_c['hello'] =

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.