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: Texture background and object

Hybrid View

  1. #1
    Newbie Newbie
    Join Date
    Dec 2012
    Posts
    2

    Texture background and object

    Hi..I'm new here..

    I have problem with my code.. i want to render a background(texture) and an object..when i put a color to the object..the background also changed the same color.. below are my code:

    void PlaceBackground()
    {
    glPushMatrix();
    glTranslatef(0.0f,0.0f,-6.0f);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-8.4f, -6.3f, 1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 8.4f, -6.3f, 1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 8.4f, 6.3f, 1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-8.4f, 6.3f, 1.0f);
    glEnd();
    glPopMatrix();

    }
    //End Draw background

    //Draw Object
    void PlaceSceneElements()
    {
    glTranslatef(x, y, z);

    // rotate the scene for viewing
    glRotatef(xpoz,1,0,0);
    glRotatef(ypoz,0,0,1);

    glPushMatrix();
    glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBronzeDiff);
    glMaterialfv(GL_FRONT, GL_SPECULAR, colorBronzeSpec);
    glMaterialf(GL_FRONT, GL_SHININESS, 50.0);
    glColor4fv(colorBronzeDiff);
    glBindTexture(GL_TEXTURE_2D, 0);
    glutSolidTeapot(500);
    glPopMatrix();

    }
    //End Draw Object

    // main rendering function
    void drawBackground()
    {
    //Render background
    switch(picture)
    {
    case 0:
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    PlaceBackground();
    break;
    case 1:
    glBindTexture(GL_TEXTURE_2D, texture[1]);
    PlaceBackground();
    break;
    };

    }

    int InitGL(GLvoid) // Create Some Everyday Functions
    {
    glShadeModel(GL_SMOOTH); // Enable Smooth Shading
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // White Background
    glClearDepth(1.0f); // Depth Buffer Setup
    glEnable(GL_DEPTH_TEST); // Enables Depth Testing
    glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
    glEnable(GL_TEXTURE_2D); // Enable Texture Mapping

    return TRUE;
    }

    int DrawGLScene(GLvoid)
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
    glLoadIdentity(); // Reset The View

    glTranslatef(0.0f,0.0f,-10.0f);

    drawBackground();

    glClear(GL_DEPTH_BUFFER_BIT);

    PlaceSceneElements();

    return TRUE;
    }

    anyone please help me..thanks..

  2. #2
    Junior Member Regular Contributor
    Join Date
    Dec 2007
    Posts
    249
    change to

    void PlaceBackground()
    {
    glColor3f(1,1,1);
    glPushMatrix();
    glTranslatef(0.0f,0.0f,-6.0f);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-8.4f, -6.3f, 1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 8.4f, -6.3f, 1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 8.4f, 6.3f, 1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-8.4f, 6.3f, 1.0f);
    glEnd();
    glPopMatrix();

    }
    this should work .

  3. #3
    Newbie Newbie
    Join Date
    Dec 2012
    Posts
    2
    thanks so much.. it's work.. and i need to disable lighting to background..

Posting Permissions

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