Open GL won't recognise "FILE" as syntax in Open GL

My Open GL program is trying to read and display a file.
I largely copied this and have been trying to adapt it, there generally no syntax errors. This is the only error I noticed, I've been comparing the 2 files for over an hour.

I declared a Pointer called FILE *fp but its not recognised, isn't FILE a command in Open GL.

Further more this means I can't open or close a file.

Code (look at the FILE section below)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//#include "stdafx.h"
#include<glut.h>
#include<windows.h>
#include<math.h>//<cmath>replace with cmath if it doesn't work

#include <stdlib.h>

//Global variables
BITMAPINFO *info;       // Bitmap information
GLubyte    *pixels;     // Actual pixel data 


GLubyte * ReadBitmap(const char *filename,BITMAPINFO **info);
float xpos, ypos;
void Draw()//SEED IN: glutDisplayFunc
{	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0,1.0,0.0);
	glBegin(GL_LINES);//XXXSHAPE);
	glVertex3f(0.25, 0.25, 0.0);
	glVertex3f(0.75, 0.75, 0.0);
	glEnd();
	glFlush();
	glutSwapBuffers();//IMPORTANT for double buffering
}

void Display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glRasterPos2f(100,ypos);
	// Draw the loaded pixels
	glDrawPixels(info->bmiHeader.biWidth,
		         info->bmiHeader.biHeight,
				 GL_BGR_EXT, GL_UNSIGNED_BYTE, pixels);

	glFlush();
	glutSwapBuffers();

	//120 is max Y value in our logical coordinate system
	ypos = ypos + 0.1;
	if (ypos >= 120.)
		ypos = 0;
	//Force a redisplay
	glutPostRedisplay();
}

/********
initilise display
*********/
void Initialize()
{
	glClearColor(0.0,0.0,0.0,0.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
	xpos = 60;
	ypos = 0;
}


/********
main program
*********/
int main(int argc, char* argv[])
{
    start:
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize (320, 240);
	glutInitWindowPosition(200, 200);
	glutCreateWindow("Display My Images");
	Initialize();
	glutDisplayFunc(Display);
	//read in the pixel data
	if (argc > 1)
		pixels = ReadBitmap(argv[1],&info);
	else 
		pixels = ReadBitmap("smiley.bmp", &info);

	glutMainLoop();
	goto start;
	return 0;
}

/********
Read Bitmap information. Return the final BITMAP PIXEL values 
*********/
GLubyte * ReadBitmap(const char * filename,BITMAPINFO **info)
{
	FILE          *fp;                 /* Open file pointer */
	GLubyte       *pixels;             /* Bitmap pixel bits */
	int           imgsize;             /* Size of bitmap image */
	int           infosize;            /* Size of header information */
	BITMAPFILEHEADER header;           /* File header */

	//try opening the file; use "rb" mode to read a binary file.
	if ((fp = fopen(filename, "rb")) == NULL)
		return (NULL);

	//Read the file header
	if (fread(&header, sizeof(BITMAPFILEHEADER), 1, fp) < 1)
	{
	//Couldn't read the file header
		fclose(fp);
		return (NULL);
	}

	if(header.bfType != 'MB')   /* Check for BM reversed... */
	{
		//Not a bitmap file
		fclose(fp);
		return (NULL);
	}

	infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER);
	if ((*info = (BITMAPINFO *)malloc(infosize)) == NULL)
	{
		fclose(fp);
		return (NULL);
	}

	if (fread(*info, 1, infosize, fp)< infosize)
	{
		free(*info);
		fclose(fp);
		return (NULL);
	}

	/*Now that we have all the header info read in,
	 * allocate memory for the bitmap and read it in...
	 */
	imgsize = (*info)->bmiHeader.biSizeImage;
	//sometimes imagesize is not set in files
	if (imgsize == 0)
		imgsize = ((*info)->bmiHeader.biWidth *
		           (*info)->bmiHeader.biBitCount + 7) / 8 * 
				   abs ((*info)->bmiHeader.biHeight);

	if ((pixels = (unsigned char *)malloc(imgsize)) == NULL)
	{
		free(*info);
		fclose(fp);
		return (NULL);
	}

	fclose(fp);
	return (pixels);
}
FILE is part of stdio. You're not including <cstdio>
Topic archived. No new replies allowed.