PDA

View Full Version : open GL texure load problem



punky
10-12-2009, 09:10 PM
how i should load the Data of the bmp
is the Data of the bmp for texture the Raw Pixel Datas without the Header or with the header?

glTexImage2D(GL_TEXTURE_2D, 0, 3, 100, 100, 0,
GL_RGB, GL_UNSIGNED_BYTE,&tmpData);

punky
10-12-2009, 09:13 PM
i load the bmp very simple



GLuint TextureArray[1];
char tmpData[30000];
typedef struct tagBMPHeader{
WORD Signature; // 4D42 hex
DWORD sizeImageData; //
WORD res1; //reserverd must be 0
WORD res2; // same
DWORD offsetDATA; // offset of image data;
DWORD BitmapIfoHeaderSize; //
DWORD width;
DWORD height;
WORD planes;
WORD depth; // bpb bits per pixel deth 8/16/24/32
DWORD compression; //(0=none, 1=RLE-8, 2=RLE-4)
DWORD sizeRawData; //size of image data padding
DWORD hrBitsPerMeter;
DWORD vrBitsPerMeter;
DWORD numColors;
DWORD numImportantColors;
}BMPHeader;
BMPHeader bmfh;




bool loadBMP(char *file) {
FILE *filePtr; //file stream for reading
char *tempData; //temp storage for image data
int numColours; //total available colours

filePtr=fopen(file,"rb");

//if the file does not exist return in error
if(filePtr==NULL) {
printf("NOT FOUND");
getc(stdin);
fclose(filePtr);
return false;
}
char buff[56];

memset(&bmfh,0,sizeof(bmfh));
fread(&buff,sizeof(bmfh),1,filePtr);
bmfh.Signature=*(PWORD)(buff);
bmfh.offsetDATA=*(PDWORD)(buff+0xA);
bmfh.sizeImageData=*(PDWORD)(buff+0x2);
bmfh.width=*(PDWORD)(buff+0x12);
bmfh.height=*(PDWORD)(buff+0x16);
bmfh.sizeRawData=*(PDWORD)(buff+0x22);

fseek(filePtr,(bmfh.offsetDATA),SEEK_SET);
fread(&tmpData,bmfh.sizeRawData,1,filePtr);
//memcpy(&bData.DATA,(tmpData+bmfh.offsetDATA),(INT) bmfh.sizeRawData),
fclose(filePtr);

glGenTextures(1, &TextureArray[1]);

glBindTexture(GL_TEXTURE_2D, TextureArray[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR); // Linear Filtering

glTexImage2D(GL_TEXTURE_2D, 0, 3, 100, 100, 0,
GL_RGB, GL_UNSIGNED_BYTE,&tmpData);





but it does not load the texutre anyway? btw it does not render it on a cube for example?


glBindTexture(GL_TEXTURE_2D, TextureArray[1]); // Select our texture
glBegin(GL_QUADS);
// Front face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-10.0f, -10.0f, 10.0f); // Bottom left of the texture and quad
glTexCoord2f(10.0f, 0.0f); glVertex3f( 10.0f, -10.0f, 10.0f); // Bottom right of the texture and quad
glTexCoord2f(10.0f, 10.0f); glVertex3f( 10.0f, 10.0f, 10.0f); // Top right of the texture and quad
glTexCoord2f(0.0f, 10.0f); glVertex3f(-10.0f, 10.0f, 10.0f); // Top left of the texture and quad
// Back face
glTexCoord2f(10.0f, 0.0f); glVertex3f(-10.0f, -10.0f, -10.0f); // Bottom right of the texture and quad
glTexCoord2f(10.0f, 10.0f); glVertex3f(-10.0f, 10.0f, -10.0f); // Top right of the texture and quad
glTexCoord2f(0.0f, 10.0f); glVertex3f( 10.0f, 10.0f, -10.0f); // Top left of the texture and quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 10.0f, -10.0f, -10.0f); // Bottom left of the texture and quad
// Top face
glTexCoord2f(0.0f, 10.0f); glVertex3f(-10.0f, 10.0f, -10.0f); // Top left of the texture and quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-10.0f, 10.0f, 10.0f); // Bottom left of the texture and quad
glTexCoord2f(10.0f, 0.0f); glVertex3f( 10.0f, 10.0f, 10.0f); // Bottom right of the texture and quad
glTexCoord2f(10.0f, 10.0f); glVertex3f( 10.0f, 10.0f, -10.0f); // Top right of the texture and quad
// Bottom face
glTexCoord2f(10.0f, 10.0f); glVertex3f(-10.0f, -10.0f, -10.0f); // Top right of the texture and quad
glTexCoord2f(0.0f, 10.0f); glVertex3f( 10.0f, -10.0f, -10.0f); // Top left of the texture and quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 10.0f, -10.0f, 10.0f); // Bottom left of the texture and quad
glTexCoord2f(10.0f, 0.0f); glVertex3f(-10.0f, -10.0f, 10.0f); // Bottom right of the texture and quad
// Right face
glTexCoord2f(10.0f, 0.0f); glVertex3f( 10.0f, -10.0f, -10.0f); // Bottom right of the texture and quad
glTexCoord2f(10.0f, 10.0f); glVertex3f( 10.0f, 10.0f, -10.0f); // Top right of the texture and quad
glTexCoord2f(0.0f, 10.0f); glVertex3f( 10.0f, 10.0f, 10.0f); // Top left of the texture and quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 10.0f, -10.0f, 10.0f); // Bottom left of the texture and quad
// Left face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-10.0f, -10.0f, -10.0f); // Bottom left of the texture and quad
glTexCoord2f(10.0f, 0.0f); glVertex3f(-10.0f, -10.0f, 10.0f); // Bottom right of the texture and quad
glTexCoord2f(10.0f, 10.0f); glVertex3f(-10.0f, 10.0f, 10.0f); // Top right of the texture and quad
glTexCoord2f(0.0f, 10.0f); glVertex3f(-10.0f, 10.0f, -10.0f); // Top left of the texture and quad
glEnd();

todayman
10-12-2009, 09:40 PM
You do not send the header data to OpenGL in glTexImage2D; the essential information is passed as arguments to the function. There is information on exactly what these mean on the man page for the function.

Another thing: texture coordinates, regardless of the actual size of the image, go from 0 to 1. In your code, they go from 0 to 10. This should repeat the image 10 times across the face, which may or may not be what you want.

You need to enable texturing (glEnable(GL_TEXTURE_2D)). Not all your code is here, so I can't check to make sure that you did it. Make sure the texture environment is what you think it is.

punky
10-12-2009, 09:56 PM
thnx a lot for the information, the problem was the opengl32.dll it did't loaded my textures. after i got new drivers for my graphic card from nvidia it loads the texture now, i also got the new gl3.h file now its fine but i need to renew my code it was all only based on opengl 1.1 so some things changed, like lightning etc..