Results 1 to 2 of 2

Thread: Qt and OpenGL: gluPerspective

  1. #1
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt and OpenGL: gluPerspective

    Hello to all. I created this simple program with Qt 4.8.2 and OpenGL. It comes to drawing a 3D grid and display it in perspective using gluPerspective. In addition, I use the mouse to move around the scene. The problem I have is to better manage the movement of the mouse. I put my project in attachment. Can you help me make better use of the mouse? The movement of the grid is chaotic, and I wanted with the right mouse button the zoom or removal and the left mouse button the grid rotation axis x and y.piano_griglia3D.zip

    I'm going crazy to solve

  2. #2
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and OpenGL: gluPerspective

    The code with glOrtho():
    Qt Code:
    1. #include "glwidget.h"
    2. #include <GL/gl.h>
    3. #include "GL/glut.h"
    4. #include "GL/freeglut.h"
    5. #include "GL/freeglut_ext.h"
    6.  
    7. GLWidget::GLWidget(QWidget *parent) :
    8. QGLWidget(parent)
    9. {
    10. //
    11. }
    12.  
    13. void GLWidget::resizeGL(int w, int h)
    14. {
    15. int side = qMin(w, h);
    16. glViewport((w - side) / 2, (h - side) / 2, side, side);
    17.  
    18. // setta la matrice corrente a quella della proiezione e cancellala
    19. glMatrixMode(GL_PROJECTION);
    20. glLoadIdentity();
    21.  
    22. // definisci il volume di clipping (frustum) del mondo (left, right, bottom, top, near, far)
    23. // in base alla massima ampiezza
    24. glOrtho(-12.0f, 12.0f, -12.0f, 12.0f, 0.0f, 10.0f);
    25. //gluPerspective(45.0f, (GLfloat)w/(GLfloat)h, -10.0f, 10.0f);
    26.  
    27. // setta la matrice corrente a quella di modello-vista e cancellala
    28. glMatrixMode(GL_MODELVIEW);
    29. glLoadIdentity();
    30. }
    31.  
    32. void GLWidget::initializeGL()
    33. {
    34. // specifica il colore lilla come colore di background
    35. // usato da glClear()
    36. glClearColor(0.7, 0.7, 0.8, 1);
    37. }
    38.  
    39. void GLWidget::paintGL()
    40. {
    41. // cancella lo sfondo con il colore scelto da glClearColor
    42. // clear buffer
    43. glClear(GL_COLOR_BUFFER_BIT);
    44.  
    45. //----------- 20x20 grid: draw XY-grid with default size -----------
    46. glBegin(GL_LINES);
    47.  
    48. glColor3f(0.5f, 0.5f, 0.5f);
    49. for(float i = 1.0f; i <= 10.0f; i+= 1.0f)
    50. {
    51. glVertex3f(-10.0f, i, 0); // lines parallel to X-axis
    52. glVertex3f( 10.0f, i, 0);
    53. glVertex3f(-10.0f, -i, 0); // lines parallel to X-axis
    54. glVertex3f( 10.0f, -i, 0);
    55.  
    56. glVertex3f( i, -10.0f, 0); // lines parallel to Y-axis
    57. glVertex3f( i, 10.0f, 0);
    58. glVertex3f(-i, -10.0f, 0); // lines parallel to Y-axis
    59. glVertex3f(-i, 10.0f, 0);
    60. }
    61.  
    62. // x-axis
    63. glColor3f(1, 0, 0);
    64. glVertex3f(-10.0f, 0, 0);
    65. glVertex3f( 10.0f, 0, 0);
    66.  
    67. // y-axis
    68. glColor3f(0, 0, 1);
    69. glVertex3f(0, -10.0f, 0);
    70. glVertex3f(0, 10.0f, 0);
    71.  
    72. glEnd();
    73. //-----------------------------------------------------------------
    74. }
    To copy to clipboard, switch view to plain text mode 
    how to get the perspective gluPerspective () so you can see my perspective grid ?
    I would use GLWidget::mouseMoveEvent (QMouseEvent * event) to rotate the grid and for zooming and moving away. How should I write the code ?

Similar Threads

  1. gluPerspective and gluOrtho2d not found in QGLWidget
    By litedrive in forum Qt Programming
    Replies: 3
    Last Post: 8th September 2013, 15:43
  2. converting GLUT/OpenGL to Qt/OpenGL - displaying issue
    By yoti13 in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2012, 00:45
  3. Replies: 0
    Last Post: 6th December 2009, 00:41
  4. Qt with OpenGL ES for ARM9 - All OpenGL ES tests have failed!
    By vinpa in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 3rd December 2009, 10:10
  5. Problem from OpenGL to QT OpenGL
    By nuts_fever_007 in forum Newbie
    Replies: 5
    Last Post: 15th May 2009, 09:37

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.