Results 1 to 2 of 2

Thread: texture mapping using multibitmaps

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2003
    Location
    Pakistan
    Posts
    23

    texture mapping using multibitmaps

    hello friends
    i am presently workng in opengl application where i am drawing some shapes like triangle etc on a window then using keyboard inerface i am switching to texture mapping that is loading one texture then using another key say "B" i am texture mapping another bitmap. hte problem i am encountring is that when i load my first bitmap using mipmap tchnique and then goes back to my original drawing where i have drawn trianges etc. its ok but when i load 2nd texture to display it on hte screen and goes back to main drwing it makes the draing dull that is it becoes black . i have tried to figure the problem but of no vain. can u help me out
    here is small code

    opening file .............here


    memset(TextureImage,0,sizeof(void *)*2);


    then i am loading 2 textures 1.bmp and 2,bmp .

    // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
    if ((TextureImage[0]=LoadBMP("1.bmp")) &&
    (TextureImage[1]=LoadBMP("2.bmp")))
    {
    Status=TRUE;

    glGenTextures(2, &texture[0]);

    for (int loop = 0; loop < 2; loop++)
    {
    // Create MipMapped Texture
    glBindTexture(GL_TEXTURE_2D, texture[loop]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);
    }
    }


    for (int loop = 0; loop < 2; loop++)
    {
    if (TextureImage[loop]) // If Texture Exists
    {
    if (TextureImage[loop]->data) // If Texture Image Exists
    {
    free(TextureImage[loop]->data); // Free The Texture Image Memory
    }

    free(TextureImage[loop]); // Free The Image Structure
    }
    }


    in drawing function i am loading texture 1 using following code

    GLvoid func1(GLvoid)
    {
    glTranslatef(0.0f,0.0f,-5.0f);
    glColorMaterial(GL_FRONT,GL_AMBIENT);
    glBindTexture(GL_TEXTURE_2D, texture[0]); // Select A Texture Based
    glBegin(GL_QUADS);
    glColor3f(1.0f,1.0f,1.0f);
    glNormal3f( 0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.5f, -1.5f, 1.0f); // Point 1 (Front)
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.5f, -1.5f, 1.0f); // Point 2 (Front)
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.5f, 1.5f, 1.0f); // Point 3 (Front)
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.5f, 1.5f, 1.0f); // Point 4 (Front)
    glEnd();
    }


    similar in another function i am loading second texture

    GLvoid func2(GLvoid)
    {
    glTranslatef(0.0f,0.0f,-5.0f);
    glColorMaterial(GL_FRONT,GL_AMBIENT);
    glBindTexture(GL_TEXTURE_2D, texture[1]); // Select A Texture Based
    glBegin(GL_QUADS);
    glColor3f(1.0f,1.0f,1.0f);
    glNormal3f( 0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.5f, -1.5f, 1.0f); // Point 1 (Front)
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.5f, -1.5f, 1.0f); // Point 2 (Front)
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.5f, 1.5f, 1.0f); // Point 3 (Front)
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.5f, 1.5f, 1.0f); // Point 4 (Front)
    glEnd();
    }


    then based upon keyboard events says key input "m" and "s" i switching over to function 1 and 2 respectively
    ofcourse main drawing is cleared.
    but when i load bitmap 1 and switch back to main drawing its ok the main drawing is same as it has to be bur when
    i load bitmap 2.bmp using keyboard input "s" it is loaded but when i goes back to
    main drawing the drawing becomes dull that is blackend somewhat. i have tried to load only bitmap 2.bmp but it is
    giving me the problem but bitmap 1.bmp is not giving me such problem. using both together makes my main drawing dull
    but when i load bitmap 1.bmp and switch back it becomes ok . i think its the problem with bitmap
    i am sending bitmaps to u please help me out.

  2. #2
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: texture mapping using multibitmaps

    OpenGL will continue to texture with the last texture coordinate used until you issue a glDisable for GL_TEXTURE_2D.

    I suspect all subsequent geometry just happens to be textured with the texel color at glTexCoord2f(0.0f, 1.0f), because that's the last coordinate you issued. It shows with one and not the other because one texture is white at that location and the other isn't.

    For many reasons it is a good idea to disable texturing when you are done with using it.

Similar Threads

  1. Texture mapping ::: 3D Face Mapping
    By 3render3 in forum OpenGL: General
    Replies: 2
    Last Post: 03-24-2013, 06:49 PM
  2. projective texture mapping and shadow mapping
    By phoenix_gl in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 10-08-2012, 08:00 PM
  3. Replies: 0
    Last Post: 01-09-2005, 06:01 PM
  4. Replies: 1
    Last Post: 01-09-2005, 05:50 PM
  5. Texture Mapping / Environmental Mapping.
    By imported_Andrew in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-09-2000, 01:20 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