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
|
('textFileRead' error below)
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <GL/glew.h>
#include <GL/glfw3.h>
#include <windows.h>
void setShaders() {
GLuint v, g, f;
char *vs,*gs, *fs;
// Create shader handlers
v = glCreateShader(GL_VERTEX_SHADER);
g = glCreateShader(GL_GEOMETRY_SHADER);
f = glCreateShader(GL_FRAGMENT_SHADER);
//*****HERE******
// Read source code from files
vs = textFileRead("shader.vtx");
gs = textFileRead("example.geom");
fs = textFileRead("shader.frg");
const char * vv = vs;
const char * gg = gs;
const char * ff = fs;
// Set shader source
glShaderSource(v, 1, &vv,NULL);
glShaderSource(g, 1, &gg,NULL);
glShaderSource(f, 1, &ff,NULL);
free(vs);free(gs);free(fs);
// Compile all shaders
glCompileShader(v);
glCompileShader(g);
glCompileShader(f);
// Create the program
GLuint p = glCreateProgram();
// Attach shaders to program
glAttachShader(p,v);
glAttachShader(p,g);
glAttachShader(p,f);
// Link and set program to use
glLinkProgram(p);
glUseProgram(p);
}
int main()
{
setShaders();
return 0;
}
|