commit e0e6a47c4c7b6c0dd1ae9ab562ffb50dfc49f1be
parent 6f33a85ce2830e865906692f786c3cd97c42fb46
Author: Brian Swetland <swetland@frotz.net>
Date: Fri, 6 Sep 2013 22:37:46 -0700
wip
Diffstat:
4 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/hello/assets/simple.glsl b/hello/assets/simple.glsl
@@ -4,7 +4,7 @@
-- vertex
layout(location = A_POSITION) in vec4 aPosition;
-layout(location = A_NORMAL) in vec4 aNormal;
+layout(location = A_NORMAL) in vec3 aNormal;
layout(location = A_TEXCOORD) in vec2 aTexCoord;
in vec4 LOCATION;
@@ -19,7 +19,7 @@ void main() {
pos.xyz += LOCATION.xyz * vec3(127.0, 127.0, 127.0);
vPosition = (uMV * pos).xyz;
- vNormal = (uMV * vec4(aNormal.xyz,0.0)).xyz;
+ vNormal = normalize(uMV * vec4(aNormal, 0.0)).xyz;
vTexCoord = aTexCoord;
gl_Position = uMVP * pos;
}
@@ -45,7 +45,7 @@ void main() {
vec3 h = normalize(v + s);
gl_FragColor = uAmbient * c
- + uDiffuse * c * max( dot(s, n), 0.0)
+ + uDiffuse * c * max(dot(s, n), 0.0)
#ifdef SPECULAR
+ uSpecular * uLightColor * pow( max( dot(h,n), 0.0), uShininess)
#endif
diff --git a/hello/hello.cc b/hello/hello.cc
@@ -119,14 +119,14 @@ int TestApp::init(void) {
if (!(e = Effect::load("simple")))
return -1;
- if (!(m = load_wavefront_obj("unitcube.obj")))
+ if (!(m = load_wavefront_obj("unitcubeoid.obj")))
return error("cannot load model");
printx("Object Loaded. %d vertices, %d indices.\n", m->vcount, m->icount);
vbuf.load(m->vdata, 32 * m->vcount);
ibuf.load(m->idx, 2 * m->icount);
- proj.setPerspective(D2R(90.0), width / (float) height, 0.1f, 250.0f);
+ proj.setPerspective(D2R(50.0), width / (float) height, 0.1f, 250.0f);
build();
zoom = SZ;
@@ -195,14 +195,14 @@ void TestApp::render(void) {
object.mv = model * view;
scene.LightColor.set(1.0, 1.0, 1.0);
- scene.LightPosition.set(0.0, 1.0, 0.0, 0.0);
+ scene.LightPosition = view * vec4(0, 1, 0, 0);
+ scene.LightPosition.w = 0;
material.Ambient.set(0.325,0.325,0.325,1.0);
material.Diffuse.set(1.0,1.0,1.0,1.0);
material.Specular.set(1.0,1.0,1.0,1.0);
- material.Specular.set(0, 0, 0, 0);
material.Color.set(0,1,0,1);
- material.Shininess = 50.0f;
+ material.Shininess = 250.0f;
scn.load(&scene, sizeof(scene));
mat.load(&material, sizeof(material));
diff --git a/test/assets/simple.glsl b/test/assets/simple.glsl
@@ -33,7 +33,7 @@ void main() {
#ifdef TEXTURED
vec4 c = texture2D(sampler0, vTexCoord);
#else
- vec4 c = vec4(1.0, 0.0, 0.0, 1.0);
+ vec4 c = uColor;
#endif
vec3 n = normalize(vNormal);
vec3 s;
@@ -48,7 +48,7 @@ void main() {
vec3 h = normalize(v + s);
gl_FragColor = uAmbient * c
- + uDiffuse * c * max( dot(s, n), 0.0)
+ + uDiffuse * c * max(dot(s, n), 0.0)
#ifdef SPECULAR
+ uSpecular * uLightColor * pow( max( dot(h,n), 0.0), uShininess)
#endif
diff --git a/test/object.cc b/test/object.cc
@@ -17,6 +17,8 @@
#include "matrix.h"
#include "shared.h"
+#include "texturefont.h"
+
#include "Model.h"
#include "Effect.h"
@@ -80,6 +82,8 @@ private:
UniformBuffer obj, mat, scn;
mat4 proj;
+
+ TextureFont font;
};
TestApp::TestApp() : App(), r(0.0) { }
@@ -95,6 +99,8 @@ int TestApp::init(void) {
ge = Effect::load("flat");
proj.setPerspective(D2R(90.0), width / (float) height, 0.1f, 250.0f);
+
+ font.init(this, "orbitron-bold-72");
return 0;
}
@@ -110,7 +116,7 @@ void TestApp::render(void) {
r += 1.0;
if (r > 360.0) r = 0.0;
- view.camera(vec3(1.5, 1.0, 2.0), vec3(1.5, 1.0, 0.0), vec3(0, 1, 0));
+ view.camera(vec3(0, 1.0, 3.0), vec3(0, 1.0, 0.0), vec3(0, 1, 0));
model.identity();
object.mvp = model * view * proj;
@@ -121,15 +127,16 @@ void TestApp::render(void) {
g->render();
scene.LightColor.set(1.0, 1.0, 1.0);
- scene.LightPosition.set(0.0, 1.0, 0.0, 0.0);
+ scene.LightPosition = view * vec4(0, 1, 0, 0);
+ scene.LightPosition.w = 0;
scn.load(&scene, sizeof(scene));
scn.use(U_SCENE);
material.Ambient.set(0.325,0.325,0.325,1.0);
material.Diffuse.set(1.0,1.0,1.0,1.0);
- material.Specular.set(1.0,1.0,1.0,1.0);
material.Specular.set(0, 0, 0, 0);
material.Shininess = 50.0f;
+ material.Color.set(1, 0, 0, 1);
mat.load(&material, sizeof(material));
mat.use(U_MATERIAL);
@@ -146,15 +153,19 @@ void TestApp::render(void) {
obj.load(&object, sizeof(object));
e->apply();
m->render();
-
+
material.Specular.set(1,1,1,1);
mat.load(&material, sizeof(material));
- model.identity().translate(1.50, 0.5, 0.0);
+ model.identity().translate(1.5, 0.5, 0.0);
object.mvp = model * view * proj;
object.mv = model * view;
obj.load(&object, sizeof(object));
e->apply();
m->render();
+
+ font.clear();
+ font.puts(100, 100, "Hello World!");
+ font.render(this);
}
App *createApp(void) {