Results 1 to 8 of 8

Thread: Texture loading problem

  1. #1
    Member Contributor
    Join Date
    Jul 2008
    Posts
    52

    Texture loading problem

    Hi masters!

    I'm experiencing problems while loading a texture from a .raw file generated by Photoshop.

    the function to load is quite simple:

    Code :
    void CarregaTextura(const char* caminho, GLuint TextIndex)
    {
    	int largura = 256;
    	int altura = 256;
    	GLubyte *dados;
    	FILE *arquivo;
     
    	dados = (GLubyte*) malloc( largura * altura * 4 );
     
    	//abre e lê como bytes
    	arquivo = fopen(caminho, "rb");
     
    	//faz a leitura do arquivo para dentro da variável dados
    	fread(dados, altura * largura * 4, 1, arquivo);
    	fclose(arquivo);
     
            glBindTexture(GL_TEXTURE_2D, TextIndex);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256,256, 0, GL_RGBA, GL_UNSIGNED_BYTE,dados);
     
    }

    The problem is the texture is not loading correctly (see image below). I've tried paintbrush bitmaps but the problem is the same.


    click to enlarge

    The original texture is as below:



    Also, when I put the text coordinates inside a display list, nothing happens.

    Can someone help me again?

    Regards!

    ************************************************** ***********

    EDIT: I got it! the problem was GL_RGBA. It's GL_RGB in that case. But now another problem:



    How to remove this borders? Why this happens?

    and also, the problem with display list continues..


  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Texture loading problem

    You "border problem" is due to your texture. OpenGL don't access border elements in repeat wrap mode. I have checked your texture with gimp and with a big zoom I can see a 1 pixel grey border all around the texture. Remove it.

    For your display list problem, I don't know, put some code.

  3. #3
    Member Contributor
    Join Date
    Jul 2008
    Posts
    52

    Re: Texture loading problem

    I got it.

    It was my mistake, sorry and another big thank you!

    It's impressive how cool all you are, you really help us with all this stuff! This is really awesome, hope I can start helping people here soon!

  4. #4
    Member Contributor
    Join Date
    Jul 2008
    Posts
    52

    Re: Texture loading problem

    By the way, How can I set texture to glu or glut polygon functions?

    for ex., how to set texture coordinates to glutSolidCube?

  5. #5
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Texture loading problem

    You can look at automatic texture coordinates generation here

    I have never used it for generating texture coordinates on a cube, but something like this may work:

    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);

  6. #6
    Member Contributor
    Join Date
    Jul 2008
    Posts
    52

    Re: Texture loading problem

    Ok, i'll try, thanks!

  7. #7
    Junior Member Newbie
    Join Date
    Aug 2008
    Posts
    6

    Re: Texture loading problem

    hello my is chinase
    English not good
    the is code
    void LoadBitmapOpenGL(GLuint *uTexture, char *BmpName)
    {
    DWORD dwBmpWidth = 256;
    DWORD dwBmpHeight = 256;
    DWORD dwBmpSize = dwBmpWidth*dwBmpHeight*3;

    HANDLE hFile = CreateFile(BmpName,
    GENERIC_READ,
    FILE_SHARE_READ,
    NULL,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    NULL);
    if (hFile == INVALID_HANDLE_VALUE)
    {
    MessageBox(NULL,"Open Bitmap Error!",BmpName,MB_OK|MB_ICONERROR);
    return FALSE;
    }
    BITMAPFILEHEADER bf;
    BITMAPINFOHEADER bi;
    ZeroMemory(&bf, sizeof(bf));
    ZeroMemory(&bi, sizeof(bi));
    DWORD dwReadByte = 0;

    ReadFile(hFile, &bf, sizeof(bf), &dwReadByte, NULL);
    SetFilePointer(hFile, bf.bfOffBits, NULL, FILE_BEGIN);
    LPBYTE pBmp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwBmpSize);
    ReadFile(hFile, pBmp, dwBmpSize, &dwReadByte, NULL);

    unsigned int i = 0;
    BYTE tmp = 0;
    for (i = 0; i < dwBmpSize; i += 3)
    {
    tmp = *(pBmp+i);
    *(pBmp+i) = *(pBmp+i+2);
    *(pBmp+i) = tmp;
    }
    glBindTexture(GL_TEXTURE_2D,*uTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, dwBmpWidth, dwBmpHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, pBmp);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    HeapFree(GetProcessHeap(), HEAP_NO_SERIALIZE, pBmp);

    CloseHandle(hFile);
    }

  8. #8
    Member Contributor
    Join Date
    Jul 2008
    Posts
    52

    Re: Texture loading problem

    Thanks man!

Similar Threads

  1. Problem loading the texture
    By Sapphire in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-09-2015, 03:43 PM
  2. problem loading texture
    By saosin in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-09-2010, 12:17 PM
  3. I have a problem with loading TGA-texture
    By Liberty_2000 in forum OpenGL ES
    Replies: 1
    Last Post: 12-28-2004, 11:14 AM
  4. Texture loading problem.
    By Questions Burner in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-07-2001, 05:58 AM
  5. JPG TEXTURE LOADING PROBLEM =(
    By TPManiac2001 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-01-2001, 06:59 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