# HG changeset patch # User John Tsiombikas # Date 1354512639 -7200 # Node ID 178a9e3c3c8cbbacf6f676ea88438acad1c0bc78 # Parent befe01bbd27fd21b29eeff8e4f925314d0dd44a8 isolines diff -r befe01bbd27f -r 178a9e3c3c8c Makefile --- a/Makefile Sun Dec 02 17:16:32 2012 +0200 +++ b/Makefile Mon Dec 03 07:30:39 2012 +0200 @@ -2,7 +2,7 @@ obj = $(src:.c=.o) bin = test -CFLAGS = -pedantic -Wall -g +CFLAGS = -pedantic -Wall -g -O3 -ffast-math LDFLAGS = $(libgl) ifeq ($(shell uname -s), Darwin) diff -r befe01bbd27f -r 178a9e3c3c8c sdr/bezier.p.glsl --- a/sdr/bezier.p.glsl Sun Dec 02 17:16:32 2012 +0200 +++ b/sdr/bezier.p.glsl Mon Dec 03 07:30:39 2012 +0200 @@ -1,7 +1,11 @@ #version 410 compatibility +uniform int tess_level; + in vec3 normal; in vec3 vpos; +in vec2 uv; + void main() { @@ -15,12 +19,21 @@ float ndotl = max(dot(n, l), 0.0); float ndoth = max(dot(n, h), 0.0); + vec3 ka = gl_FrontMaterial.ambient.xyz; vec3 kd = gl_FrontMaterial.diffuse.xyz; vec3 ks = gl_FrontMaterial.specular.xyz; float shin = gl_FrontMaterial.shininess; vec3 diffuse = kd * ndotl * gl_LightSource[0].diffuse.xyz; vec3 specular = ks * pow(ndoth, shin) * gl_LightSource[0].specular.xyz; + vec3 ambient = ka * gl_LightModel.ambient.xyz; + vec3 color = ambient + diffuse + specular; - gl_FragColor = vec4(diffuse + specular, gl_FrontMaterial.diffuse.w); + vec2 tess_uv = mod(uv * float(tess_level), 1.0); + +#define STEPSZ 0.1 + float wire = smoothstep(0.0, STEPSZ, tess_uv.x) * smoothstep(1.0, 1.0 - STEPSZ, tess_uv.x); + wire *= smoothstep(0.0, STEPSZ, tess_uv.y) * smoothstep(1.0, 1.0 - STEPSZ, tess_uv.y); + + gl_FragColor = vec4(mix(vec3(0.0, 0.0, 0.0), color, wire), gl_FrontMaterial.diffuse.w); } diff -r befe01bbd27f -r 178a9e3c3c8c sdr/bezier.te.glsl --- a/sdr/bezier.te.glsl Sun Dec 02 17:16:32 2012 +0200 +++ b/sdr/bezier.te.glsl Mon Dec 03 07:30:39 2012 +0200 @@ -4,6 +4,7 @@ out vec3 normal; out vec3 vpos; +out vec2 uv; uniform vec3 norm_scale; @@ -16,6 +17,8 @@ vec3 pos = bezier_patch(gl_TessCoord.x, gl_TessCoord.y); normal = gl_NormalMatrix * bezier_patch_norm(gl_TessCoord.x, gl_TessCoord.y); + uv = gl_TessCoord.xy; + gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1.0); vpos = (gl_ModelViewMatrix * vec4(pos, 1.0)).xyz; } diff -r befe01bbd27f -r 178a9e3c3c8c src/test.c --- a/src/test.c Sun Dec 02 17:16:32 2012 +0200 +++ b/src/test.c Mon Dec 03 07:30:39 2012 +0200 @@ -7,7 +7,7 @@ #include "teapot_data.h" void disp(void); -void draw_teapot(void); +void draw_teapot(float scale); void draw_teapot_patch(struct vec3 *bez_cp, int *index, int flip, float rot); void set_material(float dr, float dg, float db, float sr, float sg, float sb, float shin); void reshape(int x, int y); @@ -25,6 +25,8 @@ int main(int argc, char **argv) { + float amb[] = {0.05, 0.05, 0.05, 0.0}; + glutInit(&argc, argv); glutInitWindowSize(1280, 800); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); @@ -35,10 +37,12 @@ glutKeyboardFunc(keyb); glutMouseFunc(mouse); glutMotionFunc(motion); + glutIdleFunc(glutPostRedisplay); glewInit(); - glClearColor(0.07, 0.07, 0.07, 1); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb); + glClearColor(amb[0], amb[1], amb[2], 1); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); @@ -51,6 +55,7 @@ printf("maximum tesselation levels: %d\n", max_tess_level); glPatchParameteri(GL_PATCH_VERTICES, 16); + glProvokingVertex(GL_FIRST_VERTEX_CONVENTION); { unsigned int vsdr, tcsdr, tesdr, psdr; @@ -94,17 +99,21 @@ set_material(0.2, 0.35, 1.0, 1.0, 1.0, 1.0, 60.0); - draw_teapot(); + draw_teapot(2.0); glutSwapBuffers(); } -void draw_teapot(void) +void draw_teapot(float scale) { int i; + scale /= 2.0; + glPushMatrix(); + glTranslatef(0, -3.15 * scale * 0.5, 0); glRotatef(-90.0, 1, 0, 0); + glScalef(scale, scale, scale); glUseProgram(prog); set_uniform_int(prog, "tess_level", tess_level);