Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: A 3d House

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jul 2003
    Location
    Bangalore, Karnataka, India
    Posts
    123

    A 3d House

    #include <GL/glut.h>
    Dear All,

    I want to render to a 3d House(barn) . I wrote the following code.But its creating only front side with a triangle and a rectangle.It is not creating a thacthed house.What modifications should I make

    void render(void)
    {
    GLfloat x,y,z,angle;
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glRotatef(xRot,1.0f,0.0f,0.0f);
    glRotatef(yRot,0.0f,1.0f,0.0f);
    glColor3f(0.0f,1.0f,1.0f);
    glTranslatef(0.0,0.0,-5.0);
    glBegin(GL_POLYGON);
    glVertex3f(0.0,0.0,0.0);
    glVertex3f(1.0,0.0,0.0);
    glVertex3f(1.0,1.0,0.0);
    glVertex3f(0.5,1.5,0.0);
    glVertex3f(0.0,1.0,0.0);
    glVertex3f(0.0,0.0,1.0);
    glVertex3f(1.0,0.0,1.0);
    glVertex3f(1.0,1.0,1.0);
    glVertex3f(0.5,1.5,1.0);
    glVertex3f(0.0,1.0,1.0);
    glEnd();
    glPopMatrix();
    glutSwapBuffers();
    /* glFlush(); */
    }


    Regards

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,052

    Re: A 3d House

    You canīt create more than one polygon the way you tried it. Do this instead:

    glBegin(GL_POLYGON);
    glVertex3f(0.0,0.0,0.0);
    glVertex3f(1.0,0.0,0.0);
    glVertex3f(1.0,1.0,0.0);
    glVertex3f(0.5,1.5,0.0);
    glVertex3f(0.0,1.0,0.0);
    glEnd ();

    glBegin(GL_POLYGON);
    glVertex3f(0.0,0.0,1.0);
    glVertex3f(1.0,0.0,1.0);
    glVertex3f(1.0,1.0,1.0);
    glVertex3f(0.5,1.5,1.0);
    glVertex3f(0.0,1.0,1.0);
    glEnd();
    GLIM - Immediate Mode Emulation for GL3

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2003
    Location
    Atlanta, GA, USA
    Posts
    5

    Re: A 3d House

    There are rules to follow when creating polygons.
    First, all points of a single polygon must lay on a single plain. Thats why triangles are so often used, because any 3 points will always lay on a single plain.
    Second, all points must be plotted either clockwise or counterclockwise, depending on which left/right hand rule you are using.
    Lastly, this is a little hard to explain, you can not create concave polygons. If there is a point in your polygon that may lay inside of subsequent point, it will be skipped. Odd results can occure from concave polygons.
    Anywho, that's my two cents.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •