Results 1 to 8 of 8

Thread: glTexImage2D causes problem to opengl color

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2006
    Posts
    10

    glTexImage2D causes problem to opengl color

    Hi,
    in my project i load a bitmap image and then i put it into a texture using glTexImage2D. After i do this, when i draw something e.x a circle, i use black color it is black, if i try any other color the results are not what they should be. For example if i draw white the output color is dark red (that depends on the colors of the image). This seems unreasonable but maybe you know something i dont.

    when the image has only black and white colors i have no problem. The problem occures when i load a coloured image.

    The code i use to load the image is not mine, i found it ready but i dont think its the problem cause i tried other codes with the same result.

    with this code i make it a texture
    ImageLoad("bitmap.bmp", in_image);

    glGenTextures(1, &texture[2]);

    glBindTexture(GL_TEXTURE_2D, texture[2]);

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);

    glTexImage2D(GL_TEXTURE_2D, 0, 4, in_image->sizeX, in_image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, in_image->data);

    free(in_image->data);
    free(in_image);

    So if i try to draw a white rectangle like this
    glBegin(GL_QUADS);
    glColor3f(1.0f,1.0f,1.0f);
    glVertex3f(0.0f,size_winy,0.0f);
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(size_winx,0.0f,0.0f);
    glVertex3f(size_winx,size_winy,0.0f);
    glEnd();

    some other color is drawn(depending on the image).

    If you can help me understand why is that and fix it, i'll be very gratefull.
    Thanx

  2. #2
    Guest

    Re: glTexImage2D causes problem to opengl color

    Hi,

    Try using GL_BGR(A)_EXT as your source format for glTexImage2D.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2006
    Posts
    10

    Re: glTexImage2D causes problem to opengl color

    Using this format caused the texture to invert colors. Now the if the image is red it becomes blue. Anyway this didnt solve the problem since now when i draw white it comes out as dark blue

  4. #4
    Guest

    Re: glTexImage2D causes problem to opengl color

    I see. Well, just so you know, bmp images are stored in BGR(A) format, so GL_RGB won't work as an source format for glTexImae2D, unless you byte-swap the data before uploading. This may not be your only problem, but it's probably among them, unless there's more going on behind the scenes.

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2006
    Posts
    10

    Re: glTexImage2D causes problem to opengl color

    It seems that i just had to add
    glBindTexture(GL_TEXTURE_2D,0);
    before drawing anything because it binds the texture and draws it with the polygons. I'm not sure why is that since i didnt bind it anywhere but that did the trick
    Thanks anyway

  6. #6
    Guest

    Re: glTexImage2D causes problem to opengl color

    Always glad to help a citizen.

  7. #7
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: glTexImage2D causes problem to opengl color

    glDisable(Gl_TEXTURE2D)

  8. #8
    Senior Member Regular Contributor
    Join Date
    Apr 2000
    Location
    Redlands, CA, USA
    Posts
    233

    Re: glTexImage2D causes problem to opengl color

    Originally posted by blueepl:
    It seems that i just had to add
    glBindTexture(GL_TEXTURE_2D,0);
    before drawing anything because it binds the texture and draws it with the polygons. I'm not sure why is that since i didnt bind it anywhere but that did the trick
    Thanks anyway
    What about this line of your code?

    glBindTexture(GL_TEXTURE_2D, texture[2]);

    To create the texture you have to bind it...

Similar Threads

  1. about glTexImage2D problem
    By jebe7282 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-12-2013, 02:45 AM
  2. problem about the glTexImage2D
    By kamimail in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-11-2009, 11:54 PM
  3. problem with glTexImage2D ?
    By HanWu in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-15-2003, 05:59 PM
  4. problem with glTexImage2D()
    By dilectio in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 11-21-2002, 08:32 PM
  5. Problem with glTexImage2D
    By GregR in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-12-2000, 12:13 AM

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