-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextureLoader.cpp
More file actions
67 lines (56 loc) · 1.07 KB
/
Copy pathTextureLoader.cpp
File metadata and controls
67 lines (56 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
//#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
#include <iostream>
#endif
#include "TextureLoader.h"
GLubyte* LoadPPM(char* file, int* width, int* height, int* max)
{
GLubyte* img;
FILE *fd;
int n, m;
int k, nm;
char c;
int i;
char b[100];
float s;
int red, green, blue;
fd = fopen(file, "r");
fscanf(fd,"%[^\n] ",b);
if(b[0]!='P'|| b[1] != '3')
{
printf("%s is not a PPM file!\n",file);
exit(0);
}
printf("%s is a PPM file\n", file);
fscanf(fd, "%c",&c);
while(c == '#')
{
fscanf(fd, "%[^\n] ", b);
printf("%s\n",b);
fscanf(fd, "%c",&c);
}
ungetc(c,fd);
fscanf(fd, "%d %d %d", &n, &m, &k);
printf("%d rows %d columns max value= %d\n",n,m,k);
nm = n*m;
img = (GLubyte*)(malloc(3*sizeof(GLuint)*nm));
s=255.0/k;
for(i=0;i<nm;i++)
{
fscanf(fd,"%d %d %d",&red, &green, &blue );
img[3*nm-3*i-3]=red*s;
img[3*nm-3*i-2]=green*s;
img[3*nm-3*i-1]=blue*s;
}
*width = n;
*height = m;
*max = k;
return img;
}