Results 1 to 4 of 4

Thread: My cube again :)

  1. #1

    My cube again :)

    I got some pictures of my cube I made, it looks like this, why is it wrong?
    First it look like this, when rotating: Cube Pic 1
    Then after rotating some more it looks like this:
    Cube Pic 2
    And after even some more rotating like this:
    Cube Pic 3

    Why?
    My code is like this and last in the code u can see my Perspective:

    void createRoom(float langd, float hojd, float bredd, GLuint texture_id)
    {
    glPushMatrix();
    glBindTexture ( GL_TEXTURE_2D, texture_id);
    glBegin(GL_QUADS);
    /*front*/
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(0.0f, 0.0f, 0.0f); //bottom left
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(langd, 0.0f, 0.0f); //bottom right
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(langd, hojd, 0.0f); // top right
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(0.0f, hojd ,0.0f); //top left

    /*Back*/
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(langd, 0.0f, bredd); //bottom right
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(langd, hojd, bredd); //top right
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(0.0f, hojd, bredd); // top left
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0.0f, 0.0f, bredd); //bottom left

    /*Top*/
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(0.0f, hojd, 0.0f); //top left
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(0.0f, hojd, bredd); //bottom left
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(langd, hojd,bredd); //bottom right
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(langd, hojd, 0.0f); //top right

    /*botten*/
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(langd, 0.0f, 0.0f); //top right
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(0.0f, 0.0f, 0.0f); //top left
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0.0f, 0.0f, bredd); //bottom left
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(langd, 0.0f, bredd); //bottom right

    /*Right*/
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(langd, 0.0f, bredd); // bottom right
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(langd, hojd, bredd); // top right
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(langd, hojd, 0.0f); // top left
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(langd, 0.0f, 0.0f); // bottom left

    /*Left*/
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(0.0f, 0.0f, 0.0f); //bottom left
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(0.0f, 0.0f, bredd); //bottom right
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(0.0f, hojd, bredd); //top right
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0.0f, hojd, 0.0f); //top left

    glEnd();
    glDisable(GL_TEXTURE_2D);
    glPopMatrix();
    }

    ----------------------------
    Code in my resize function:
    -----------------------------
    ...
    gluPerspective(45.0f,(GLfloat) width / (GLfloat) height, 0.01f, 10000.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0,0.0,5.0,
    0.0,0.0,-1.0,
    0.0f,1.0f,0.0f);
    ...
    --------------------------------
    This is how I create the cube
    --------------------------------
    createRoom(1.0f,1.0f,1.0f,texture_id[WALL1_TEXTURE]);

    Hope to get a answer and if the code are wrong?
    regards Nergal

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: My cube again :)

    Becuase some sides of the cube has it's vertices winded in the wrong order and you have back face culling enabled.

    Take the front and back side of the cube as an example. When looking at the front side of the front face, you will see the vertices in counter clockwise order. This is the default order OpenGL's face culling treats as front face. Now, if you look at the back face, you will see it's vertices is ordered in clockwise order (remember that it's front is facing the oposite direction, so you have to rotate the cube 180 degrees before looking at it's winding order), which is the default order for a back face, and it will be removed if you have back face culling enabled.

  3. #3

    Re: My cube again :)

    aha, how to disable back face culling than?
    regards Nergal

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: My cube again :)

    glDisable(GL_CULL_FACE) maybe.

Similar Threads

  1. Cube Map without using OpenGL's Cube Mapping
    By someoney in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-10-2010, 01:05 PM
  2. display a cube inside another bigger cube
    By jyoung77 in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 05-08-2003, 06:12 PM
  3. Wire Cube, and Cube and GUI
    By tony_ee81 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 09-20-2002, 12:58 PM
  4. Cube,Cube and a Cylinder
    By tony_ee81 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-03-2002, 12:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean