Results 1 to 4 of 4

Thread: Problems just resizing a cube

  1. #1
    Member Contributor
    Join Date
    Apr 2007
    Posts
    80

    Problems just resizing a cube

    Hi,

    i have found the code below to draw a cube.

    Then i have modified the code to draw a another cube but ten times bigger.

    The original code shows a very little cube without problems.

    But the second code i have write dont show anything at all...

    This is the original code:

    glBegin(GL_QUADS); // Draw The Cube Using quads
    glColor3f(0.0f,1.0f,0.0f); // Color Blue
    glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)
    glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)
    glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)
    glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)
    glColor3f(1.0f,0.5f,0.0f); // Color Orange
    glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)
    glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)
    glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)
    glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)
    glColor3f(1.0f,0.0f,0.0f); // Color Red
    glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)
    glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)
    glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)
    glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)
    glColor3f(1.0f,1.0f,0.0f); // Color Yellow
    glVertex3f( 1.0f,-1.0f,-1.0f); // Top Right Of The Quad (Back)
    glVertex3f(-1.0f,-1.0f,-1.0f); // Top Left Of The Quad (Back)
    glVertex3f(-1.0f, 1.0f,-1.0f); // Bottom Left Of The Quad (Back)
    glVertex3f( 1.0f, 1.0f,-1.0f); // Bottom Right Of The Quad (Back)
    glColor3f(0.0f,0.0f,1.0f); // Color Blue
    glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)
    glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)
    glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)
    glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)
    glColor3f(1.0f,0.0f,1.0f); // Color Violet
    glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)
    glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)
    glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)
    glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)
    glEnd();


    This is the code i have modified to make the cube 10 times bigger.


    // Draw a filled rectangle with current color
    glBegin(GL_QUADS); // Draw The Cube Using quads
    glColor3f(0.0f,10.0f,0.0f); // Color Blue
    glVertex3f( 10.0f, 10.0f,-10.0f); // Top Right Of The Quad (Top)
    glVertex3f(-10.0f, 10.0f,-10.0f); // Top Left Of The Quad (Top)
    glVertex3f(-10.0f, 10.0f, 10.0f); // Bottom Left Of The Quad (Top)
    glVertex3f( 10.0f, 10.0f, 10.0f); // Bottom Right Of The Quad (Top)
    glColor3f(10.0f, 0.5f,0.0f); // Color Orange
    glVertex3f( 10.0f,-10.0f, 10.0f); // Top Right Of The Quad (Bottom)
    glVertex3f(-10.0f,-10.0f, 10.0f); // Top Left Of The Quad (Bottom)
    glVertex3f(-10.0f,-10.0f,-10.0f); // Bottom Left Of The Quad (Bottom)
    glVertex3f( 10.0f,-10.0f,-10.0f); // Bottom Right Of The Quad (Bottom)
    glColor3f(10.0f,0.0f,0.0f); // Color Red
    glVertex3f( 10.0f, 10.0f, 10.0f); // Top Right Of The Quad (Front)
    glVertex3f(-10.0f, 10.0f, 10.0f); // Top Left Of The Quad (Front)
    glVertex3f(-10.0f,-10.0f, 10.0f); // Bottom Left Of The Quad (Front)
    glVertex3f( 10.0f,-10.0f, 10.0f); // Bottom Right Of The Quad (Front)
    glColor3f(10.0f,10.0f,0.0f); // Color Yellow
    glVertex3f( 10.0f,-10.0f,-10.0f); // Top Right Of The Quad (Back)
    glVertex3f(-10.0f,-10.0f,-10.0f); // Top Left Of The Quad (Back)
    glVertex3f(-10.0f, 10.0f,-10.0f); // Bottom Left Of The Quad (Back)
    glVertex3f( 10.0f, 10.0f,-10.0f); // Bottom Right Of The Quad (Back)
    glColor3f(0.0f,0.0f,1.0f); // Color Blue
    glVertex3f(-10.0f, 10.0f, 10.0f); // Top Right Of The Quad (Left)
    glVertex3f(-10.0f, 10.0f,-10.0f); // Top Left Of The Quad (Left)
    glVertex3f(-10.0f,-10.0f,-10.0f); // Bottom Left Of The Quad (Left)
    glVertex3f(-10.0f,-10.0f, 10.0f); // Bottom Right Of The Quad (Left)
    glColor3f(10.0f,0.0f,10.0f); // Color Violet
    glVertex3f( 10.0f, 10.0f,-10.0f); // Top Right Of The Quad (Right)

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: Problems just resizing a cube

    And ten times more colorful as well, eh?
    glColor3f(0.0f,10.0f,0.0f); // Color Blue
    That's green.

    What about the missing glEnd()?

    Depending on your matrix setup the cube might not even be inside the frustum but around it.

  3. #3
    Member Contributor
    Join Date
    Apr 2007
    Posts
    80

    Re: Problems just resizing a cube

    it is true...

    anyway, glEnd() is written also.

    I dont know it is inside of the frustum. Im gonna look for more information.

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: Problems just resizing a cube

    Check the code for occurances of:
    glMatrixMode, GL_PROJECTION, GL_MODELVIEW,
    gluPerspective, glFrustum, glOrtho.

    All these affect your viewing setup. You should read their manuals and also check the OpenGL Programming Guide on transformations. There is a redbook.pdf to be found on the internet.

    If you're lost, put this code in front of your rendering call above and the big cube will definitely appear in the center:

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0, 1.0, 1.0, 39.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -20.0f);
    // Now your drawing calls
    glBegin...

    If you're unsure if you rendered black-on-black, it's always a good idea to set the glClearColor() to something different than the default black.

Similar Threads

  1. Problems with my mouse function after resizing
    By Schieby in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-09-2013, 07:53 AM
  2. help: problems resizing GLX windows
    By bootstrap in forum OpenGL: Linux
    Replies: 1
    Last Post: 03-23-2008, 09:32 AM
  3. Resizing problems in Splitter Views (MFC)
    By tlaepple in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 01-28-2002, 02:45 AM
  4. Resizing Problems in Splitter Windows (MFC)
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-28-2002, 02:18 AM
  5. newbie : problems resizing window
    By sagilca in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-02-2001, 06:38 AM

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