MCPcopy Create free account
hub / github.com/avaxman/Directional / createProgram

Function createProgram

external/eigen/unsupported/test/openglsupport.cpp:96–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96GLint createProgram(const char* vtx, const char* frg, bool print_errors = true)
97{
98 GLint prg_id = glCreateProgram();
99 GLint vtx_id = glCreateShader(GL_VERTEX_SHADER);
100 GLint frg_id = glCreateShader(GL_FRAGMENT_SHADER);
101 GLint ok;
102
103 glShaderSource(vtx_id, 1, &vtx, 0);
104 glCompileShader(vtx_id);
105 glGetShaderiv(vtx_id, GL_COMPILE_STATUS, &ok);
106 if(!ok)
107 {
108 if (print_errors)
109 {
110 std::cerr << "vtx compilation failed\n";
111 std::cerr << "Source:\n" << vtx << "\n";
112 printShaderInfoLog(vtx_id);
113 }
114 glDeleteShader(vtx_id);
115 return GL_ZERO;
116 }
117
118 glShaderSource(frg_id, 1, &frg, 0);
119 glCompileShader(frg_id);
120 glGetShaderiv(frg_id, GL_COMPILE_STATUS, &ok);
121 if(!ok)
122 {
123 if (print_errors)
124 {
125 std::cerr << "frg compilation failed.\n";
126 std::cerr << "Source:\n" << frg << "\n";
127 printShaderInfoLog(frg_id);
128 }
129 glDeleteShader(vtx_id);
130 glDeleteShader(frg_id);
131 return GL_ZERO;
132 }
133
134 glAttachShader(prg_id, vtx_id);
135 glAttachShader(prg_id, frg_id);
136 glLinkProgram(prg_id);
137
138 // Delete shaders once linked.
139 glDeleteShader(vtx_id);
140 glDeleteShader(frg_id);
141 glGetProgramiv(prg_id, GL_LINK_STATUS, &ok);
142 if(!ok)
143 {
144 if (print_errors)
145 {
146 std::cerr << "linking failed.\n";
147 printProgramInfoLog(prg_id);
148 }
149 glDeleteProgram(prg_id);
150 return GL_ZERO;
151 }
152
153 glUseProgram(prg_id);

Callers 1

openglsupport_test_loopFunction · 0.85

Calls 2

printShaderInfoLogFunction · 0.85
printProgramInfoLogFunction · 0.85

Tested by

no test coverage detected