Skip to content

Commit

Permalink
Merge branch 'release-1.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaakman committed Aug 22, 2015
2 parents 176bbc1 + 4b5e580 commit a509156
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 164 deletions.
Binary file modified bin/test3d.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion notes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Game templates version 1.3.0
Game templates version 1.3.1

[test3d]

Expand Down
7 changes: 5 additions & 2 deletions src/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ GLuint CreateShader(const std::string& source, int type)

return shader;
}

GLuint CreateShaderProgram(const std::string& sourceVertex, const std::string& sourceFragment)
GLuint CreateShaderProgram (const char *sourceVertex, const char *sourceFragment)
{
return CreateShaderProgram (std::string (sourceVertex), std::string (sourceFragment));
}
GLuint CreateShaderProgram (const std::string& sourceVertex, const std::string& sourceFragment)
{
GLint result = GL_FALSE;
int logLength;
Expand Down
1 change: 1 addition & 0 deletions src/shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
* :returns: OpenGL handle to the shader program, or 0 on error
*/
GLuint CreateShaderProgram (const std::string& sourceVertex, const std::string& sourceFragment);
GLuint CreateShaderProgram (const char *sourceVertex, const char *sourceFragment);

#endif // SHADER_H
81 changes: 50 additions & 31 deletions src/test3d/toon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,56 @@ ToonScene::~ToonScene ()
glDeleteTextures (1, &texBG.tex);
glDeleteProgram (shaderProgram);
}

const char

// Toon vector shader:
toon_vsh [] = R"shader(
varying vec3 N;
varying vec3 v;
varying vec4 color;
void main()
{
v = vec3 (gl_ModelViewMatrix * gl_Vertex);
N = normalize (gl_NormalMatrix * gl_Normal);
color = gl_Color;
gl_Position = ftransform();
}
)shader",

// Toon fragment shader:
toon_fsh [] = R"shader(
uniform float cutOff = 0.8;
varying vec3 N;
varying vec3 v;
varying vec4 color;
void main()
{
vec3 L = normalize(gl_LightSource[0].position.xyz - v);
float lum = clamp (dot(normalize (N), L) + 0.5, 0.0, 1.0);
if (lum < cutOff)
lum = cutOff;
else
lum = 1.0;
gl_FragColor = color * lum;
}
)shader";
bool ToonScene::Init ()
{
std::string resPath = std::string(SDL_GetBasePath()) + "test3d.zip",
sourceV = "", sourceF = "";;
std::string resPath = std::string(SDL_GetBasePath()) + "test3d.zip";

SDL_RWops *f;
bool success;
Expand Down Expand Up @@ -85,38 +131,11 @@ bool ToonScene::Init ()
return false;
}

// Load the vertex shader source:
f = SDL_RWFromZipArchive (resPath.c_str(), "shaders/toon.vsh");
if (!f)
return false;

success = ReadAll (f, sourceV);
f->close(f);

if (!success)
{
SetError ("error parsing toon.vsh: %s", GetError ());
return false;
}

// Load the fragment shader source:
f = SDL_RWFromZipArchive (resPath.c_str(), "shaders/toon.fsh");
if (!f)
return false;
success = ReadAll (f, sourceF);
f->close(f);

if (!success)
{
SetError ("error parsing toon.fsh: %s", GetError ());
return false;
}

// Create shader from sources:
shaderProgram = CreateShaderProgram (sourceV, sourceF);
shaderProgram = CreateShaderProgram (toon_vsh, toon_fsh);
if (!shaderProgram)
{
SetError ("error creating shader program from toon.vsh and toon.fsh: %s", GetError ());
SetError ("error creating toon shader program: %s", GetError ());
return false;
}

Expand Down
Loading

0 comments on commit a509156

Please sign in to comment.