diff options
Diffstat (limited to 'glview.cc')
-rw-r--r-- | glview.cc | 47 |
1 files changed, 34 insertions, 13 deletions
@@ -22,7 +22,6 @@ #include <QWheelEvent> #include <QMouseEvent> -#include <GL/glew.h> #define FAR_FAR_AWAY 100000.0 @@ -49,32 +48,44 @@ extern GLint e1, e2, e3; void GLView::initializeGL() { - GLenum err = glewInit(); - if (GLEW_OK != err) { - fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err)); - } - glEnable(GL_DEPTH_TEST); glDepthRange(-FAR_FAR_AWAY, +FAR_FAR_AWAY); glClearColor(1.0, 1.0, 0.9, 0.0); +#ifdef ENABLE_OPENCSG + GLenum err = glewInit(); + if (GLEW_OK != err) { + fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err)); + } if (glewIsSupported("GL_VERSION_2_0")) { const char *vs_source = - "attribute vec3 tripos;\n" - "varying vec3 tp;\n" + "uniform float xscale, yscale;\n" + "attribute vec3 pos_b, pos_c;\n" + "attribute vec3 trig, mask;\n" + "varying vec3 tp, tr;\n" "void main() {\n" - " gl_Position = ftransform();\n" - " tp = tripos;\n" + " vec4 p0 = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + " vec4 p1 = gl_ModelViewProjectionMatrix * vec4(pos_b, 1.0);\n" + " vec4 p2 = gl_ModelViewProjectionMatrix * vec4(pos_c, 1.0);\n" + " float a = distance(vec2(xscale*p1.x/p1.w, yscale*p1.y/p1.w), vec2(xscale*p2.x/p2.w, yscale*p2.y/p2.w));\n" + " float b = distance(vec2(xscale*p0.x/p0.w, yscale*p0.y/p0.w), vec2(xscale*p1.x/p1.w, yscale*p1.y/p1.w));\n" + " float c = distance(vec2(xscale*p0.x/p0.w, yscale*p0.y/p0.w), vec2(xscale*p2.x/p2.w, yscale*p2.y/p2.w));\n" + " float s = (a + b + c) / 2.0;\n" + " float A = sqrt(s*(s-a)*(s-b)*(s-c));\n" + " float ha = 2.0*A/a;\n" + " gl_Position = p0;\n" + " tp = mask * ha;\n" + " tr = trig;\n" "}\n"; const char *fs_source = "uniform vec4 color1, color2;\n" - "varying vec3 tp;\n" + "varying vec3 tp, tr, tmp;\n" "void main() {\n" " gl_FragColor = color1;\n" - " if (tp.x > 0.95 || tp.y > 0.95 || tp.z > 0.95)\n" + " if (tp.x < tr.x || tp.y < tr.y || tp.z < tr.z)\n" " gl_FragColor = color2;\n" "}\n"; @@ -94,7 +105,12 @@ void GLView::initializeGL() shaderinfo[0] = edgeshader_prog; shaderinfo[1] = glGetUniformLocation(edgeshader_prog, "color1"); shaderinfo[2] = glGetUniformLocation(edgeshader_prog, "color2"); - shaderinfo[3] = glGetAttribLocation(edgeshader_prog, "tripos"); + shaderinfo[3] = glGetAttribLocation(edgeshader_prog, "trig"); + shaderinfo[4] = glGetAttribLocation(edgeshader_prog, "pos_b"); + shaderinfo[5] = glGetAttribLocation(edgeshader_prog, "pos_c"); + shaderinfo[6] = glGetAttribLocation(edgeshader_prog, "mask"); + shaderinfo[7] = glGetUniformLocation(edgeshader_prog, "xscale"); + shaderinfo[8] = glGetUniformLocation(edgeshader_prog, "yscale"); GLenum err = glGetError(); if (err != GL_NO_ERROR) { @@ -124,10 +140,15 @@ void GLView::initializeGL() } else { fprintf(stdout, "GLEW: GL_VERSION_2_0 is not supported!\n"); } +#endif /* ENABLE_OPENCSG */ } void GLView::resizeGL(int w, int h) { +#ifdef ENABLE_OPENCSG + shaderinfo[9] = w; + shaderinfo[10] = h; +#endif glViewport(0, 0, w, h); w_h_ratio = sqrt((double)w / (double)h); } |