Results 1 to 4 of 4

Thread: tetrahedron.cpp:124: error: 'gluPickMatrix' was not declared in this scope

  1. #1
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default tetrahedron.cpp:124: error: 'gluPickMatrix' was not declared in this scope

    Hello

    I read the book: "C++ GUI Programming with Qt4 (2nd Edition - Feb 2008)"

    I have this error message: "tetrahedron.cpp:124: error: 'gluPickMatrix' was not declared in this scope"

    Chapter 8

    tetrahedron.pro
    Qt Code:
    1. TEMPLATE = app
    2. QT += opengl
    3. CONFIG += console
    4. HEADERS = tetrahedron.h
    5. SOURCES = main.cpp \
    6. tetrahedron.cpp
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include <iostream>
    3.  
    4. #include "tetrahedron.h"
    5.  
    6. using namespace std;
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QApplication app(argc, argv);
    11. if (!QGLFormat::hasOpenGL()) {
    12. cerr << "This system has no OpenGL support" << endl;
    13. return 1;
    14. }
    15.  
    16. Tetrahedron tetrahedron;
    17. tetrahedron.setWindowTitle(QObject::tr("Tetrahedron"));
    18. tetrahedron.resize(300, 300);
    19. tetrahedron.show();
    20.  
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    tetrahedron.h
    Qt Code:
    1. #ifndef TETRAHEDRON_H
    2. #define TETRAHEDRON_H
    3.  
    4. #include <QGLWidget>
    5.  
    6. class Tetrahedron : public QGLWidget
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. Tetrahedron(QWidget *parent = 0);
    12.  
    13. protected:
    14. void initializeGL();
    15. void resizeGL(int width, int height);
    16. void paintGL();
    17. void mousePressEvent(QMouseEvent *event);
    18. void mouseMoveEvent(QMouseEvent *event);
    19. void mouseDoubleClickEvent(QMouseEvent *event);
    20.  
    21. private:
    22. void draw();
    23. int faceAtPosition(const QPoint &pos);
    24.  
    25. GLfloat rotationX;
    26. GLfloat rotationY;
    27. GLfloat rotationZ;
    28. QColor faceColors[4];
    29. QPoint lastPos;
    30. };
    31.  
    32. #endif
    To copy to clipboard, switch view to plain text mode 

    tetrahedron.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include <QtOpenGL>
    3.  
    4. #include "tetrahedron.h"
    5.  
    6. Tetrahedron::Tetrahedron(QWidget *parent)
    7. : QGLWidget(parent)
    8. {
    9. setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
    10. rotationX = -21.0;
    11. rotationY = -57.0;
    12. rotationZ = 0.0;
    13. faceColors[0] = Qt::red;
    14. faceColors[1] = Qt::green;
    15. faceColors[2] = Qt::blue;
    16. faceColors[3] = Qt::yellow;
    17. }
    18.  
    19. void Tetrahedron::initializeGL()
    20. {
    21. qglClearColor(Qt::black);
    22. glShadeModel(GL_FLAT);
    23. glEnable(GL_DEPTH_TEST);
    24. glEnable(GL_CULL_FACE);
    25. }
    26.  
    27. void Tetrahedron::resizeGL(int width, int height)
    28. {
    29. glViewport(0, 0, width, height);
    30. glMatrixMode(GL_PROJECTION);
    31. glLoadIdentity();
    32. GLfloat x = GLfloat(width) / height;
    33. glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);
    34. glMatrixMode(GL_MODELVIEW);
    35. }
    36.  
    37. void Tetrahedron::paintGL()
    38. {
    39. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    40. draw();
    41. }
    42.  
    43. void Tetrahedron::mousePressEvent(QMouseEvent *event)
    44. {
    45. lastPos = event->pos();
    46. }
    47.  
    48. void Tetrahedron::mouseMoveEvent(QMouseEvent *event)
    49. {
    50. GLfloat dx = GLfloat(event->x() - lastPos.x()) / width();
    51. GLfloat dy = GLfloat(event->y() - lastPos.y()) / height();
    52.  
    53. if (event->buttons() & Qt::LeftButton) {
    54. rotationX += 180 * dy;
    55. rotationY += 180 * dx;
    56. updateGL();
    57. } else if (event->buttons() & Qt::RightButton) {
    58. rotationX += 180 * dy;
    59. rotationZ += 180 * dx;
    60. updateGL();
    61. }
    62. lastPos = event->pos();
    63. }
    64.  
    65. void Tetrahedron::mouseDoubleClickEvent(QMouseEvent *event)
    66. {
    67. int face = faceAtPosition(event->pos());
    68. if (face != -1) {
    69. QColor color = QColorDialog::getColor(faceColors[face], this);
    70. if (color.isValid()) {
    71. faceColors[face] = color;
    72. updateGL();
    73. }
    74. }
    75. }
    76.  
    77. void Tetrahedron::draw()
    78. {
    79. static const GLfloat P1[3] = { 0.0, -1.0, +2.0 };
    80. static const GLfloat P2[3] = { +1.73205081, -1.0, -1.0 };
    81. static const GLfloat P3[3] = { -1.73205081, -1.0, -1.0 };
    82. static const GLfloat P4[3] = { 0.0, +2.0, 0.0 };
    83.  
    84. static const GLfloat * const coords[4][3] = {
    85. { P1, P2, P3 }, { P1, P3, P4 }, { P1, P4, P2 }, { P2, P4, P3 }
    86. };
    87.  
    88. glMatrixMode(GL_MODELVIEW);
    89. glLoadIdentity();
    90. glTranslatef(0.0, 0.0, -10.0);
    91. glRotatef(rotationX, 1.0, 0.0, 0.0);
    92. glRotatef(rotationY, 0.0, 1.0, 0.0);
    93. glRotatef(rotationZ, 0.0, 0.0, 1.0);
    94.  
    95. for (int i = 0; i < 4; ++i) {
    96. glLoadName(i);
    97. glBegin(GL_TRIANGLES);
    98. qglColor(faceColors[i]);
    99. for (int j = 0; j < 3; ++j) {
    100. glVertex3f(coords[i][j][0], coords[i][j][1],
    101. coords[i][j][2]);
    102. }
    103. glEnd();
    104. }
    105. }
    106.  
    107. int Tetrahedron::faceAtPosition(const QPoint &pos)
    108. {
    109. const int MaxSize = 512;
    110. GLuint buffer[MaxSize];
    111. GLint viewport[4];
    112.  
    113. glGetIntegerv(GL_VIEWPORT, viewport);
    114. glSelectBuffer(MaxSize, buffer);
    115. glRenderMode(GL_SELECT);
    116.  
    117. glInitNames();
    118. glPushName(0);
    119.  
    120. glMatrixMode(GL_PROJECTION);
    121. glPushMatrix();
    122. glLoadIdentity();
    123. gluPickMatrix(GLdouble(pos.x()), GLdouble(viewport[3] - pos.y()),
    124. 5.0, 5.0, viewport);
    125. GLfloat x = GLfloat(width()) / height();
    126. glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);
    127. draw();
    128. glMatrixMode(GL_PROJECTION);
    129. glPopMatrix();
    130.  
    131. if (!glRenderMode(GL_RENDER))
    132. return -1;
    133. return buffer[3];
    134. }
    To copy to clipboard, switch view to plain text mode 

    Thanks

    Ivan

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: tetrahedron.cpp:124: error: 'gluPickMatrix' was not declared in this scope

    I have this error message: "tetrahedron.cpp:124: error: 'gluPickMatrix' was not declared in this scope"
    Well, that error sort of implies that you haven't included the header file that contains the definition of "gluPickMatrix" doesn't it? Try looking for "glu.h" in your OpenGL installation. (Not QtOpenGL, OpenGL).

  3. #3
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: tetrahedron.cpp:124: error: 'gluPickMatrix' was not declared in this scope

    Have I to do to make it work? Must I install the OpenGL library? GLUT?

  4. #4
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: tetrahedron.cpp:124: error: 'gluPickMatrix' was not declared in this scope

    Yes! I solved this problem!

    I included in the file 'tetrahedron.cpp':

    Qt Code:
    1. #include <GL/glu.h>
    To copy to clipboard, switch view to plain text mode 

    But when I close the application I see the error message.

    tetrahedron.pngCrash.png

Similar Threads

  1. Replies: 3
    Last Post: 8th April 2011, 17:09
  2. Variable not declared in this scope error
    By hojoff79 in forum Newbie
    Replies: 1
    Last Post: 30th December 2010, 00:29
  3. Replies: 10
    Last Post: 22nd September 2010, 06:20
  4. Replies: 2
    Last Post: 16th July 2010, 07:17
  5. glutSolidSphere was not declared in this scope error
    By nuts_fever_007 in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2009, 04:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.