Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Texture mapping problem

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2001
    Location
    Boston
    Posts
    5

    Texture mapping problem

    Hello,


    This may be a stupid question, or I could just be stupid, I do not know, but I am having a HELL of a time trying to figure out how to just texture map a polygon with just a normal, everyday, texture (no blending, no mipmap, etc).


    Here is my code for setting the texture...

    glGenTextures(1, &Texture);
    glBindTexture(GL_TEXTURE_2D, Texture);

    glTexImage2D(GL_TEXTURE_2D, 0, 3, Bitmap.GetWidth() - 1, Bitmap.GetHeight() - 1, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, Image);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);


    And here is my code for generating Image, which is of type GLubyte*...

    struct _pixBGRData{
    GLubyte B;
    GLubyte G;
    GLubyte R;
    GLubyte Reserved;
    };


    void glcBitmap::GetPixels(GLubyte Buffer[], int Type, int R, int G, int B){

    int BufferIndex = 0;
    int PixIndex = 0;

    if (Loaded){
    if (Type == 0){

    for (; PixIndex < (Info.biWidth *
    Info.biHeight); PixIndex++){

    Buffer[BufferIndex] = BGR[PixIndex].B;
    Buffer[BufferIndex + 1] = BGR[PixIndex].G;
    Buffer[BufferIndex + 2] = BGR[PixIndex].R;
    BufferIndex += 3;
    }
    }
    }
    }


    Also, I know the data is intact because I make a call to glDrawPixels and it draws properly.
    I just do NOT get it!! Is there a difference between the data passed in glDrawPixels and glTexImage2D, or am I forgetting a function call, messing up the order of calls?

    I have a demo on this that works (someone else wrote it), and as far as I can tell, the openGL calls we make are the same, but how we load in the bitmap is different.


    One last thing, in this very long problem. I know there is a built in bmp loader in the open gl library (though I didn't know to AFTER I created my bmp loaded), but I want to get this working with MY bmp loader. I want to know what I am really doing wrong!!

    Can anyone help?
    Thank you for your time,
    occamrzr

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Portsmouth, Hampshire, England
    Posts
    926

    Re: Texture mapping problem

    Just a quick check, I didn't see any
    glEnable(GL_TEXTURE_2D); 's in there anywhere. You must call this to turn on 2 dimensional texture mapping. Maybe you have it enabled somewhere else?

    Nutty

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Dec 2007
    Posts
    1,077

    Re: Texture mapping problem

    Look in that other thread running here.
    Additionally to what Nutty said, you don't check wether the texture is a power of 2 big in either direction.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Dec 2007
    Posts
    1,077

    Re: Texture mapping problem

    And if your compiler alignes the structure components, you might get an error as well. I would sort the image data in a big byte array.

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2001
    Location
    Boston
    Posts
    5

    Re: Texture mapping problem

    Hello,


    Sorry, I do enable GL_TEXTURE_2D in my setup function.
    The image I'm using is 128x128, which I believe is within the acceptable limits for oGL.
    I am also storing the image data into a Byte Array.


    Thank you,
    occamrzr

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2000
    Location
    Marlborough, MA, USA
    Posts
    21

    Re: Texture mapping problem

    Hmm, the glTexImage2D call looks right on a quick glance. Silly question but are you sure your texture coordinates are correct for your polygon? Maybe you could post a snippet where you setup the polygon? You might want to try setting the wrap modes to repeat just to see if you are getting anything and maybe set the texenv mode to replace just to be sure:

    glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    dave
    Dave Gosselin
    Software Engineer
    ATI Research, INC.

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2001
    Location
    Boston
    Posts
    5

    Re: Texture mapping problem

    Hello,


    I tried what was mentioned and it did not work.

    This is the code that I use to draw my polygon...

    glBegin(GL_QUADS);

    CalcNormal(Faces[x].A, Faces[x].B, Faces[x].C, Norm);
    glNormal3f(Norm.x, Norm.y, Norm.z);
    glTexCoord2f(0.0, 0.0);
    glVertex3f(Faces[x].A.x, Faces[x].A.y, Faces[x].A.z);
    glTexCoord2f(1.0, 0.0);
    glVertex3f(Faces[x].B.x, Faces[x].B.y, Faces[x].B.z);
    glTexCoord2f(1.0, 1.0);
    glVertex3f(Faces[x].C.x, Faces[x].C.y, Faces[x].C.z);
    glTexCoord2f(0.0, 1.0);
    glVertex3f(Faces[x].D.x, Faces[x].D.y, Faces[x].D.z);

    glEnd();

  8. #8
    Member Contributor
    Join Date
    Apr 2000
    Location
    Staten Island New York
    Posts
    53

    Re: Texture mapping problem

    Where is the path to the texture?

  9. #9
    Junior Member Newbie
    Join Date
    Jan 2001
    Location
    Boston
    Posts
    5

    Re: Texture mapping problem

    I'm not sure I understand that question. If you mean the physical path of the .bmp file, it's in my main working program directory. The BMP loads fine, because it will display with one of the openGL functions. I just cannot get textures to work, for some reason.

    If you mean, where is the Image object within the program, it's a global object of type GLubyte *Image;

    It is inited later with...
    Image = new GLubyte[NumberOfPixels*3];

    Thank you,
    Occamrzr

  10. #10
    Member Contributor
    Join Date
    Dec 2000
    Location
    Kaifeng,He'nan,PRC
    Posts
    69

    Re: Texture mapping problem

    mail your project to me if you can,maybe i can solve it.

    my mailbox: suvcon_cn@sina.com
    ========================
    As an old Chinese saying:One Live a Short while Die a Long...
    If I am useful to this world,I am reasonable to myself.
    =========================

Page 1 of 2 12 LastLast

Similar Threads

  1. Problem with texture mapping
    By obastob in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 11-21-2010, 05:37 AM
  2. Replies: 1
    Last Post: 01-10-2005, 09:50 AM
  3. Replies: 0
    Last Post: 01-09-2005, 06:01 PM
  4. Replies: 0
    Last Post: 01-09-2005, 05:53 PM
  5. Replies: 1
    Last Post: 01-09-2005, 05:50 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