-/* specifies image as texture */
-void initTexture(void)
-{
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glGenTextures(1, &gflux->texName);
- glBindTexture(GL_TEXTURE_2D, gflux->texName);
- 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);
-
- clear_gl_error();
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, gflux->imageWidth,
- gflux->imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, *(gflux->image));
- check_gl_error("texture");
-}
-
-#else /* HAVE_PPM FALSE */
-
-#define presult(A,B,C) (*(result+(A)*(gflux->imageWidth)*4+(B)*4+(C)))
-void loadTexture(void)
-{
- int i, j, levels, width, height;
- int red,green,blue;
- char s[4];
- int ppmType=0;
- FILE *file = stdin;
- GLubyte *result;
-
- fgets(s,4,file);
-
- if(!strncmp(s,"P6",2)) ppmType=6;
- if(!strncmp(s,"P5",2)) ppmType=5;
- if(!strncmp(s,"P3",2)) ppmType=3;
- if(!strncmp(s,"P2",2)) ppmType=2;
- if(!ppmType)exit(1);
-
- while((i=getc(file))=='#')
- {
- while(getc(file)!='\n');
- }
- ungetc(i,file);
-
- fscanf(file,"%d %d %d",&width,&height,&levels);
-
- result = malloc(sizeof(GLubyte)*4*width*height);
- gflux->imageWidth = width;
- gflux->imageHeight = height;
-
- switch(ppmType) {
- case 2 : /* ASCII grey */
- for(i=0;i<height;i++) {
- for(j=0;j<width;j++) {
- fscanf(file,"%d",&red);
- presult(j,i,0) = red;
- presult(j,i,1) = red;
- presult(j,i,2) = red;
- }
- }
- break;
- case 3 : /* ASCII rgb */
- for(i=0;i<height;i++) {
- for(j=0;j<width;j++) {
- fscanf(file,"%d %d %d",&red,&green,&blue);
- presult(j,i,0) = red;
- presult(j,i,1) = green;
- presult(j,i,2) = blue;
- }
- }
- break;
- case 5 : /* Binary grey */
- getc(file); /* seems nessessary */
- for(i=0;i<height;i++) {
- for(j=0;j<width;j++) {
- red = getc(file);
- presult(j,i,0) = red;
- presult(j,i,1) = red;
- presult(j,i,2) = red;
- }
- }
- break;
- case 6 : /* Binary rgb */
- getc(file); /* seems nessessary */
- for(i=0;i<height;i++) {
- for(j=0;j<width;j++) {
- red = getc(file);
- green = getc(file);
- blue = getc(file);
- presult(j,i,0) = red;
- presult(j,i,1) = green;
- presult(j,i,2) = blue;
- }
- }
- break;
- }
- gflux->image = result;
-}
-
-void createTexture(void)
-{
- int i,j,c;
- GLubyte *result;
-
- gflux->imageHeight = gflux->imageWidth = 8;
-
- result = malloc(sizeof(GLubyte)*4*gflux->imageHeight*gflux->imageWidth);
- for(i=0;i<gflux->imageHeight;i++) {
- for(j=0;j<gflux->imageWidth;j++) {
- c = (((i)%2 ^ (j)%2) ? 100 : 200 );
- presult(i,j,0) = (GLubyte) c;
- presult(i,j,1) = (GLubyte) c;
- presult(i,j,2) = (GLubyte) c;
- presult(i,j,3) = (GLubyte) 255;
- }
- }
- gflux->image = result;
-}