PDA

View Full Version : Pixel-per-pixel texture



NDLeo5
03-20-2013, 07:03 AM
Hello,
I created program whitch take image(.tga format) and write each pixel to txt file with:

glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_UNSIGNED_ BYTE,(char*)pixel);
Next program read pixels by two. For example 4b4f05ff int txt RGBA. I convert numbers from hexdecimal to decimal and write it to the array.
R=4b
G=4f
B=f0
A=ff
There is code:


string line="";
short int decimal;
ifstream myfile ("example.txt");

unsigned long int color=0;
for(int a=0;a<h;a++){
for(int b=0;b<w;color+=4,b++)
for(int i=0;i<4;i++){

line+= myfile.get();
line+= myfile.get();
stringstream hexadecimal;
hexadecimal<<std::hex<<line;
hexadecimal>>decimal;

line="";

if(i==0) pole[color]=decimal;
else if(i==1) pole[color+1]=decimal;
else if(i==2) pole[color+2]=decimal;
else if(i==3) pole[color+3]=decimal;
}
}
Then use glTexImage2D but on screen is a mess of pixels. It do not show texture I saved as txt. Can u pls help where is problem?Maybe I do it wrong way.
There is creating the texture.


GLuint LTex;
glGenTextures(1,&LTex);
glBindTexture(GL_TEXTURE_2D,LTex);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,w,h,0,GL_RGBA ,GL_UNSIGNED_BYTE,pole);




Many thanks for answer, Andy.