Hi, I struggled a lot to load OBJ files, then I found GLM library and Im amazed how easy,
then I took my old QT OpenGL code,
and Ive started making a new FPS view game.
Problem is, I have no experience in how to rotate the view.

Here's how I rotate (xRot = 0, yRot = 0)
Qt Code:
  1. glRotatef(xRot+speedX, 0, 0.01f, 0);
  2. glRotatef(yRot+speedY, 0.01f, 0, 0);
To copy to clipboard, switch view to plain text mode 

and here's how I make rotation with speedX and speedY:

Qt Code:
  1. void GLWidget::mouseMoveEvent(QMouseEvent *event) {
  2. if(event->x() != this->width()/2 && event->y() != this->height()/2) {
  3. speedX += (float)event->x()/500;
  4. speedY += (float)event->y()/500;
  5. }
  6.  
  7. //Mouse mouse to Center in Linux
  8. dpy = XOpenDisplay(0);
  9. root_window = XRootWindow(dpy, 0);
  10. XSelectInput(dpy, root_window, KeyReleaseMask);
  11. XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, this->width()/2, this->height()/2);
  12. XFlush(dpy); // Flushes the output buffer, therefore updates the cursor's position. Thanks to Achernar.
  13. XCloseDisplay(dpy);
  14. }
To copy to clipboard, switch view to plain text mode 

And here's full Code, if it interests anybody (its in one file):
Qt Code:
  1. #include <QtGui/QApplication>
  2. #include <QtOpenGL/QGLWidget>
  3. #include <QtGui/QMouseEvent>
  4. #include <GL/glu.h>
  5. #include <QTimer>
  6. #include <QThread>
  7. #include <QCursor>
  8. #include <X11/Xlib.h>
  9. #include <math.h>
  10. #include <GL/glfw.h>
  11. #include "glm.h"
  12. #define screenWidth 800
  13. #define screenHeight 600
  14.  
  15. #define PI 3.14159265358979
  16. float cameraX, cameraY, cameraZ;
  17. float xMove, yMove, zMove;
  18. float angleX = 0;
  19. float angleY = 0;
  20. float angleZ = 0;
  21. float xRot = 0;
  22. float yRot = 0;
  23. float zRot = 0;
  24. float z = 1.0f;
  25. float speedX = 0.0f;
  26. float speedY = 0.0f;
  27. GLMmodel *model = 0;
  28. Display *dpy;
  29. Window root_window;
  30.  
  31. class GLWidget : public QGLWidget{
  32. public:
  33. GLWidget();
  34. void initializeGL();
  35. void resizeGL(int w, int h);
  36. void paintGL();
  37. void mousePressEvent(QMouseEvent *event);
  38. void mouseMoveEvent(QMouseEvent *event);
  39. void keyPressEvent(QKeyEvent *event);
  40. private slots:
  41. void updateGL();
  42. private:
  43. QTimer glUpdateTime;
  44. };
  45.  
  46. GLWidget::GLWidget() {
  47. connect(&glUpdateTime, SIGNAL(timeout()), this, SLOT(updateGL()));
  48. glUpdateTime.start(1);
  49. setMouseTracking(true);
  50. }
  51.  
  52. void GLWidget::updateGL() {
  53. this->update();
  54. }
  55.  
  56. void GLWidget::initializeGL() {
  57. glDisable(GL_TEXTURE_2D);
  58. glDisable(GL_DEPTH_TEST);
  59. glDisable(GL_COLOR_MATERIAL);
  60. glEnable(GL_BLEND);
  61. glEnable(GL_POLYGON_SMOOTH);
  62. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  63. glClearColor(0, 0, 0, 0);
  64. cameraX = 0;
  65. cameraY = 0;
  66. cameraZ = -10;
  67. }
  68.  
  69. void GLWidget::resizeGL(int w, int h) {
  70. glMatrixMode(GL_PROJECTION);
  71. glLoadIdentity();
  72. gluPerspective(40.0,(GLdouble)w/(GLdouble)h,0.5,20.0);
  73. glMatrixMode(GL_MODELVIEW);
  74. glLoadIdentity();
  75. glViewport(0, 0, w, h);
  76. }
  77.  
  78. void GLWidget::paintGL() {
  79. if(!model) {
  80. model = glmReadOBJ("/home/marcus/untitled/untitled.obj");
  81. glmUnitize(model);
  82. glmFacetNormals(model);
  83. glmVertexNormals(model, 90.0);
  84. }
  85.  
  86. glClear(GL_COLOR_BUFFER_BIT);
  87. glLoadIdentity();
  88. glTranslatef(0, 0, -z);
  89. glRotatef(xRot+speedX, 0, 0.01f, 0);
  90. glRotatef(yRot+speedY, 0.01f, 0, 0);
  91. glTranslatef(cameraX + xMove, cameraY + yMove, cameraZ + zMove);
  92. glmDraw(model, GLM_SMOOTH | GLM_MATERIAL);
  93. glTranslatef(-2.0f, 0.0f, 0.0f);
  94. glmDraw(model, GLM_SMOOTH | GLM_MATERIAL);
  95. glTranslatef(-2.0f, 0.0f, 0.0f);
  96. glmDraw(model, GLM_SMOOTH | GLM_MATERIAL);
  97. glTranslatef(-2.0f, 0.0f, 0.0f);
  98. glmDraw(model, GLM_SMOOTH | GLM_MATERIAL);
  99. glTranslatef(-2.0f, 0.0f, 0.0f);
  100. glmDraw(model, GLM_SMOOTH | GLM_MATERIAL);
  101. }
  102. void GLWidget::mousePressEvent(QMouseEvent *event) {
  103.  
  104. }
  105. void GLWidget::mouseMoveEvent(QMouseEvent *event) {
  106. if(event->x() != this->width()/2 && event->y() != this->height()/2) {
  107. speedX += (float)event->x()/500;
  108. speedY += (float)event->y()/500;
  109. }
  110. dpy = XOpenDisplay(0);
  111. root_window = XRootWindow(dpy, 0);
  112. XSelectInput(dpy, root_window, KeyReleaseMask);
  113. XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, this->width()/2, this->height()/2);
  114. XFlush(dpy); // Flushes the output buffer, therefore updates the cursor's position. Thanks to Achernar.
  115. XCloseDisplay(dpy);
  116. }
  117. void GLWidget::keyPressEvent(QKeyEvent* event) {
  118. switch(event->key()) {
  119. case Qt::Key_Escape:
  120. close();
  121. break;
  122. case Qt::Key_W:
  123. zMove += 0.35f;
  124. break;
  125. case Qt::Key_S:
  126. zMove -= 0.35f;
  127. break;
  128. case Qt::Key_A:
  129. xMove += 0.35f;
  130. break;
  131. case Qt::Key_D:
  132. xMove -= 0.35f;
  133. break;
  134. default:
  135. event->ignore();
  136. break;
  137. }
  138. }
  139. int main(int argc, char *argv[])
  140. {
  141. QApplication a(argc, argv);
  142. GLWidget window;
  143. window.resizeGL(screenWidth, screenHeight);
  144. window.showFullScreen();
  145. a.exec();
  146. }
To copy to clipboard, switch view to plain text mode 

Thanks in advance.