Results 1 to 6 of 6

Thread: texture as a background

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    3

    texture as a background

    I'm trying to display a texture as a background that I can then draw on top of. I'm not sure if I should do my rendering first then put texture the background or the other way around. Regardless, I can not get my texture background to appear. This is my code :
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(camfovy, aspectr, nearD, farD);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();


    glClearColor(0.1, 0.1, 0.1, 0.0);
    glClearDepth(1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    eye = p;
    lookat = dpoint;
    updir = u;
    gluLookAt(eye.x, eye.y, eye.z, lookat.x, lookat.y,lookat.z, updir.x, updir.y, updir.z);


    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, imageID[0]);

    // Draw a textured quad
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f( -aspectr, -1.0f,10.f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f( -aspectr, 1.0f,10.f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( aspectr, 1.0f,10.f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( aspectr, -1.0f,10.f);
    glEnd();

    glDisable(GL_TEXTURE_2D);

    Can anyone give me some insight to this?

    Thanks in advance.

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: texture as a background

    Draw the textured quad for the background first, using an orthographic projection and disable depth writes so that all your geometry is on top of the background.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    3

    Re: texture as a background

    Right, I can do that, but how do I keep the background in place once I call gluLookAt with a different eye, lookat and updir vectors?
    I'm trying to have the texture background regardless of the changes to the modelview.

    Actually I should have mentioned that if I change my eye location I can see the texture, but I don't see it as a background. Only a textured GL_QUAD off in the distance.


    thanks again.

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,675

    Re: texture as a background

    I'm trying to have the texture background regardless of the changes to the modelview.
    Then draw it before calling gluLookAt.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    3

    Re: texture as a background

    Okay, thanks guys - that worked. I appreciate the help. I'm still struggling to get the hang of the switching matrix modes. I think I'm starting to get the hang of it.

  6. #6
    Member Contributor
    Join Date
    Feb 2011
    Posts
    72

    Re: texture as a background

    hey i actually wanted to do something similar
    and was asking how to do this
    but today i tried something and its actually the same as rendering text
    so i just copied all my code from text and just replaced the draw font with the textured quad and it worked
    with this method you can have it below glulookat()
    basically anywhere you want but its best to draw things like this last before you swap which is what i heard


    void DrawImage(void) {

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0.0, glutGet(GLUT_WINDOW_WIDTH), 0.0, glutGet(GLUT_WINDOW_HEIGHT), -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();


    glLoadIdentity();
    glDisable(GL_LIGHTING);


    glColor3f(1,1,1);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, mark_textures[0].id);


    // Draw a textured quad
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
    glTexCoord2f(0, 1); glVertex3f(0, 100, 0);
    glTexCoord2f(1, 1); glVertex3f(100, 100, 0);
    glTexCoord2f(1, 0); glVertex3f(100, 0, 0);
    glEnd();


    glDisable(GL_TEXTURE_2D);
    glPopMatrix();


    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);

    }

Similar Threads

  1. How to Scroll Texture Just for Background
    By rafayameen in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-18-2016, 04:44 AM
  2. Texture background and object
    By eena312 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-18-2012, 07:17 PM
  3. Blending texture background bug.
    By pixelita in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-19-2011, 07:26 AM
  4. Setting texture as background...
    By guzba in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-19-2003, 05:44 PM
  5. Tiled-texture background
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-07-2000, 11:17 PM

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