22 GLuint Vertexhandle = glCreateShader(GL_VERTEX_SHADER);
23 GLuint Fragmenthandle = glCreateShader(GL_FRAGMENT_SHADER);
24 GLuint Geometryhandle = glCreateShader(GL_GEOMETRY_SHADER);
28 string VertexShaderCode;
29 ifstream VertexShaderStream(vertex_path, ios::in);
30 if(VertexShaderStream.is_open())
33 while(getline(VertexShaderStream, Line))
34 VertexShaderCode +=
"\n" + Line;
35 VertexShaderStream.close();
39 string FragmentShaderCode;
40 ifstream FragmentShaderStream(fragment_path, ios::in);
41 if(FragmentShaderStream.is_open())
44 while(getline(FragmentShaderStream, Line))
45 FragmentShaderCode +=
"\n" + Line;
46 FragmentShaderStream.close();
50 string GeometryShaderCode;
51 ifstream GeometryShaderStream(geo_path, ios::in);
52 if(GeometryShaderStream.is_open())
55 while(getline(GeometryShaderStream, Line))
56 GeometryShaderCode +=
"\n" + Line;
57 GeometryShaderStream.close();
63 char const * VertexPtr = VertexShaderCode.c_str();
64 glShaderSource(Vertexhandle, 1, &VertexPtr , NULL);
65 glCompileShader(Vertexhandle);
70 glGetShaderiv(Vertexhandle, GL_COMPILE_STATUS, &succeded);
71 if (succeded == GL_FALSE)
75 glGetShaderiv(Vertexhandle, GL_INFO_LOG_LENGTH, &logSize);
76 GLchar* message =
new char[logSize];
77 glGetShaderInfoLog(Vertexhandle, logSize, NULL, message);
84 char const * FragmentPtr = FragmentShaderCode.c_str();
85 glShaderSource(Fragmenthandle, 1, &FragmentPtr , NULL);
86 glCompileShader(Fragmenthandle);
90 glGetShaderiv(Fragmenthandle, GL_COMPILE_STATUS, &succeded);
91 if (succeded == GL_FALSE)
95 glGetShaderiv(Fragmenthandle, GL_INFO_LOG_LENGTH, &logSize);
96 GLchar* message =
new char[logSize];
97 glGetShaderInfoLog(Fragmenthandle, logSize, NULL, message);
104 char const * GeometryPtr = GeometryShaderCode.c_str();
105 glShaderSource(Geometryhandle, 1, &GeometryPtr , NULL);
106 glCompileShader(Geometryhandle);
110 glGetShaderiv(Geometryhandle, GL_COMPILE_STATUS, &succeded);
111 if (succeded == GL_FALSE)
115 glGetShaderiv(Geometryhandle, GL_INFO_LOG_LENGTH, &logSize);
116 GLchar* message =
new char[logSize];
117 glGetShaderInfoLog(Geometryhandle, logSize, NULL, message);
124 GLuint programHandle = glCreateProgram();
125 glAttachShader(programHandle, Vertexhandle);
126 glAttachShader(programHandle, Fragmenthandle);
129 glBindFragDataLocation(programHandle, 0,
"fragColor");
130 glLinkProgram(programHandle);
135 glGetProgramiv(programHandle, GL_LINK_STATUS, &succeded);
140 glGetShaderiv(programHandle, GL_INFO_LOG_LENGTH, &logSize);
141 GLchar* message =
new char[logSize];
142 glGetShaderInfoLog(programHandle, logSize, NULL, message);
147 glDeleteShader(Vertexhandle);
148 glDeleteShader(Fragmenthandle);
149 glDeleteShader(Geometryhandle);
151 return programHandle;
GLuint LoadShaders(const char *vertex_path, const char *fragment_path, const char *geo_path)
Diese Methode laedt die Shader. Parameter sind die jeweiligen Dateipfade.