-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfiletobuf.cpp
More file actions
43 lines (37 loc) · 1.16 KB
/
filetobuf.cpp
File metadata and controls
43 lines (37 loc) · 1.16 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
#include <cstdlib>
#include <iostream>
#include <gl/glew.h>
#include <gl/freeglut.h>
#include <gl/freeglut_ext.h>
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
char* filetobuf(const char* file)
{
FILE* fptr;
long length;
char* buf;
fopen_s(&fptr, file, "rb"); // Open file for reading
if (!fptr) // Return NULL on failure
return NULL;
fseek(fptr, 0, SEEK_END); // Seek to the end of the file
length = ftell(fptr); // Find out how many bytes into the file we are
buf = (char*)malloc(length + 1); // Allocate a buffer for the entire length of the file and a null terminator
fseek(fptr, 0, SEEK_SET); // Go back to the beginning of the file
fread(buf, length, 1, fptr); // Read the contents of the file in to the buffer
fclose(fptr); // Close the file
buf[length] = 0; // Null terminator
return buf; // Return the buffer
}
BOOL checkCompileErrors(GLuint uin, const char* errorword)
{
GLint result;
glGetShaderiv(uin, GL_COMPILE_STATUS, &result);
if (result != GL_TRUE)
{
GLsizei log_length = 0;
GLchar message[1024];
glGetShaderInfoLog(uin, 1024, &log_length, message);
return false;
}
return true;
}