| 128 setFile (null); |
128 setFile (null); |
| 129 setDrawOnly (false); |
129 setDrawOnly (false); |
| 130 setMessageLog (null); |
130 setMessageLog (null); |
| 131 m_width = m_height = -1; |
131 m_width = m_height = -1; |
| 132 m_hoverpos = g_origin; |
132 m_hoverpos = g_origin; |
| |
133 m_compiler = new GLCompiler; |
| 133 |
134 |
| 134 m_toolTipTimer = new QTimer (this); |
135 m_toolTipTimer = new QTimer (this); |
| 135 m_toolTipTimer->setSingleShot (true); |
136 m_toolTipTimer->setSingleShot (true); |
| 136 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer())); |
137 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer())); |
| 137 |
138 |
| 147 CameraIcon* info = &m_cameraIcons[cam]; |
148 CameraIcon* info = &m_cameraIcons[cam]; |
| 148 info->img = new QPixmap (getIcon (iconname)); |
149 info->img = new QPixmap (getIcon (iconname)); |
| 149 info->cam = cam; |
150 info->cam = cam; |
| 150 } |
151 } |
| 151 |
152 |
| 152 // Init VBO for axes |
|
| 153 float axesdata[18]; |
|
| 154 memset (axesdata, 0, sizeof axesdata); |
|
| 155 float colordata[18]; |
|
| 156 |
|
| 157 for (int i = 0; i < 3; ++i) |
|
| 158 { |
|
| 159 for (int j = 0; j < 3; ++j) |
|
| 160 { |
|
| 161 axesdata[(i * 6) + j] = g_GLAxes[i].vert.getCoordinate (j); |
|
| 162 axesdata[(i * 6) + 3 + j] = -g_GLAxes[i].vert.getCoordinate (j); |
|
| 163 } |
|
| 164 |
|
| 165 for (int j = 0; j < 2; ++j) |
|
| 166 { |
|
| 167 colordata[(i * 6) + (j * 3) + 0] = g_GLAxes[i].col.red(); |
|
| 168 colordata[(i * 6) + (j * 3) + 1] = g_GLAxes[i].col.green(); |
|
| 169 colordata[(i * 6) + (j * 3) + 2] = g_GLAxes[i].col.blue(); |
|
| 170 } |
|
| 171 } |
|
| 172 |
|
| 173 glGenBuffers (1, &g_GLAxes_VBO); |
|
| 174 glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO); |
|
| 175 glBufferData (GL_ARRAY_BUFFER, sizeof axesdata, axesdata, GL_STATIC_DRAW); |
|
| 176 glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO); |
|
| 177 |
|
| 178 calcCameraIcons(); |
153 calcCameraIcons(); |
| 179 } |
154 } |
| 180 |
155 |
| 181 // ============================================================================= |
156 // ============================================================================= |
| 182 // |
157 // |
| 278 |
255 |
| 279 setAutoFillBackground (false); |
256 setAutoFillBackground (false); |
| 280 setMouseTracking (true); |
257 setMouseTracking (true); |
| 281 setFocusPolicy (Qt::WheelFocus); |
258 setFocusPolicy (Qt::WheelFocus); |
| 282 |
259 |
| 283 g_vertexCompiler.compileDocument(); |
260 m_compiler->initialize(); |
| |
261 m_compiler->compileDocument(); |
| |
262 |
| |
263 initializeAxes(); |
| |
264 } |
| |
265 |
| |
266 // ============================================================================= |
| |
267 // |
| |
268 void GLRenderer::initializeAxes() |
| |
269 { |
| |
270 float axesdata[18]; |
| |
271 memset (axesdata, 0, sizeof axesdata); |
| |
272 float colordata[18]; |
| |
273 |
| |
274 for (int i = 0; i < 3; ++i) |
| |
275 { |
| |
276 for (int j = 0; j < 3; ++j) |
| |
277 { |
| |
278 axesdata[(i * 6) + j] = g_GLAxes[i].vert.getCoordinate (j); |
| |
279 axesdata[(i * 6) + 3 + j] = -g_GLAxes[i].vert.getCoordinate (j); |
| |
280 } |
| |
281 |
| |
282 for (int j = 0; j < 2; ++j) |
| |
283 { |
| |
284 colordata[(i * 6) + (j * 3) + 0] = g_GLAxes[i].col.red(); |
| |
285 colordata[(i * 6) + (j * 3) + 1] = g_GLAxes[i].col.green(); |
| |
286 colordata[(i * 6) + (j * 3) + 2] = g_GLAxes[i].col.blue(); |
| |
287 } |
| |
288 } |
| |
289 |
| |
290 glGenBuffers (1, &g_GLAxes_VBO); |
| |
291 glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO); |
| |
292 glBufferData (GL_ARRAY_BUFFER, sizeof axesdata, axesdata, GL_STATIC_DRAW); |
| |
293 glBindBuffer (GL_ARRAY_BUFFER, 0); |
| 284 } |
294 } |
| 285 |
295 |
| 286 // ============================================================================= |
296 // ============================================================================= |
| 287 // |
297 // |
| 288 QColor GLRenderer::getMainColor() |
298 QColor GLRenderer::getMainColor() |
| 398 glEnableClientState (GL_VERTEX_ARRAY); |
408 glEnableClientState (GL_VERTEX_ARRAY); |
| 399 |
409 |
| 400 if (gl_axes) |
410 if (gl_axes) |
| 401 { |
411 { |
| 402 glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO); |
412 glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO); |
| |
413 checkGLError(); |
| 403 glVertexPointer (3, GL_FLOAT, 0, NULL); |
414 glVertexPointer (3, GL_FLOAT, 0, NULL); |
| |
415 checkGLError(); |
| 404 glDrawArrays (GL_LINES, 0, 6); |
416 glDrawArrays (GL_LINES, 0, 6); |
| |
417 checkGLError(); |
| 405 } |
418 } |
| 406 |
419 |
| 407 drawVBOs (VBO_Triangles, GL_TRIANGLES); |
420 drawVBOs (VBO_Triangles, GL_TRIANGLES); |
| 408 drawVBOs (VBO_Quads, GL_QUADS); |
421 drawVBOs (VBO_Quads, GL_QUADS); |
| 409 drawVBOs (VBO_Lines, GL_LINES); |
422 drawVBOs (VBO_Lines, GL_LINES); |
| 410 drawVBOs (VBO_CondLines, GL_LINES); |
423 drawVBOs (VBO_CondLines, GL_LINES); |
| 411 |
424 |
| 412 glPopMatrix(); |
425 glPopMatrix(); |
| |
426 glBindBuffer (GL_ARRAY_BUFFER, 0); |
| 413 glDisableClientState (GL_VERTEX_ARRAY); |
427 glDisableClientState (GL_VERTEX_ARRAY); |
| |
428 checkGLError(); |
| 414 glDisable (GL_CULL_FACE); |
429 glDisable (GL_CULL_FACE); |
| 415 glMatrixMode (GL_MODELVIEW); |
430 glMatrixMode (GL_MODELVIEW); |
| 416 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); |
431 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); |
| 417 } |
432 } |
| 418 |
433 |
| 419 // ============================================================================= |
434 // ============================================================================= |
| 420 // |
435 // |
| 421 void GLRenderer::drawVBOs (E_VBOArray arrayType, GLenum type) |
436 void GLRenderer::drawVBOs (E_VBOArray arrayType, GLenum type) |
| 422 { |
437 { |
| 423 g_vertexCompiler.prepareVBOArray (arrayType); |
438 m_compiler->prepareVBOArray (arrayType); |
| 424 GLuint idx = g_vertexCompiler.getVBOIndex (arrayType); |
439 GLuint idx = m_compiler->getVBOIndex (arrayType); |
| 425 GLsizei count = g_vertexCompiler.getVBOCount (arrayType); |
440 GLsizei count = m_compiler->getVBOCount (arrayType); |
| 426 |
441 |
| 427 if (count > 0) |
442 if (count > 0) |
| 428 { |
443 { |
| 429 glBindBuffer (GL_ARRAY_BUFFER, idx); |
444 glBindBuffer (GL_ARRAY_BUFFER, idx); |
| |
445 checkGLError(); |
| 430 glVertexPointer (3, GL_FLOAT, 0, null); |
446 glVertexPointer (3, GL_FLOAT, 0, null); |
| |
447 checkGLError(); |
| 431 // glColorPointer (4, GL_UNSIGNED_BYTE, sizeof (GLCompiler::VAO), &array->data()[0].color); |
448 // glColorPointer (4, GL_UNSIGNED_BYTE, sizeof (GLCompiler::VAO), &array->data()[0].color); |
| 432 // glVertexAttribPointer (idx, 3, GL_FLOAT, GL_FALSE, 0, null); |
449 // glVertexAttribPointer (idx, 3, GL_FLOAT, GL_FALSE, 0, null); |
| 433 glDrawArrays (type, 0, count); |
450 glDrawArrays (type, 0, count); |
| |
451 checkGLError(); |
| 434 } |
452 } |
| 435 } |
453 } |
| 436 |
454 |
| 437 // ============================================================================= |
455 // ============================================================================= |
| 438 // This converts a 2D point on the screen to a 3D point in the model. If 'snap' |
456 // This converts a 2D point on the screen to a 3D point in the model. If 'snap' |