Results 1 to 9 of 9

Thread: how to draw a room with walls

  1. #1
    Member Newbie
    Join Date
    Sep 2002
    Posts
    40

    how to draw a room with walls

    Hi,
    I have to draw a simple room with walls and floor, using gl_quads(rectangle)
    Could someone tell me how to go about doing that,
    Thanks

  2. #2
    Member Newbie
    Join Date
    Nov 2002
    Location
    Germany
    Posts
    48

    Re: how to draw a room with walls

    gl_quads(rectangle) ???

    How about drawing six quads? This would draw a 2x2x2 room (or cube):

    glBegin(GL_QUADS)
    /* Floor */
    glVertex3f(-1,-1,-1);
    glVertex3f(1,-1,-1);
    glVertex3f(1,-1,1);
    glVertex3f(-1,-1,1);
    /* Ceiling */
    glVertex3f(-1,1,-1);
    glVertex3f(1,1,-1);
    glVertex3f(1,1,1);
    glVertex3f(-1,1,1);
    /* Walls */
    glVertex3f(-1,-1,1);
    glVertex3f(1,-1,1);
    glVertex3f(1,1,1);
    glVertex3f(-1,1,1);

    glVertex3f(-1,-1,-1);
    glVertex3f(1,-1,-1);
    glVertex3f(1,1,-1);
    glVertex3f(-1,1,-1);

    glVertex3f(1,1,1);
    glVertex3f(1,-1,1);
    glVertex3f(1,-1,-1);
    glVertex3f(1,1,-1);

    glVertex3f(-1,1,1);
    glVertex3f(-1,-1,1);
    glVertex3f(-1,-1,-1);
    glVertex3f(-1,1,-1);
    glEnd();
    Knowledge is Power

  3. #3
    Member Newbie
    Join Date
    Sep 2002
    Posts
    40

    Re: how to draw a room with walls

    Thats exactly what i was trying to do.
    Thank you,

    well but how can I control their appearance probably by setting their material property or something like that , so that i get that 3D effect in there.

  4. #4
    Member Newbie
    Join Date
    Sep 2002
    Posts
    40

    Re: how to draw a room with walls

    Hello,
    My second problem is how to get a drawing (any kind of painting or frame) on one of those walls....anything i drwa seems to cover the entie room. It has to be inside the room on the wall...
    Can someone help?

    Thanks,
    lara

  5. #5
    Member Newbie
    Join Date
    Nov 2002
    Location
    Germany
    Posts
    48

    Re: how to draw a room with walls

    Maybe you should read an OpenGL tutorial first. =)

    Well, you can color the walls by using glColor*(), for example glColor3f(red,green,blue). The values for red, green and blue have to be (0 <= value <= 1). You can use this command for every vertex. Just set the vertex color before calling glVertex*(). If you want the vertex colors to be interpolated within a polygon, you can set the shading model to smooth:

    glShadeModel(GL_SMOOTH);

    And you want to put things into the room? You can draw them like you've drawn the room itself. Remember the room is 2x2x2, so your objects should be smaller. You can, of course, use floating point numbers for coordinates. Also remember that the y-coordinate for the floor of that room is -1, so you'll want to draw from -1 upwards.

    Material color and stuff like that? You'll probably want to add textures (so the polygon appears as a picture). This is such a big topic, I can't explain it all here. There are just a few commands, but to understand all of it, you should read a good texture mapping tutorial. You'll find a lot of links to information resources on this site.

    [This message has been edited by mm_freak (edited 11-08-2002).]
    Knowledge is Power

  6. #6
    Member Newbie
    Join Date
    Sep 2002
    Posts
    40

    Re: how to draw a room with walls

    Hi,
    Well I already colored my walls and yes read the Red Book too.
    But the problem seemed graver than what i expected. At present I have colored each wall with a separate color...because I really dont need to go into texture and all for this project..as you said it is seemingly complicated and I want to concentrate on this part first.
    The reason why i color each wall with a separate color is , otherwsie it all blends into the same thing..and then i can no longer make out the room..but just one rectangle....
    IS there a way I can not loose the 3D effect and still have all the walls the same color...
    moreover i actually have a new post in which i explained how as soon as i enable one light ..everything becomes a grey rectangle.
    I think I have too many questions for now.
    Thanks for your help though

  7. #7
    Member Newbie
    Join Date
    Nov 2002
    Location
    Germany
    Posts
    48

    Re: how to draw a room with walls

    No problem. Did you enable material colors? I guess not. glEnable(GL_COLOR_MATERIAL) should do the job. But there is a major problem with lighting. OpenGL's lighting is not, as you may have expected, pixel-oriented, but vertex-oriented. A solution would be to split up all walls of that room into about 16 or more polygons. I recommend you to write an algorhythm to split up polygons into many quads. Well... don't use too many, else performance will be lost. The second solution is to calculate the light by yourself, but then you'll need to rely on textures.
    Knowledge is Power

  8. #8
    Member Newbie
    Join Date
    Jun 2002
    Posts
    33

    Re: how to draw a room with walls

    Also to make the lights work you need to define normals for each of your walls. Normals are vetors that are perpendicular to the surface you want lit. So for instance the top wall (ceiling I gues the normal has to be (0,-1,0) To assign a normal to a vertex you must call the correct function I think gl_normal3f(0,0,-1). This is set for all vertices until you change it to something else.

    fringe

  9. #9
    Junior Member Newbie
    Join Date
    Nov 2011
    Posts
    4

    Re: how to draw a room with walls

    Hello ,, I'v tried this example and it works fine ,but is there a way to create a room similar to this ,,
    http://img694.imageshack.us/img694/692/roomzc.jpg

    because in the first one , you cant really differentiate between the back-wall and ceiling or floor ..
    Thanks ..

Similar Threads

  1. OpenGl 3D Room
    By Torrtuga in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 04-28-2015, 12:16 PM
  2. Draw a room
    By phuongmaruko in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 12-07-2010, 10:41 AM
  3. Making a room
    By nergal in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-27-2002, 07:32 AM
  4. How to create a room??
    By new_to_opegl in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-25-2002, 06:11 AM
  5. modelling a room
    By fox in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-20-2001, 02:10 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