1 /*
2  * Copyright (C) 2010 Emweb bv, Herent, Belgium.
3  *
4  * See the LICENSE file for terms of use.
5  */
6 
7 #ifndef PAINTWIDGET_H_
8 #define PAINTWIDGET_H_
9 
10 #include <Wt/WGLWidget.h>
11 
12 using namespace Wt;
13 
14 // You must inherit Wt::WGLWidget to draw a 3D scene
15 class PaintWidget: public WGLWidget
16 {
17 public:
18   PaintWidget(const bool & useBinaryBuffers);
19 
20   // Specialization of WGLWidgeT::intializeGL()
21   void initializeGL();
22 
23   // Specialization of WGLWidgeT::paintGL()
24   void paintGL();
25 
26   // Specialization of WGLWidgeT::resizeGL()
27   void resizeGL(int width, int height);
28 
29   // Sets the shader source. Must be set before the widget is first rendered.
30   void setShaders(const std::string &vertexShader,
31       const std::string &fragmentShader);
32 
33 private:
34   bool initialized_;
35 
36   // The shaders, in plain text format
37   std::string vertexShader_;
38   std::string fragmentShader_;
39 
40   // Program and related variables
41   Program         shaderProgram_;
42   AttribLocation  vertexPositionAttribute_;
43   AttribLocation  vertexNormalAttribute_;
44   UniformLocation pMatrixUniform_;
45   UniformLocation cMatrixUniform_;
46   UniformLocation mvMatrixUniform_;
47   UniformLocation nMatrixUniform_;
48 
49   // A client-side JavaScript matrix variable
50   JavaScriptMatrix4x4 jsMatrix_;
51 
52   // The so-called VBOs, Vertex Buffer Objects
53   // This one contains both vertex (xyz) and normal (xyz) data
54   Buffer objBuffer_;
55 
56   bool useBinaryBuffers_;
57 };
58 
59 #endif
60 
61