PDA

View Full Version : How do I use more than 256*256 pixel for mapping texture?



rhizome
11-25-2002, 08:48 PM
please help me
Thanks a lot :-)

vijaykiran
11-25-2002, 09:36 PM
Try using this pseudo code:

// define texture parameters
#define TEXTUREWRAP 1
#define TEXWIDTH 1024
#define TEXHEIGHT 1024
#define TEXSIZE TEXWIDTH*TEXHEIGHT*3 //3 is used for RGB

//declaring variables for textures
GLuint texname;
char Texture[TEXSIZE];

//function prototypes:
void LoadTexture(void);
void drawtexture(void);

//display function syntax:
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawtexture();
glFlush();
glutSwapBuffers();
}

void LoadTexture(void)
{
FILE *in;
printf("loading texture...\n");
in=fopen("blaw-blaw.raw", "rb");
if(in)
{
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &texname);
glBindTexture(GL_TEXTURE_2D, texname);
fread(Texture, TEXSIZE,1,in);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXWIDTH, TEXHEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, Texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
}
else
printf(" error generating texture\n");
}

void drawtexture(void)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texname);
glBegin(GL_QUADS);

glTexCoord2f(0, 0);
glVertex2f(0, Wy);

glTexCoord2f(TEXTUREWRAP, 0);
glVertex2f(Wx, Wy);

glTexCoord2f(TEXTUREWRAP, TEXTUREWRAP);
glVertex2f(Wx, 0);

glTexCoord2f(0, TEXTUREWRAP);
glVertex2f(0, 0);

glEnd();
glFlush();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
glutInitWindowPosition(400, 50);
glutCreateWindow("yada yada yada");

init();
LoadTexture();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(key_pos);
//glutFullScreen();
glutMainLoop();
return 0;
}

i hope this should help you!!

cheers,
vijay.

vijaykiran
11-25-2002, 09:42 PM
change the value of 256 to a higher or lower number depending upon the image resolution... make sure the size of texture is a multiple of (2 raise to the power n) i.e., the texture should be of size - 64 x 64 or 128 x 128, 256 x 256 or 512 x 512 or 1024 x 1024 and so on...
the size of the texture should be used in the code...

i think you got ur question answered...

enjoy,
vijay.