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: Creating a Room

  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    1

    Question Creating a Room

    hi guys..

    i working on a project in open gl for how to draw a room and 6 objects in it, but i had some problems, the colors of the objects doesn't show .

    can any body help me with this project ??

    here is the Code:



    Code :
    #include<glut.h>
     
     
      int i=0,j=0;
     
    float eyex=0, eyey=1,eyez=0;
    float centx=0 ,centy=0,centz=-100;
    float upx=0 ,upy=1,upz=0;
     
    void pressKey(int key, int x, int y) {
    glutPostRedisplay();
            switch (key) {
     
      case GLUT_KEY_LEFT : 
            eyex-=2;
      ;break;
      case GLUT_KEY_RIGHT : 
            eyex+=2;
      ;break;
      case GLUT_KEY_UP : 
        eyey+=2;
            break;
      case GLUT_KEY_DOWN : 
        eyey-=2;
            break;
      case GLUT_KEY_HOME :
            eyez-=2;
        break;
      case GLUT_KEY_END : 
            eyez+=2;
     
            break;
     
     
      case GLUT_KEY_F2 : 
        centx+=5;
            break;
      case GLUT_KEY_F3 : 
        centx-=5;
            break;
      case GLUT_KEY_F4 : 
        centy+=5;
            break;
      case GLUT_KEY_F5 : 
        centy-=5;
            break;
      case GLUT_KEY_F6 : 
        centz+=5;
            break;
      case GLUT_KEY_F7 : 
        centz-=5;
            break;
     
      case GLUT_KEY_INSERT : 
        eyex=0, eyey=1,eyez=0;
     centx=0 ,centy=0,centz=-100;
     upx=0 ,upy=1,upz=0;
            break;
     
            }
    }
     
     
    void reshape(int w, int h)
    {
            glViewport(0, 0, w, h);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
      gluPerspective(45.0, (float)w/(float)h, 1.0, 800.0);
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
    }
     
     
     
     
    void Init()
    {
            glClearColor(5, 6, 4, 0.0);  
            glEnable(GL_DEPTH_TEST);
            glEnable(GL_LIGHT0);
            glEnable(GL_LIGHTING);
     
    }    
     
    void render(void) 
    {
     
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glLoadIdentity();
     gluLookAt( eyex, eyey, eyez, centx, centy, centz, upx, upy, upz );
     
     
            glPushMatrix();
    		glColor3f(0.0f, 1.0f, 0.0f);
      glTranslatef(1.5,3.0,-22.0);
            glutSolidTeapot(2);
         glPopMatrix();
     
            /*----------------FLOOR--------------*/
     
            glDisable(GL_DEPTH_TEST);
     
     
            glPushMatrix();
      glTranslatef(0,0,-11.0);
        glRotatef(90,1,0,0);
      glScalef(4,4,4);
          glColor3f( 1 ,  0 , 0 );
     
         glEnd();
        glPopMatrix();
    	glPushMatrix();
    	glColor3i(1,1,0);
    	glutSolidCube(50);
    	glPopMatrix();
     
            glEnable(GL_DEPTH_TEST);
     
    /*----------------FLOOR--------------*/
     
        glutSwapBuffers();
     
    }
     
    void main(int argc, char **argv) {
            glutInit(&argc, argv);
            glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
            glutInitWindowPosition(100,100);
            glutInitWindowSize(320,320);
            glutCreateWindow("The Room");
     
            Init();
            glutDisplayFunc(render);
    /***********************/
            glutIdleFunc(render); 
    //      glutIgnoreKeyRepeat(1);
            glutSpecialFunc(pressKey);
            /***********************/
            glutReshapeFunc(reshape);
     
      glutMainLoop();
    }

  2. #2
    Junior Member Regular Contributor
    Join Date
    Aug 2009
    Location
    Poland
    Posts
    109
    Hi,

    You enabled lighting in Init function, but I don't see any calls to glLight* in Your code
    You must setup at least one light to see anything. (Or disable lighting and go with plain unshaded colors)

  3. #3
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    1
    hi i am test code but there are no result but black screen addressed the room

Posting Permissions

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