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:

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… :frowning:

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.

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! :smiley:

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

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

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);

Ok, i’ll try, thanks!

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);

}

Thanks man!