@@ -70,6 +70,7 @@ GLFWwindow* MiniGL::m_glfw_window = nullptr;
70
70
bool MiniGL::m_vsync = false ;
71
71
double MiniGL::m_lastTime;
72
72
Shader MiniGL::m_shader;
73
+ Shader MiniGL::m_shader_screen;
73
74
Matrix4r MiniGL::m_modelview_matrix;
74
75
Matrix4r MiniGL::m_projection_matrix;
75
76
Vector3r MiniGL::m_ambientIntensity;
@@ -117,11 +118,9 @@ void MiniGL::coordinateSystem()
117
118
118
119
void MiniGL::drawVector (const Vector3r &a, const Vector3r &b, const float w, float *color)
119
120
{
120
- float thickness = 0.001 * w;
121
+ float thickness = 0 .001f * w;
121
122
122
- glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
123
123
drawCylinder (a, b, color, thickness, 8 , false );
124
- glPolygonMode (GL_FRONT_AND_BACK, drawMode);
125
124
}
126
125
127
126
void MiniGL::drawCylinder (const Vector3r &a, const Vector3r &b, const float *color, const float radius, const unsigned int subdivisions, const bool lighting)
@@ -710,7 +709,7 @@ void MiniGL::initLights ()
710
709
m_lightPosition.segment <3 >(2 * 3 ) << 0.0 , 10.0 , 10.0 ;
711
710
}
712
711
713
- void MiniGL::initShader (const std::string& shaderPath)
712
+ void MiniGL::initShaders (const std::string& shaderPath)
714
713
{
715
714
Shader& shader = m_shader;
716
715
shader.compileShaderFile (GL_VERTEX_SHADER, shaderPath + " /mini.vert" );
@@ -730,6 +729,16 @@ void MiniGL::initShader(const std::string& shaderPath)
730
729
shader.addUniform (" specularReflectance" );
731
730
shader.addUniform (" shininess" );
732
731
shader.end ();
732
+
733
+ Shader& screenShader = m_shader_screen;
734
+ screenShader.compileShaderFile (GL_VERTEX_SHADER, shaderPath + " /mini_screen.vert" );
735
+ screenShader.compileShaderFile (GL_FRAGMENT_SHADER, shaderPath + " /mini_screen.frag" );
736
+ screenShader.createAndLinkProgram ();
737
+ screenShader.begin ();
738
+ screenShader.addUniform (" width" );
739
+ screenShader.addUniform (" height" );
740
+ screenShader.addUniform (" color" );
741
+ screenShader.end ();
733
742
}
734
743
735
744
void MiniGL::enableShader (const Vector3r& ambientReflectance, const Vector3r& diffuseReflectance, const Vector3r& specularReflectance, const Real shininess, const Real pointSize)
@@ -759,6 +768,21 @@ void MiniGL::disableShader()
759
768
shader.end ();
760
769
}
761
770
771
+ void MiniGL::enableScreenShader (const Vector3r& color)
772
+ {
773
+ Shader& shader = m_shader_screen;
774
+ shader.begin ();
775
+ glUniform1f (shader.getUniform (" width" ), static_cast <Real>(m_width));
776
+ glUniform1f (shader.getUniform (" height" ), static_cast <Real>(m_height));
777
+ glUniform3fv (shader.getUniform (" color" ), 1 , &color (0 ));
778
+ }
779
+
780
+ void MiniGL::disableScreenShader ()
781
+ {
782
+ Shader& shader = m_shader_screen;
783
+ shader.end ();
784
+ }
785
+
762
786
void MiniGL::supplyVectors (GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const Real* data)
763
787
{
764
788
glBindBuffer (GL_ARRAY_BUFFER, vbo);
@@ -1006,25 +1030,17 @@ void MiniGL::error_callback(int error, const char* description)
1006
1030
1007
1031
void MiniGL::drawSelectionRect ()
1008
1032
{
1009
- glDisable (GL_LIGHTING);
1010
- glPushMatrix ();
1011
- glLoadIdentity ();
1012
- glMatrixMode (GL_PROJECTION);
1013
- glPushMatrix ();
1014
- glLoadIdentity ();
1015
- glOrtho (0 .0f , m_width, m_height, 0 .0f , -1 .0f , 1 .0f );
1016
- glBegin (GL_LINE_LOOP);
1017
- glColor3f (1 , 0 , 0 ); // Set the colour to red
1018
- glVertex2f (static_cast <GLfloat>(m_selectionStart[0 ]), static_cast <GLfloat>(m_selectionStart[1 ]));
1019
- glVertex2f (static_cast <GLfloat>(m_selectionStart[0 ]), static_cast <GLfloat>(mouse_pos_y_old));
1020
- glVertex2f (mouse_pos_x_old, mouse_pos_y_old);
1021
- glVertex2f (mouse_pos_x_old, m_selectionStart[1 ]);
1022
- glEnd ();
1023
- glPopMatrix ();
1024
- glMatrixMode (GL_MODELVIEW);
1025
-
1026
- glPopMatrix ();
1027
- glEnable (GL_LIGHTING);
1033
+ Real selectionRect[] = {
1034
+ static_cast <Real>(m_selectionStart[0 ]), static_cast <Real>(m_selectionStart[1 ]),
1035
+ static_cast <Real>(m_selectionStart[0 ]), static_cast <Real>(mouse_pos_y_old),
1036
+ static_cast <Real>(mouse_pos_x_old), static_cast <Real>(mouse_pos_y_old),
1037
+ static_cast <Real>(mouse_pos_x_old), static_cast <Real>(m_selectionStart[1 ])
1038
+ };
1039
+ enableScreenShader (Vector3r (1 , 0 , 0 ));
1040
+ supplyVectors (0 , m_vbo_vertices, 2 , 4 , &selectionRect[0 ]);
1041
+ glDrawArrays (GL_LINE_LOOP, 0 , 4 );
1042
+ glDisableVertexAttribArray (0 );
1043
+ disableScreenShader ();
1028
1044
}
1029
1045
1030
1046
void MiniGL::mainLoop ()
0 commit comments