40 // ============================================================================= |
40 // ============================================================================= |
41 void renderer::initializeGL () { |
41 void renderer::initializeGL () { |
42 glLoadIdentity(); |
42 glLoadIdentity(); |
43 glMatrixMode (GL_MODELVIEW); |
43 glMatrixMode (GL_MODELVIEW); |
44 |
44 |
45 setBackground (); |
45 setColor (gl_bgcolor, &glClearColor); |
46 |
46 |
47 glEnable (GL_POLYGON_OFFSET_FILL); |
47 glEnable (GL_POLYGON_OFFSET_FILL); |
48 glPolygonOffset (1.0f, 1.0f); |
48 glPolygonOffset (1.0f, 1.0f); |
49 |
49 |
50 glEnable (GL_DEPTH_TEST); |
50 glEnable (GL_DEPTH_TEST); |
63 } |
63 } |
64 |
64 |
65 // ============================================================================= |
65 // ============================================================================= |
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
67 // ============================================================================= |
67 // ============================================================================= |
68 void renderer::setBackground () { |
68 void renderer::setColor (strconfig& cfg, |
69 QColor col (gl_bgcolor.value.chars()); |
69 void (*func) (float, float, float, float)) |
70 |
70 { |
71 if (col.isValid ()) { |
71 QColor col (cfg.value.chars()); |
72 glClearColor ( |
72 |
73 ((double)col.red()) / 255.0f, |
73 if (!col.isValid ()) |
74 ((double)col.green()) / 255.0f, |
74 return; |
75 ((double)col.blue()) / 255.0f, |
75 |
76 1.0f); |
76 (*func) ( |
77 } else { |
77 ((double)col.red()) / 255.0f, |
78 glClearColor (0.8f, 0.8f, 0.85f, 1.0f); |
78 ((double)col.green()) / 255.0f, |
79 } |
79 ((double)col.blue()) / 255.0f, |
|
80 1.0f); |
80 } |
81 } |
81 |
82 |
82 // ============================================================================= |
83 // ============================================================================= |
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
84 // ============================================================================= |
85 // ============================================================================= |
171 break; |
172 break; |
172 |
173 |
173 case OBJ_Triangle: |
174 case OBJ_Triangle: |
174 { |
175 { |
175 LDTriangle* tri = static_cast<LDTriangle*> (obj); |
176 LDTriangle* tri = static_cast<LDTriangle*> (obj); |
176 glColor3f (0.5f, 0.0f, 0.0f); // Draw all polygons red for now |
177 setColor (gl_maincolor, glColor4f); |
177 glBegin (GL_TRIANGLES); |
178 glBegin (GL_TRIANGLES); |
178 for (short i = 0; i < 3; ++i) |
179 for (short i = 0; i < 3; ++i) |
179 GL_VERTEX (tri->vaCoords[i]) |
180 GL_VERTEX (tri->vaCoords[i]) |
180 glEnd (); |
181 glEnd (); |
181 } |
182 } |
182 break; |
183 break; |
183 |
184 |
184 case OBJ_Quad: |
185 case OBJ_Quad: |
185 { |
186 { |
186 LDQuad* quad = static_cast<LDQuad*> (obj); |
187 LDQuad* quad = static_cast<LDQuad*> (obj); |
187 glColor3f (0.5f, 0.0f, 0.0f); |
188 setColor (gl_maincolor, glColor4f); |
188 glBegin (GL_QUADS); |
189 glBegin (GL_QUADS); |
189 for (short i = 0; i < 4; ++i) |
190 for (short i = 0; i < 4; ++i) |
190 GL_VERTEX (quad->vaCoords[i]) |
191 GL_VERTEX (quad->vaCoords[i]) |
191 glEnd (); |
192 glEnd (); |
192 } |
193 } |