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 representation causes problems

  1. #1
    Newbie Newbie
    Join Date
    Sep 2017
    Posts
    2

    Texture representation causes problems

    Hi,
    i cant find he misstake i did. Pls Help me.

    My Problems are:
    -Image is printet nearly white (95% with some blue/red/green pixels) but he images is nearly colored more hen 90%
    -Texture edges arn't parse on Images edges like:

    Correct edges parse:
    0---------1
    |_| _ |_|_|
    |_| _ |_|_|
    3---------2

    and it is shown as:
    0---------1
    | /_ /_ /_|
    |/ _ /_ / _|
    -------23--

    Image is png and has w:505 and h:378

    My Code:
    Image load:
    Code :
    cv::Mat *GroundImage;
     
    if(GroundImage)
        delete GroundImage;
    cv::Mat load=cv::Mat(cv::imread("download.png"));
    cv::flip(load,load,0);
    cvtColor(load, load, CV_BGR2RGB);
     
    GroundImage=new cv::Mat(load);

    Set Image in Opengl window (it is inside a winform)
    Code :
    void SetGround(cv::Mat *Image){
        GroundImage=Image;
     
        if(tex)
            delete tex;
        tex=new GLuint ();
        glEnable(GL_TEXTURE_2D);
        // Create Texture
        glGenTextures(1, tex);
        glBindTexture(GL_TEXTURE_2D, *tex); // 2d texture (x and y size)
     
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale linearly when image smalled than texture
          // 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image,
        // border 0 (normal), rgb color data, unsigned byte data, and finally the data itself.
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, GroundImage->cols, GroundImage->rows, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, GroundImage->data);            
        glBindTexture(GL_TEXTURE_2D, *tex); // choose the texture to use.
    }


    and draw
    Code :
    void drawGround()
    {
        if(GroundImage){
            glColor3f(1,1,1); // set global color to white, otherwise this color will be (somehow) added to the texture
     
            glBegin(GL_QUADS);
     
            float x = 10.0;
            float y = 10.0;
     
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-x, -y, 0.0f); 
            glTexCoord2f(0.0f, 1.0f);glVertex3f( x, -y, 0.0f);
            glTexCoord2f(1.0f, 1.0f);glVertex3f( x, y, 0.0f); 
            glTexCoord2f(1.0f, 0.0f);glVertex3f(-x, y, 0.0f); 
     
            glEnd();
        }
    }
    Last edited by Dark Photon; 09-05-2017 at 05:55 AM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,407
    Quote Originally Posted by GLABA2017 View Post
    Image is png and has w:505
    If the image data is RGB (3 bytes per pixel) and the image width isn't a multiple of 4, then you'll need to use:
    Code :
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    prior to the glTexImage2D() call.

    The default alignment is 4 bytes.

  3. #3
    Newbie Newbie
    Join Date
    Sep 2017
    Posts
    2

    Result

    Thanks, very nice.

Posting Permissions

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