@@ -89,10 +89,10 @@ class EffectsImpl : public Effects {
8989 glShaderSource (vert, BITTY_COUNTOF (verVert), verVert, NULL );
9090 glShaderSource (frag, BITTY_COUNTOF (verFrag), verFrag, NULL );
9191 glCompileShader (vert);
92- if (!getError (vert, workspace ))
92+ if (!getError (workspace, vert, " Vertex shader: " ))
9393 return ;
9494 glCompileShader (frag);
95- if (!getError (frag, workspace ))
95+ if (!getError (workspace, frag, " Fragment shader: " ))
9696 return ;
9797 glAttachShader (program, vert);
9898 glAttachShader (program, frag);
@@ -151,7 +151,7 @@ class EffectsImpl : public Effects {
151151 valid = false ;
152152 }
153153
154- bool getError (GLuint obj, Workspace* workspace ) {
154+ bool getError (Workspace* workspace, GLuint obj, const char * prefix ) {
155155 int status = 0 ;
156156 glGetShaderiv (obj, GL_COMPILE_STATUS, &status);
157157
@@ -162,7 +162,8 @@ class EffectsImpl : public Effects {
162162 glGetShaderInfoLog (obj, BITTY_COUNTOF (msg), &len, msg);
163163 fprintf (stderr, " %s\n " , msg);
164164
165- std::string msg_ = " Effects:\n " ;
165+ std::string msg_ = prefix;
166+ msg_ += " \n " ;
166167 msg_ += msg;
167168 workspace->error (msg_.c_str ());
168169
@@ -262,10 +263,35 @@ class EffectsImpl : public Effects {
262263 file->readString (fx);
263264 file->close ();
264265
265- if (use (fx.c_str (), workspace ))
266+ if (use (workspace, fx.c_str ()))
266267 return true ;
267268 }
268269 }
270+ const GLchar* vertSrc =
271+ " #version 150\n "
272+ " uniform mat4 ProjMatrix;\n "
273+ " in vec2 Position;\n "
274+ " in vec2 UV;\n "
275+ " in vec4 Color;\n "
276+ " out vec2 Frag_UV;\n "
277+ " out vec4 Frag_Color;\n "
278+ " void main()\n "
279+ " {\n "
280+ " Frag_UV = UV;\n "
281+ " Frag_Color = Color;\n "
282+ " gl_Position = ProjMatrix * vec4(Position.xy, 0, 1);\n "
283+ " }\n " ;
284+ const GLchar* fragSrc =
285+ " #version 150\n "
286+ " uniform sampler2D Texture;\n "
287+ " in vec2 Frag_UV;\n "
288+ " in vec4 Frag_Color;\n "
289+ " out vec4 Out_Color;\n "
290+ " void main()\n "
291+ " {\n "
292+ " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n "
293+ " }\n " ;
294+ _material.open (vertSrc, fragSrc, workspace);
269295
270296 return true ;
271297 }
@@ -295,7 +321,7 @@ class EffectsImpl : public Effects {
295321 return true ;
296322 }
297323
298- virtual bool use (const char * config, class Workspace * workspace ) override {
324+ virtual bool use (class Workspace * workspace, const char * config ) override {
299325 Json::Ptr json (Json::create ());
300326 if (!json->fromString (config))
301327 return false ;
@@ -304,9 +330,9 @@ class EffectsImpl : public Effects {
304330 return false ;
305331
306332 std::string vert, frag;
307- if (!Jpath::get (doc, vert, " vert " ))
333+ if (!Jpath::get (doc, vert, " vs " ))
308334 return false ;
309- if (!Jpath::get (doc, frag, " frag " ))
335+ if (!Jpath::get (doc, frag, " fs " ))
310336 return false ;
311337
312338 File::Ptr file (File::create ());
@@ -478,7 +504,7 @@ class EffectsImpl : public Effects {
478504 return false ;
479505 }
480506
481- virtual bool use (const char *, class Workspace *) override {
507+ virtual bool use (class Workspace *, const char *) override {
482508 return false ;
483509 }
484510
0 commit comments